X-Git-Url: http://git.annexia.org/?p=xavierbot.git;a=blobdiff_plain;f=xavierbot.pl;fp=xavierbot.pl;h=4650f0d042f4e813e48ef58a3a35beca21cde0f5;hp=bfdd9bfb8b01806d72f13684b9f1c5c2a32f5bad;hb=27dea572ce631f21e6dd27472a55c79092c682aa;hpb=1ddb7873d30b80c638d22ec43a771bdb3fc5cb4c diff --git a/xavierbot.pl b/xavierbot.pl index bfdd9bf..4650f0d 100755 --- a/xavierbot.pl +++ b/xavierbot.pl @@ -2,7 +2,7 @@ # xavierbot : an OCaml interpreter IRC bot. # By Richard W.M. Jones . # This code is in the Public Domain. -# $Id: xavierbot.pl,v 1.7 2007/06/29 07:55:47 rjones Exp $ +# $Id: xavierbot.pl,v 1.8 2007/06/29 19:39:13 rjones Exp $ use strict; use POE qw(Component::IRC Wheel::Run); @@ -22,6 +22,11 @@ my $channel = "#ocaml"; $ENV{PATH} = "/usr/bin:/bin"; +# Simple flood protection. This counts number of lines received from +# the toplevel, and is reset when we send a line. If this exceeds +# some value, then we just eat lines. +my $flood_lim = 0; + POE::Session->create ( package_states => [ main => [ qw(_default _start irc_001 irc_public got_stdout got_sigchld) ], @@ -78,11 +83,14 @@ sub irc_public print "got: $what\n"; if (my ($stmt) = $what =~ /^\s*([^#].*;;)\s*$/) { $heap->{ocaml}->put ("$stmt\n"); + $flood_lim = 0; } # XXX How to interpolate $nick into the patterns? elsif ($what =~ /^\s*xavierbot\b.*\bhelp\b/) { my $nick = (split /!/, $who)[0]; $kernel->post ($sender => privmsg => $channel => + "hello $nick, I am xavierbot, an OCaml toplevel"); + $kernel->post ($sender => privmsg => $channel => "$nick: expr ;; evaluate expr in OCaml toplevel"); $kernel->post ($sender => privmsg => $channel => "$nick: help help message"); @@ -120,7 +128,10 @@ sub got_stdout { my ($kernel,$heap, $input, $wheel_id) = @_[KERNEL,HEAP,ARG0,ARG1]; print "Child said: $input\n"; - $kernel->post ($heap->{irc} => privmsg => $channel => "$input"); + if ($flood_lim < 16) { + $kernel->post ($heap->{irc} => privmsg => $channel => "$input"); + } + $flood_lim++; } # Got a SIGCHLD, so start the bot up again.