From d297717cfb35e77701997e3722b4a09b3dae7091 Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Tue, 26 Jul 2005 02:31:53 +0000 Subject: aliasing works now, find a more proprietaery name for it --- bot.pl | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/bot.pl b/bot.pl index 2d37864..0c0a426 100644 --- a/bot.pl +++ b/bot.pl @@ -7,7 +7,7 @@ use DBI; use POE; use POE::Component::IRC; -my $current_nick = "francoise_"; +my $current_nick = 'francoise_'; my $channel = '#test'; POE::Component::IRC->new("francoise"); @@ -311,8 +311,33 @@ sub francoise_alias{ my ($kernel, $dest, $msg ) = @_; my ($nick, $alias) = (split / /, $msg ); - print "$nick is also $alias \n"; + my $sth = $dbh->prepare( "SELECT nick FROM aliases WHERE alias = ?" ); + $sth->execute( $nick ); + if( my ($tmp) = $sth->fetchrow_array ) { + $alias = $nick; $nick = $tmp; + } + + $sth = $dbh->prepare( "SELECT COUNT(*) FROM aliases WHERE nick = ? AND alias = ?" ); + $sth->execute( $nick, $alias); + return if( ($sth->fetchrow_array)[0] > 0 ); + + $sth = $dbh->prepare( "SELECT words, lines FROM users WHERE nick = ?"); + $sth->execute($nick); my @userrow = $sth->fetchrow_array; + $sth->execute($alias); my @aliasrow = $sth->fetchrow_array; + + print "@userrow @aliasrow \n"; + + if( @userrow && @aliasrow ) { + $sth = $dbh->prepare( "UPDATE users SET isaway = false, words = ?, lines = ? WHERE nick = ?" ); + $sth->execute( $userrow[0]+$aliasrow[0], $userrow[1]+$aliasrow[1], $nick ); + + $sth = $dbh->prepare( "INSERT INTO aliases ( nick, alias ) VALUES ( ?, ? )" ); + $sth->execute($nick, $alias); + + $sth = $dbh->prepare( "DELETE FROM users WHERE nick = ?" ); + $sth->execute( $alias ); + } } sub francoise_topten0r { -- cgit v1.2.3