summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <>2005-07-20 14:56:49 +0000
committererdgeist <>2005-07-20 14:56:49 +0000
commitb1dc1d7a6254a68d3001f55c310d9ea4361ef3d3 (patch)
treec2ad7ba3a24fdb179b819918a5a62872d676f15a
parent9d90c78beadd8f0e8e34ead2a8c2e37f2e10a934 (diff)
Rudimentaere Databaseshiat
-rw-r--r--bot.pl30
1 files 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 @@
1#!/usr/bin/perl 1#!/usr/bin/perl
2 2
3use strict; 3use strict;
4use DBI;
4 5
6
7# IRC Server stuff
5use POE; 8use POE;
6use POE::Component::IRC; 9use POE::Component::IRC;
7 10
11my $current_nick = "francoise";
12my $channel = '#test';
13
8POE::Component::IRC->new("irc_client"); 14POE::Component::IRC->new("irc_client");
9 15
10POE::Session->new ( _start => \&irc_start, 16POE::Session->new ( _start => \&irc_start,
@@ -19,6 +25,10 @@ POE::Session->new ( _start => \&irc_start,
19 irc_msg => \&irc_priv_msg, 25 irc_msg => \&irc_priv_msg,
20); 26);
21 27
28# Database connection stuff
29my $dbh = DBI->connect("DBI:Pg:dbname='francoise'", 'francoise', 'kiffer')
30 or die "ohoh, datenbank b0rken: $!";
31
22sub irc_start { 32sub irc_start {
23 # KERNEL, HEAP, and SESSION are constants exported by POE 33 # KERNEL, HEAP, and SESSION are constants exported by POE
24 my $kernel = $_[KERNEL]; 34 my $kernel = $_[KERNEL];
@@ -28,7 +38,7 @@ sub irc_start {
28 $kernel->refcount_increment( $session->ID(), "my bot"); 38 $kernel->refcount_increment( $session->ID(), "my bot");
29 $kernel->post(irc_client=> register=> "all"); 39 $kernel->post(irc_client=> register=> "all");
30 40
31 $kernel->post(irc_client=>connect=> { Nick => 'francoise', 41 $kernel->post(irc_client=>connect=> { Nick => $current_nick,
32 Username => 'francoise', 42 Username => 'francoise',
33 Ircname => 'francoise', 43 Ircname => 'francoise',
34 Server => 'irc.kiffer.de', 44 Server => 'irc.kiffer.de',
@@ -40,7 +50,7 @@ sub irc_start {
40sub irc_connect { 50sub irc_connect {
41 my $kernel = $_[KERNEL]; 51 my $kernel = $_[KERNEL];
42 52
43 $kernel->post(irc_client=>join=>'#kiffer.de'); 53 $kernel->post(irc_client=>join=>$channel);
44} 54}
45 55
46sub irc_motd { 56sub irc_motd {
@@ -76,9 +86,15 @@ sub irc_part {
76 86
77#user joined 87#user joined
78sub irc_join { 88sub irc_join {
89 my $kernel = $_[KERNEL];
79 my $nick = (split /!/, $_[ARG0])[0]; 90 my $nick = (split /!/, $_[ARG0])[0];
80 my $channel = $_[ARG1]; 91 my $channel = $_[ARG1];
81 92
93 if( $nick eq $current_nick ) {
94 print "I JOIN JOIN JOIN\n";
95 $kernel->post( 'irc_client', 'privmsg', $channel, 'Hier bin ich!');
96 }
97
82 print "#-> $nick has joined $channel\n"; 98 print "#-> $nick has joined $channel\n";
83} 99}
84 100
@@ -100,7 +116,15 @@ sub irc_pub_msg{
100} 116}
101 117
102sub irc_priv_msg{ 118sub irc_priv_msg{
103 print "Got a PM\n"; 119 my $kernel = $_[KERNEL];
120 my $nick = (split /!/, $_[ARG0])[0];
121 my $msg = $_[ARG2];
122
123 $kernel->post( 'irc_client', 'privmsg', $nick, 'Ich dich auch!');
124
125 $dbh->do( "INSERT INTO strings VALUES ('$nick', '$msg')" );
126
127 print "PRIV: [$nick] $msg\n";
104} 128}
105 129
106#start everything 130#start everything