From: Michael Andreen Date: Thu, 20 Aug 2009 22:42:42 +0000 (+0200) Subject: Add megahal support to delling X-Git-Url: https://ruin.nu/git/?p=NDIRC.git;a=commitdiff_plain;h=84affcdf70684e8f29e83dc2c3ab75520da383d7 Add megahal support to delling --- diff --git a/Bot.pm b/Bot.pm index c90f833..1200424 100644 --- a/Bot.pm +++ b/Bot.pm @@ -128,7 +128,7 @@ sub _build_disp { $disp->load(@commands); } - my $channels = new IO::File 'channels'; + my $channels = new IO::File 'channels' or die $!;; while (<$channels>){ my ($chan, @types) = split /\s+/; say "$chan - @types"; diff --git a/Delling.pm b/Delling.pm index e08f791..224a657 100644 --- a/Delling.pm +++ b/Delling.pm @@ -28,6 +28,14 @@ extends 'NDIRC::Bot'; use POE::Session; use ND::DB; +use AI::MegaHAL; + +has hal => ( + is => 'ro', + isa => 'Object', + lazy_build => 1, +); + sub irc_public { my ($self,$sender, $who, $where, $msg) = @_[OBJECT,SENDER, ARG0 .. ARG2]; my ($nick,$username,$address) = ( split /[!@]/, $who ); @@ -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)/){ @@ -53,7 +65,6 @@ sub irc_public { } } - sub irc_msg { my ($self,$sender, $who, $where, $msg) = @_[OBJECT,SENDER, ARG0 .. ARG2]; my ($nick,$username,$address) = ( split /[!@]/, $who ); @@ -125,4 +136,15 @@ sub refresh { 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;