From 3672fa58704db16fdb0b2a95c2fe08b8ff1ae71c Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Sat, 23 Jul 2005 17:38:59 +0000 Subject: Zusammenfuehrung aller Nutzerqueries --- bot.pl | 55 +++++++++++++++++++++++++++++++++++++------------------ tables.sql | 3 +++ 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/bot.pl b/bot.pl index 57ab3de..9f09cbd 100644 --- a/bot.pl +++ b/bot.pl @@ -110,14 +110,9 @@ sub irc_join { my $host = (split /@/, $_[ARG0])[1]; if( $nick eq $current_nick ) { - $kernel->post( 'irc_client', 'privmsg', $channel, 'Hier bin ich!'); + $kernel->post( 'irc_client', 'privmsg', $channel, 'Hier bin ich!'); } else { - my ($cnt) = $dbh->selectrow_array( "SELECT COUNT(*) FROM users WHERE nick='$nick'" ); - if ( $cnt == 0 ) { - $dbh->do( "INSERT INTO users(id, nick, words, lines, lastlogin, lasthost) VALUES ( '$nick', '$nick', 0, 0, now(), '$host' )"); - } else { - $dbh->do( "UPDATE users SET lasthost = '$host', lastlogin = now() WHERE nick = '$nick'" ); - } + francoise_verifyuser( $nick, $host, 1 ); } print "#-> $nick has joined $channel\n"; @@ -132,18 +127,21 @@ sub irc_quit { } sub irc_pub_msg{ - my $kernel = $_[KERNEL]; - my $nick = (split /!/, $_[ARG0])[0]; - my $channel = $_[ARG1]->[0]; - my $msg = $_[ARG2]; - my $words = (split / /, $msg); + my $kernel = $_[KERNEL]; + my $nick = (split /!/, $_[ARG0])[0]; + my $channel = $_[ARG1]->[0]; + my $msg = $_[ARG2]; + my @words = (split / /, $msg); + my $numwords = $#words; if( $msg =~ /^!(\S+)(.*)$/ ) { &{$commands{ $1 } || \&francoise_donothing } ( $kernel, $channel, $msg ); } + $nick = francoise_verifyuser( $nick, "", 0, $kernel ); + if( $nick ne $current_nick ) { - $dbh->do( "UPDATE users SET lines = lines + 1, words = words + $words WHERE nick = '$nick'" ); + $dbh->do( "UPDATE users SET lines = lines + 1, words = words + $numwords + 1 WHERE nick = '$nick'" ); } print "$channel: <$nick> $msg\n"; @@ -154,7 +152,6 @@ sub irc_priv_msg{ my $nick = (split /!/, $_[ARG0])[0]; my $msg = $_[ARG2]; - if( $msg =~ /^!(\S+)(.*)$/ ) { &{$commands{ $1 } || \&francoise_donothing } ( $kernel, $nick, $msg ); } @@ -167,21 +164,43 @@ sub irc_whois{ my $host = (split / /, $_[ARG1])[2]; if( $nick ne $current_nick ) { + francoise_verifyuser( $nick, $host, 0 ); + } +} + +sub francoise_verifyuser { + my $nick_ = $_[0]; + my $host = $_[1]; + my $updtime = $_[2]; + my $kernel = $_[3]; + + my $nick = ( split /_/, $nick_ )[0] || $nick_; + + if( $host ) { my ($cnt) = $dbh->selectrow_array( "SELECT COUNT(*) FROM users WHERE nick='$nick'" ); if ( $cnt == 0 ) { - $dbh->do( "INSERT INTO users(id, nick, words, lines, lastlogin, lasthost) VALUES ( '', '$nick', 0, 0, now(), '$host' )"); + $dbh->do( "INSERT INTO users(id, nick, words, lines, lastlogin, lasthost) VALUES ( '$nick', '$nick', 0, 0, now(), '$host' )"); } else { - $dbh->do( "UPDATE users SET lasthost = '$host' WHERE nick = '$nick'" ); + $dbh->do( "UPDATE users SET lasthost = '$host'" . ( $updtime ? ", lastlogin = now()" : "" ) . " WHERE nick = '$nick'" ); } + } else { + $kernel->post( 'irc_client', 'whois', $nick_); } + + return $nick; } sub francoise_help { my $kernel = $_[0]; my $dest = $_[1]; - $kernel->post( 'irc_client', 'privmsg', $dest, 'Ich bins doch.'); - + $kernel->post( 'irc_client', 'privmsg', $dest, 'Hallo, ich bin Francoise, der freundliche Kifferchat-Bot.'); + $kernel->post( 'irc_client', 'privmsg', $dest, 'Ich kann folgende Kommandos ausfuehren:'); + $kernel->post( 'irc_client', 'privmsg', $dest, '!help Diese Hilfe anzeigen'); + $kernel->post( 'irc_client', 'privmsg', $dest, '!stat Informationen ueber mich ausgeben'); + $kernel->post( 'irc_client', 'privmsg', $dest, '!topten Die aktivsten Chatter anzeigen'); + $kernel->post( 'irc_client', 'privmsg', $dest, '!topten0r Die 13370rsten Chatter anzeigen'); + $kernel->post( 'irc_client', 'privmsg', $dest, '!forget Einen Trigger vergessen'); } sub francoise_stat { diff --git a/tables.sql b/tables.sql index acb9e8f..533735a 100644 --- a/tables.sql +++ b/tables.sql @@ -13,6 +13,9 @@ create table users ( words integer, lines integer, + isaway bool default false, + awaymsg text, + lastlogin timestamp, lasthost text ); -- cgit v1.2.3