From 2685f40922e098aa6375f945626046f764588958 Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Mon, 25 Jul 2005 03:07:32 +0000 Subject: Added the following functionality: * incoming privmsgs starting with !say will be echoed to the channel * an aliasestable is being queried to find the base of the nick * nick changes are being ignored, if the same base nick appears in newnick * else user is being treated as newly logged in * knowledge collection has been enabled * several bugs have been fixed * protection against sql injection needs to be added --- bot.pl | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 10 deletions(-) diff --git a/bot.pl b/bot.pl index 6548aac..d35fb33 100644 --- a/bot.pl +++ b/bot.pl @@ -33,6 +33,14 @@ my %commands = ( 'help' => \&francoise_help, 'forget' => \&francoise_forget, ); +my @hilfsverb = ( 'bin', 'bist', 'ist', 'is', 'sind', 'seid', + 'werde', 'wirst', 'wird', 'werden', 'werdet', + 'war', 'warst', 'waren', 'wart', + 'habe', 'hast', 'hat', 'haben', 'habt', + 'hatte', 'hattest', 'hatten', 'hattet' ); + +my $hv = join( '|', @hilfsverb); + # Database connection stuff my $dbh = DBI->connect("DBI:Pg:dbname='francoise'", 'francoise', 'kiffer') or die "ohoh, datenbank b0rken: $!"; @@ -84,14 +92,17 @@ sub irc_names { #nick change sub irc_nick { - my $oldnick = (split /!/, $_[ARG0])[0]; - my $newnick = $_[ARG1]; + my $oldnick_ = (split /!/, $_[ARG0])[0]; + my $newnick_ = $_[ARG1]; + + my $oldnick = francoise_getbasenick( $oldnick_ ); + my $newnick = francoise_getbasenick( $newnick_ ); - if( $newnick ne $current_nick ) { - $dbh->do( "UPDATE users SET nick = '$newnick' WHERE nick = '$oldnick'" ); + if( $newnick_ ne $current_nick && $newnick ne $oldnick ) { + francoise_verifyuser( $newnick_, '', 0 ); } - print "#-> $oldnick is now known as $newnick\n"; + print "#-> $oldnick_ is now known as $newnick_\n"; } #user parted @@ -134,15 +145,15 @@ sub irc_pub_msg{ my @words = (split / /, $msg); my $numwords = $#words; + my $nick = francoise_verifyuser( $nick_, "", 0, $kernel ); + if( $msg =~ /^!(\S+)(.*)$/ ) { &{$commands{ $1 } || \&francoise_donothing } ( $kernel, $channel, $msg ); } - my $nick = francoise_verifyuser( $nick_, "", 0, $kernel ); - - if( $msg =~ /^wo ist (\S+)/i ) { + if( $msg =~ /^wo ist (\S+)\??$/i ) { my $wois_ = $1; - my $wois = ( split /_/, $1 )[0] || $1; + my $wois = francoise_getbasenick( $1 ); my $sth = $dbh->prepare( "SELECT awaymsg FROM users WHERE nick = '$wois' AND isaway = 'true'"); $sth->execute(); if ( my @awaymsg = $sth->fetchrow_array ) { @@ -150,6 +161,19 @@ sub irc_pub_msg{ } else { $kernel->post( 'irc_client', 'privmsg', $channel, "Ich weiss nicht, wo $wois_ ist." ); } + } elsif( $msg =~ /(.+) ($hv) (.+)$/i ) { + my $trigger = $1; + my $hilfsverb = $2; + my $reply = $3; + + my $sth = $dbh->prepare( "INSERT INTO knowledge ( trigger, hilfsverb, reply ) VALUES ( ?, ?, ?) " ); + $sth->execute( $trigger, $hilfsverb, $reply ); + } else { + my $sth = $dbh->prepare( "SELECT trigger, hilfsverb, reply FROM knowledge WHERE trigger = ? ORDER BY RANDOM() LIMIT 1"); + $sth->execute( $msg ); + if( my @row = $sth->fetchrow_array ) { + $kernel->post( 'irc_client', 'privmsg', $channel, "$row[0] $row[1] $row[2]"); + } } if( $nick ne $current_nick ) { @@ -168,6 +192,9 @@ sub irc_priv_msg{ &{$commands{ $1 } || \&francoise_donothing } ( $kernel, $nick, $msg ); } + if( $msg =~ /^!say (.*)$/ ) { + $kernel->post( 'irc_client', 'privmsg', $channel, $1); } + print "PRIV: [$nick] $msg\n"; } @@ -180,13 +207,29 @@ sub irc_whois{ } } +sub francoise_getbasenick{ + my $nick = $_[0]; + + + $nick = ( split /_/, $nick )[0] || $nick; + $nick = ( split /\|/, $nick )[0] || $nick; + + my $sth = $dbh->prepare( "SELECT nick FROM aliases WHERE alias = '$nick'" ); + $sth->execute(); + if( my @row = $sth->fetchrow_array ) { + $nick = $row[0]; + } + + return $nick; +} + sub francoise_verifyuser { my $nick_ = $_[0]; my $host = $_[1]; my $updtime = $_[2]; my $kernel = $_[3]; - my $nick = ( split /_/, $nick_ )[0] || $nick_; + my $nick = francoise_getbasenick( $nick_ ); if( $host ) { my ($cnt) = $dbh->selectrow_array( "SELECT COUNT(*) FROM users WHERE nick='$nick'" ); -- cgit v1.2.3