Version 0.9: Use a nickserv password, and some fixes for OCaml 3.11.
[xavierbot.git] / xavierbot.pl.in
index c0e0f82..55ddae6 100755 (executable)
@@ -2,11 +2,12 @@
 # xavierbot : an OCaml interpreter IRC bot.
 # By Richard W.M. Jones <rich@annexia.org>.
 # This code is in the Public Domain.
-# $Id: xavierbot.pl.in,v 1.8 2007/07/05 12:43:14 rjones Exp $
+# $Id: xavierbot.pl.in,v 1.10 2010/04/04 19:38:40 rjones Exp $
 
 use strict;
 use POE qw(Component::IRC Wheel::Run);
 use Getopt::Long;
+use POE::Component::IRC::Plugin::NickServID;
 
 #----------------------------------------------------------------------
 # Start of configuration.
@@ -17,6 +18,8 @@ my $server = "chat.freenode.net";
 my $port = 6667;
 my $channel = "#ocaml";
 
+my $nickservpw = "123456"; # or undef
+
 # End of configuration.
 #----------------------------------------------------------------------
 
@@ -62,6 +65,11 @@ sub _start
         port => $port,
         ) or die "POE::Component::IRC->spawn failed: $!";
 
+    $irc->plugin_add('NickServID',
+                     POE::Component::IRC::Plugin::NickServID->new(
+                         Password => $nickservpw,
+                     ));
+
     my $ocaml = start_toplevel ();
 
     $kernel->sig(CHLD => qw(got_sigchld));
@@ -112,6 +120,11 @@ sub irc_public
        $kernel->post ($sender => privmsg => $channel => $_)
            foreach (@usage);
     }
+    elsif ($what =~ /^\s*xavierbot\b.*\brestart\b/) {
+       $sleeping = 0;
+       print STDOUT "got instruction to restart ...\n";
+       restart_toplevel ($heap->{ocaml});
+    }
     elsif (!$sleeping) {
        if (my ($stmt) = $what =~ m/^\s*([^\#].*;;)\s*$/) {
            $heap->{ocaml}->put ("$stmt\n");
@@ -128,11 +141,6 @@ sub irc_public
            $kernel->post ($sender => privmsg => $channel =>
                           "xavierbot wakes up");
        }
-       elsif ($what =~ /^\s*xavierbot\b.*\brestart\b/) {
-           $sleeping = 0;
-           print STDOUT "got instruction to restart ...\n";
-           restart_toplevel ($heap->{ocaml});
-       }
     }
     undef;
 }