summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bot.pl36
1 files 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,
24 irc_311 => \&irc_whois, 24 irc_311 => \&irc_whois,
25 irc_public => \&irc_pub_msg, 25 irc_public => \&irc_pub_msg,
26 irc_msg => \&irc_priv_msg, 26 irc_msg => \&irc_priv_msg,
27 irc_ctcp_action => \&irc_action,
28 _default => \&_default,
27); 29);
28 30
31sub _default {
32 if ( $_[ARG0] =~ /^irc_(.*)$/ ) {
33# print "IRC $1 received\n";
34 }
35}
36
29my %commands = ( 'help' => \&francoise_help, 37my %commands = ( 'help' => \&francoise_help,
30 'stat' => \&francoise_stat, 38 'stat' => \&francoise_stat,
31 'topten' => \&francoise_topten, 39 'topten' => \&francoise_topten,
@@ -161,7 +169,7 @@ sub irc_pub_msg{
161 } else { 169 } else {
162 $kernel->post( 'irc_client', 'privmsg', $channel, "Ich weiss nicht, wo $wois_ ist." ); 170 $kernel->post( 'irc_client', 'privmsg', $channel, "Ich weiss nicht, wo $wois_ ist." );
163 } 171 }
164 } elsif( $msg =~ /(.+) ($hv) (.+)$/i ) { 172 } elsif( $msg =~ /(.+?) ($hv) (.*)$/i ) {
165 my $trigger = $1; 173 my $trigger = $1;
166 my $hilfsverb = $2; 174 my $hilfsverb = $2;
167 my $reply = $3; 175 my $reply = $3;
@@ -171,22 +179,38 @@ sub irc_pub_msg{
171 } else { 179 } else {
172 my $sth = $dbh->prepare( "SELECT trigger, hilfsverb, reply FROM knowledge WHERE trigger = ? ORDER BY RANDOM() LIMIT 1"); 180 my $sth = $dbh->prepare( "SELECT trigger, hilfsverb, reply FROM knowledge WHERE trigger = ? ORDER BY RANDOM() LIMIT 1");
173 $sth->execute( $msg ); 181 $sth->execute( $msg );
174 if( my @row = $sth->fetchrow_array ) { 182 if( my ($trigger, $hilfsverb, $reply) = $sth->fetchrow_array ) {
175 $kernel->post( 'irc_client', 'privmsg', $channel, "$row[0] $row[1] $row[2]"); 183 if( $reply =~ /^<reply>(.*)$/ ) {
184 $kernel->post( 'irc_client', 'privmsg', $channel, "$1");
185 } else {
186 $kernel->post( 'irc_client', 'privmsg', $channel, "$trigger $hilfsverb $reply");
187 }
176 } 188 }
177 } 189 }
178 190
179 if( $nick ne $current_nick ) { 191 if( $nick ne $current_nick ) {
180 $dbh->do( "UPDATE users SET lines = lines + 1, words = words + $numwords + 1 WHERE nick = '$nick'" ); 192 $dbh->do( "UPDATE users SET lines = lines + 1, words = words + $numwords + 1, isaway = false WHERE nick = '$nick'" );
181 } 193 }
182 194
183 print "$channel: <$nick> $msg\n"; 195 print "$channel: <$nick> $msg\n";
184} 196}
185 197
198sub irc_action{
199 my ( $who, $msg ) = @_[ ARG0, ARG2 ];
200 my $nick_ = ( split /!/, $who )[0];
201
202 my $nick = francoise_getbasenick( $nick_ );
203
204 if( $msg =~ /^ist (.+)$/ ) {
205 my $awaymsg = $1;
206 my $sth = $dbh->prepare( "UPDATE users SET isaway = true, awaymsg = ? WHERE nick = '$nick'");
207 $sth->execute( $awaymsg );
208 }
209}
210
186sub irc_priv_msg{ 211sub irc_priv_msg{
187 my $kernel = $_[KERNEL]; 212 my ( $kernel, $msg ) = @_[KERNEL, ARG2];
188 my $nick = (split /!/, $_[ARG0])[0]; 213 my $nick = (split /!/, $_[ARG0])[0];
189 my $msg = $_[ARG2];
190 214
191 if( $msg =~ /^!(\S+)(.*)$/ ) { 215 if( $msg =~ /^!(\S+)(.*)$/ ) {
192 &{$commands{ $1 } || \&francoise_donothing } ( $kernel, $nick, $msg ); 216 &{$commands{ $1 } || \&francoise_donothing } ( $kernel, $nick, $msg );