diff options
| author | erdgeist <> | 2005-07-23 04:31:35 +0000 |
|---|---|---|
| committer | erdgeist <> | 2005-07-23 04:31:35 +0000 |
| commit | 516c1f91af641f17bade476156ec0667a9b22857 (patch) | |
| tree | ea543aaaadf6ee5e8dd2342c9a01d703d119af0d | |
| parent | 937f46fb74c72e829a015ed196bb87c86fee3435 (diff) | |
command func hash, topten
| -rw-r--r-- | bot.pl | 53 |
1 files changed, 51 insertions, 2 deletions
| @@ -26,6 +26,13 @@ POE::Session->new ( _start => \&irc_start, | |||
| 26 | irc_msg => \&irc_priv_msg, | 26 | irc_msg => \&irc_priv_msg, |
| 27 | ); | 27 | ); |
| 28 | 28 | ||
| 29 | my %commands = ( 'help' => \&francoise_help, | ||
| 30 | 'stat' => \&francoise_stat, | ||
| 31 | 'topten' => \&francoise_topten, | ||
| 32 | 'topten0r' => \&francoise_topten0r, | ||
| 33 | 'forget' => \&francoise_forget, | ||
| 34 | ); | ||
| 35 | |||
| 29 | # Database connection stuff | 36 | # Database connection stuff |
| 30 | my $dbh = DBI->connect("DBI:Pg:dbname='francoise'", 'francoise', 'kiffer') | 37 | my $dbh = DBI->connect("DBI:Pg:dbname='francoise'", 'francoise', 'kiffer') |
| 31 | or die "ohoh, datenbank b0rken: $!"; | 38 | or die "ohoh, datenbank b0rken: $!"; |
| @@ -70,7 +77,7 @@ sub irc_names { | |||
| 70 | print "#-> Users on $channel [ $names ]\n"; | 77 | print "#-> Users on $channel [ $names ]\n"; |
| 71 | 78 | ||
| 72 | for my $user (split / /, $names) { | 79 | for my $user (split / /, $names) { |
| 73 | $user =~ s/^@|%|\+//; | 80 | $user =~ s/^[@%+]//; |
| 74 | $kernel->post( 'irc_client', 'whois', $user); | 81 | $kernel->post( 'irc_client', 'whois', $user); |
| 75 | } | 82 | } |
| 76 | } | 83 | } |
| @@ -131,6 +138,10 @@ sub irc_pub_msg{ | |||
| 131 | my $msg = $_[ARG2]; | 138 | my $msg = $_[ARG2]; |
| 132 | my $words = (split / /, $msg); | 139 | my $words = (split / /, $msg); |
| 133 | 140 | ||
| 141 | if( $msg =~ /^!(\S+)(.*)$/ ) { | ||
| 142 | &{$commands{ $1 } || \&francoise_donothing } ( $kernel, $channel, $msg ); | ||
| 143 | } | ||
| 144 | |||
| 134 | if( $nick ne $current_nick ) { | 145 | if( $nick ne $current_nick ) { |
| 135 | $dbh->do( "UPDATE users SET lines = lines + 1, words = words + $words WHERE nick = '$nick'" ); | 146 | $dbh->do( "UPDATE users SET lines = lines + 1, words = words + $words WHERE nick = '$nick'" ); |
| 136 | } | 147 | } |
| @@ -143,7 +154,10 @@ sub irc_priv_msg{ | |||
| 143 | my $nick = (split /!/, $_[ARG0])[0]; | 154 | my $nick = (split /!/, $_[ARG0])[0]; |
| 144 | my $msg = $_[ARG2]; | 155 | my $msg = $_[ARG2]; |
| 145 | 156 | ||
| 146 | $kernel->post( 'irc_client', 'privmsg', $nick, 'Ich dich auch!'); | 157 | |
| 158 | if( $msg =~ /^!(\S+)(.*)$/ ) { | ||
| 159 | &{$commands{ $1 } || \&francoise_donothing } ( $kernel, $nick, $msg ); | ||
| 160 | } | ||
| 147 | 161 | ||
| 148 | print "PRIV: [$nick] $msg\n"; | 162 | print "PRIV: [$nick] $msg\n"; |
| 149 | } | 163 | } |
| @@ -162,5 +176,40 @@ sub irc_whois{ | |||
| 162 | } | 176 | } |
| 163 | } | 177 | } |
| 164 | 178 | ||
| 179 | sub francoise_help { | ||
| 180 | my $kernel = $_[0]; | ||
| 181 | my $dest = $_[1]; | ||
| 182 | |||
| 183 | $kernel->post( 'irc_client', 'privmsg', $dest, 'Ich bins doch.'); | ||
| 184 | |||
| 185 | } | ||
| 186 | |||
| 187 | sub francoise_stat { | ||
| 188 | |||
| 189 | } | ||
| 190 | |||
| 191 | sub francoise_topten { | ||
| 192 | my $kernel = $_[0]; | ||
| 193 | my $dest = $_[1]; | ||
| 194 | |||
| 195 | my $sth = $dbh->prepare( "SELECT words, nick FROM users ORDER BY words DESC LIMIT 10" ); | ||
| 196 | $sth->execute(); | ||
| 197 | while ( my @row = $sth->fetchrow_array ) { | ||
| 198 | $kernel->post( 'irc_client', 'privmsg', $dest, "$row[0] $row[1]" ); | ||
| 199 | } | ||
| 200 | } | ||
| 201 | |||
| 202 | sub francoise_topten0r { | ||
| 203 | |||
| 204 | } | ||
| 205 | |||
| 206 | sub francoise_forget { | ||
| 207 | |||
| 208 | } | ||
| 209 | |||
| 210 | sub francoise_donothing { | ||
| 211 | |||
| 212 | } | ||
| 213 | |||
| 165 | #start everything | 214 | #start everything |
| 166 | $poe_kernel->run(); | 215 | $poe_kernel->run(); |
