X-Git-Url: http://git.annexia.org/?p=xavierbot.git;a=blobdiff_plain;f=xavierbot.pl.in;h=55ddae6726366f1795b6c06fbd5a8f4d1caea57a;hp=76258c6b70ca1880fe3df2ada16598c1ff918c7e;hb=e510484ab8b113b43cf95a18820ad3a0629edf4b;hpb=1404efcc8dc5e7bebfcd3af1b1cd03ffdd169cae diff --git a/xavierbot.pl.in b/xavierbot.pl.in index 76258c6..55ddae6 100755 --- a/xavierbot.pl.in +++ b/xavierbot.pl.in @@ -1,25 +1,35 @@ -#!/usr/bin/perl -wT +#!/usr/bin/perl -w # xavierbot : an OCaml interpreter IRC bot. # By Richard W.M. Jones . # This code is in the Public Domain. -# $Id: xavierbot.pl.in,v 1.6 2007/06/29 21:43:21 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. my $nick = "xavierbot"; my $ircname = "Xavierbot"; # Printable name. -#my $server = "chat.freenode.net"; -my $server = "devserv.devel.redhat.com"; +my $server = "chat.freenode.net"; my $port = 6667; my $channel = "#ocaml"; +my $nickservpw = "123456"; # or undef + # End of configuration. #---------------------------------------------------------------------- -# Current state. + +# Command line args can override configuration. +GetOptions ("nick=s" => \$nick, + "ircname=s" => \$ircname, + "server=s" => \$server, + "port=i" => \$port, + "channel=s" => \$channel) + or die "$0: GetOptions: $!"; # Simple flood protection. This counts number of lines received from # the toplevel, and is reset when we send a line. If this exceeds @@ -55,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)); @@ -105,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"); @@ -121,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; }