From 9af9f63149e2f1ecffe83560e615ad3c6a3c2681 Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Mon, 25 Jul 2005 04:23:34 +0000 Subject: trigger ist REPLY works --- bot.pl | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/bot.pl b/bot.pl index d35fb33..b216b17 100644 --- a/bot.pl +++ b/bot.pl @@ -24,8 +24,16 @@ POE::Session->new ( _start => \&irc_start, irc_311 => \&irc_whois, irc_public => \&irc_pub_msg, irc_msg => \&irc_priv_msg, + irc_ctcp_action => \&irc_action, + _default => \&_default, ); +sub _default { + if ( $_[ARG0] =~ /^irc_(.*)$/ ) { +# print "IRC $1 received\n"; + } +} + my %commands = ( 'help' => \&francoise_help, 'stat' => \&francoise_stat, 'topten' => \&francoise_topten, @@ -161,7 +169,7 @@ sub irc_pub_msg{ } else { $kernel->post( 'irc_client', 'privmsg', $channel, "Ich weiss nicht, wo $wois_ ist." ); } - } elsif( $msg =~ /(.+) ($hv) (.+)$/i ) { + } elsif( $msg =~ /(.+?) ($hv) (.*)$/i ) { my $trigger = $1; my $hilfsverb = $2; my $reply = $3; @@ -171,22 +179,38 @@ sub irc_pub_msg{ } else { my $sth = $dbh->prepare( "SELECT trigger, hilfsverb, reply FROM knowledge WHERE trigger = ? ORDER BY RANDOM() LIMIT 1"); $sth->execute( $msg ); - if( my @row = $sth->fetchrow_array ) { - $kernel->post( 'irc_client', 'privmsg', $channel, "$row[0] $row[1] $row[2]"); + if( my ($trigger, $hilfsverb, $reply) = $sth->fetchrow_array ) { + if( $reply =~ /^(.*)$/ ) { + $kernel->post( 'irc_client', 'privmsg', $channel, "$1"); + } else { + $kernel->post( 'irc_client', 'privmsg', $channel, "$trigger $hilfsverb $reply"); + } } } if( $nick ne $current_nick ) { - $dbh->do( "UPDATE users SET lines = lines + 1, words = words + $numwords + 1 WHERE nick = '$nick'" ); + $dbh->do( "UPDATE users SET lines = lines + 1, words = words + $numwords + 1, isaway = false WHERE nick = '$nick'" ); } print "$channel: <$nick> $msg\n"; } +sub irc_action{ + my ( $who, $msg ) = @_[ ARG0, ARG2 ]; + my $nick_ = ( split /!/, $who )[0]; + + my $nick = francoise_getbasenick( $nick_ ); + + if( $msg =~ /^ist (.+)$/ ) { + my $awaymsg = $1; + my $sth = $dbh->prepare( "UPDATE users SET isaway = true, awaymsg = ? WHERE nick = '$nick'"); + $sth->execute( $awaymsg ); + } +} + sub irc_priv_msg{ - my $kernel = $_[KERNEL]; + my ( $kernel, $msg ) = @_[KERNEL, ARG2]; my $nick = (split /!/, $_[ARG0])[0]; - my $msg = $_[ARG2]; if( $msg =~ /^!(\S+)(.*)$/ ) { &{$commands{ $1 } || \&francoise_donothing } ( $kernel, $nick, $msg ); -- cgit v1.2.3