diff options
author | erdgeist <> | 2005-07-25 04:23:34 +0000 |
---|---|---|
committer | erdgeist <> | 2005-07-25 04:23:34 +0000 |
commit | 9af9f63149e2f1ecffe83560e615ad3c6a3c2681 (patch) | |
tree | 20fe9f1b8bc8bd20b7150b78ab00fc26ed4c9998 | |
parent | f6ab8ecf9b23518283bba5c3755a4df25d9f45d6 (diff) |
trigger ist <reply> REPLY works
-rw-r--r-- | bot.pl | 36 |
1 files changed, 30 insertions, 6 deletions
@@ -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 | ||
31 | sub _default { | ||
32 | if ( $_[ARG0] =~ /^irc_(.*)$/ ) { | ||
33 | # print "IRC $1 received\n"; | ||
34 | } | ||
35 | } | ||
36 | |||
29 | my %commands = ( 'help' => \&francoise_help, | 37 | my %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 | ||
198 | sub 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 | |||
186 | sub irc_priv_msg{ | 211 | sub 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 ); |