From b1dc1d7a6254a68d3001f55c310d9ea4361ef3d3 Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Wed, 20 Jul 2005 14:56:49 +0000 Subject: Rudimentaere Databaseshiat --- bot.pl | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/bot.pl b/bot.pl index 341a67c..cdf6845 100644 --- a/bot.pl +++ b/bot.pl @@ -1,10 +1,16 @@ #!/usr/bin/perl use strict; +use DBI; + +# IRC Server stuff use POE; use POE::Component::IRC; +my $current_nick = "francoise"; +my $channel = '#test'; + POE::Component::IRC->new("irc_client"); POE::Session->new ( _start => \&irc_start, @@ -19,6 +25,10 @@ POE::Session->new ( _start => \&irc_start, irc_msg => \&irc_priv_msg, ); +# Database connection stuff +my $dbh = DBI->connect("DBI:Pg:dbname='francoise'", 'francoise', 'kiffer') + or die "ohoh, datenbank b0rken: $!"; + sub irc_start { # KERNEL, HEAP, and SESSION are constants exported by POE my $kernel = $_[KERNEL]; @@ -28,7 +38,7 @@ sub irc_start { $kernel->refcount_increment( $session->ID(), "my bot"); $kernel->post(irc_client=> register=> "all"); - $kernel->post(irc_client=>connect=> { Nick => 'francoise', + $kernel->post(irc_client=>connect=> { Nick => $current_nick, Username => 'francoise', Ircname => 'francoise', Server => 'irc.kiffer.de', @@ -40,7 +50,7 @@ sub irc_start { sub irc_connect { my $kernel = $_[KERNEL]; - $kernel->post(irc_client=>join=>'#kiffer.de'); + $kernel->post(irc_client=>join=>$channel); } sub irc_motd { @@ -76,9 +86,15 @@ sub irc_part { #user joined sub irc_join { + my $kernel = $_[KERNEL]; my $nick = (split /!/, $_[ARG0])[0]; my $channel = $_[ARG1]; + if( $nick eq $current_nick ) { + print "I JOIN JOIN JOIN\n"; + $kernel->post( 'irc_client', 'privmsg', $channel, 'Hier bin ich!'); + } + print "#-> $nick has joined $channel\n"; } @@ -100,7 +116,15 @@ sub irc_pub_msg{ } sub irc_priv_msg{ - print "Got a PM\n"; + my $kernel = $_[KERNEL]; + my $nick = (split /!/, $_[ARG0])[0]; + my $msg = $_[ARG2]; + + $kernel->post( 'irc_client', 'privmsg', $nick, 'Ich dich auch!'); + + $dbh->do( "INSERT INTO strings VALUES ('$nick', '$msg')" ); + + print "PRIV: [$nick] $msg\n"; } #start everything -- cgit v1.2.3