X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Delling.pm;h=39c7cf9f65494371a17733531bbe950251fcd44b;hb=eb496c248b615ab2aca038757df256f3f63648a0;hp=e08f7910b98c8d4daf90a9c66acd616a2ae1455f;hpb=921132036eac2233472b1b315e4ee39f5ab17fbd;p=NDIRC.git diff --git a/Delling.pm b/Delling.pm index e08f791..39c7cf9 100644 --- a/Delling.pm +++ b/Delling.pm @@ -28,7 +28,15 @@ extends 'NDIRC::Bot'; use POE::Session; use ND::DB; -sub irc_public { +use AI::MegaHAL; + +has hal => ( + is => 'ro', + isa => 'Object', + lazy_build => 1, +); + +after irc_public => sub { my ($self,$sender, $who, $where, $msg) = @_[OBJECT,SENDER, ARG0 .. ARG2]; my ($nick,$username,$address) = ( split /[!@]/, $who ); my $channel = $where->[0]; @@ -40,7 +48,11 @@ sub irc_public { my $seen = $dbh->prepare_cached(q{UPDATE users SET laston = NOW() WHERE hostmask = ?}); $seen->execute($address); - if ($msg =~ /^(\S+): (.+)$/ && $self->disp->has_command('anon',$channel)){ + my $nickname = $irc->nick_name; + if ($msg =~ /^$nickname: (.*)/i){ + my $text = $self->hal->do_reply($1); + $irc->yield(privmsg => $channel, "$nick: $text"); + }elsif ($msg =~ /^(\S+): (.+)$/ && $self->disp->has_command('anon',$channel)){ my $_ = $1; my $text = $2; unless ($irc->is_channel_member($channel,$1) || /(Constructing|Researching)/){ @@ -51,10 +63,9 @@ sub irc_public { if ($self->parseCommand($msg,$irc,$nick,$address,$channel,$dbh)){ #Command parsed and run successfully } -} - +}; -sub irc_msg { +after irc_msg => sub { my ($self,$sender, $who, $where, $msg) = @_[OBJECT,SENDER, ARG0 .. ARG2]; my ($nick,$username,$address) = ( split /[!@]/, $who ); my $irc = $sender->get_heap(); @@ -68,7 +79,7 @@ sub irc_msg { }else{ $irc->yield(notice => $nick, "unknown command"); } -} +}; sub irc_join { my ($self,$sender, $who, $channel) = @_[OBJECT,SENDER, ARG0 .. ARG1]; @@ -106,23 +117,37 @@ sub refresh { my $dbh = DB(); my $scans = $dbh->prepare(q{SELECT s.scan_id + ,coords(x,y,z),type ,array_agg(sr.nick) AS nick ,array_agg(sr.id) AS id FROM scan_requests sr JOIN scans s USING (pid,type) + JOIN current_planet_stats USING (pid) WHERE sr.time > NOW() - '30 min'::INTERVAL AND s.tick >= sr.tick AND NOT sr.sent - GROUP BY scan_id + GROUP BY scan_id,x,y,z,type }); my $sentscan = $dbh->prepare(q{UPDATE scan_requests SET sent = TRUE WHERE id = ANY($1) }); $scans->execute; while (my $scan = $scans->fetchrow_hashref){ - $heap->{irc}->yield(notice => $scan->{nick}, "http://game.planetarion.com/showscan.pl?scan_id=$scan->{scan_id}"); + $heap->{irc}->yield(notice => $scan->{nick}, "($scan->{coords} $scan->{type})" + ." http://game.planetarion.com/showscan.pl?scan_id=$scan->{scan_id}"); $sentscan->execute($scan->{id}); } return; } +sub _build_hal { + my $hal = AI::MegaHAL->new('Path' => '.', 'Banner' => 0, 'Prompt' => 0, 'Wrap' => 0, 'AutoSave' => 1); + return $hal; +} + +after sig_usr2 => sub { + my $self = shift; + say 'Saving brain!'; + $self->hal->_cleanup; +}; + 1;