X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Delling.pm;h=39c7cf9f65494371a17733531bbe950251fcd44b;hb=8fa0654350fcf47b257f2ffa7256b3c4c6152475;hp=362e7aac79b93846ebee164e0a27071e77e7175f;hpb=97961925ba4f37fb6f63e3d914241d6d4d8d84a2;p=NDIRC.git diff --git a/Delling.pm b/Delling.pm index 362e7aa..39c7cf9 100644 --- a/Delling.pm +++ b/Delling.pm @@ -1,5 +1,5 @@ #************************************************************************** -# Copyright (C) 2006 by Michael Andreen * +# Copyright (C) 2009 by Michael Andreen * # * # This program is free software; you can redistribute it and/or modify * # it under the terms of the GNU General Public License as published by * @@ -22,12 +22,22 @@ use strict; use warnings; use feature ':5.10'; +use Moose; +extends 'NDIRC::Bot'; + use POE::Session; -use NDIRC::Misc; use ND::DB; -sub irc_public { - my ($sender, $heap, $who, $where, $msg) = @_[SENDER, HEAP, ARG0 .. ARG2]; +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]; @@ -38,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+): (.+)$/ && $heap->{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)/){ @@ -46,14 +60,13 @@ sub irc_public { } } - if (parseCommand($msg,$irc,$nick,$address,$channel,$heap->{disp},$dbh)){ + if ($self->parseCommand($msg,$irc,$nick,$address,$channel,$dbh)){ #Command parsed and run successfully } -} - +}; -sub irc_msg { - my ($sender, $heap, $who, $where, $msg) = @_[SENDER, HEAP, ARG0 .. ARG2]; +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(); @@ -61,15 +74,15 @@ sub irc_msg { my $seen = $dbh->prepare_cached(q{UPDATE users SET laston = NOW() WHERE hostmask = ?}); $seen->execute($address); - if (parseCommand($msg,$irc,$nick,$address,'pm',$heap->{disp},$dbh)){ + if ($self->parseCommand($msg,$irc,$nick,$address,'pm',$dbh)){ #Command parsed and run successfully }else{ $irc->yield(notice => $nick, "unknown command"); } -} +}; sub irc_join { - my ($sender, $heap, $who, $channel) = @_[SENDER, HEAP, ARG0 .. ARG1]; + my ($self,$sender, $who, $channel) = @_[OBJECT,SENDER, ARG0 .. ARG1]; my ($nick,$username,$address) = ( split /[!@]/, $who ); my $irc = $sender->get_heap(); @@ -77,7 +90,7 @@ sub irc_join { my $seen = $dbh->prepare_cached(q{UPDATE users SET laston = NOW() WHERE hostmask = ?}); $seen->execute($address); - if($heap->{disp}->has_command('voice',$channel)){ + if($self->disp->has_command('voice',$channel)){ my $flags = $dbh->prepare_cached(q{ SELECT DISTINCT flag FROM users u @@ -104,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;