From 516c1f91af641f17bade476156ec0667a9b22857 Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Sat, 23 Jul 2005 04:31:35 +0000 Subject: command func hash, topten --- bot.pl | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/bot.pl b/bot.pl index f9a0c4e..57ab3de 100644 --- a/bot.pl +++ b/bot.pl @@ -26,6 +26,13 @@ POE::Session->new ( _start => \&irc_start, irc_msg => \&irc_priv_msg, ); +my %commands = ( 'help' => \&francoise_help, + 'stat' => \&francoise_stat, + 'topten' => \&francoise_topten, + 'topten0r' => \&francoise_topten0r, + 'forget' => \&francoise_forget, + ); + # Database connection stuff my $dbh = DBI->connect("DBI:Pg:dbname='francoise'", 'francoise', 'kiffer') or die "ohoh, datenbank b0rken: $!"; @@ -70,7 +77,7 @@ sub irc_names { print "#-> Users on $channel [ $names ]\n"; for my $user (split / /, $names) { - $user =~ s/^@|%|\+//; + $user =~ s/^[@%+]//; $kernel->post( 'irc_client', 'whois', $user); } } @@ -131,6 +138,10 @@ sub irc_pub_msg{ my $msg = $_[ARG2]; my $words = (split / /, $msg); + if( $msg =~ /^!(\S+)(.*)$/ ) { + &{$commands{ $1 } || \&francoise_donothing } ( $kernel, $channel, $msg ); + } + if( $nick ne $current_nick ) { $dbh->do( "UPDATE users SET lines = lines + 1, words = words + $words WHERE nick = '$nick'" ); } @@ -143,7 +154,10 @@ sub irc_priv_msg{ my $nick = (split /!/, $_[ARG0])[0]; my $msg = $_[ARG2]; - $kernel->post( 'irc_client', 'privmsg', $nick, 'Ich dich auch!'); + + if( $msg =~ /^!(\S+)(.*)$/ ) { + &{$commands{ $1 } || \&francoise_donothing } ( $kernel, $nick, $msg ); + } print "PRIV: [$nick] $msg\n"; } @@ -162,5 +176,40 @@ sub irc_whois{ } } +sub francoise_help { + my $kernel = $_[0]; + my $dest = $_[1]; + + $kernel->post( 'irc_client', 'privmsg', $dest, 'Ich bins doch.'); + +} + +sub francoise_stat { + +} + +sub francoise_topten { + my $kernel = $_[0]; + my $dest = $_[1]; + + my $sth = $dbh->prepare( "SELECT words, nick FROM users ORDER BY words DESC LIMIT 10" ); + $sth->execute(); + while ( my @row = $sth->fetchrow_array ) { + $kernel->post( 'irc_client', 'privmsg', $dest, "$row[0] $row[1]" ); + } +} + +sub francoise_topten0r { + +} + +sub francoise_forget { + +} + +sub francoise_donothing { + +} + #start everything $poe_kernel->run(); -- cgit v1.2.3