diff options
author | erdgeist <> | 2005-07-20 14:56:49 +0000 |
---|---|---|
committer | erdgeist <> | 2005-07-20 14:56:49 +0000 |
commit | b1dc1d7a6254a68d3001f55c310d9ea4361ef3d3 (patch) | |
tree | c2ad7ba3a24fdb179b819918a5a62872d676f15a | |
parent | 9d90c78beadd8f0e8e34ead2a8c2e37f2e10a934 (diff) |
Rudimentaere Databaseshiat
-rw-r--r-- | bot.pl | 30 |
1 files changed, 27 insertions, 3 deletions
@@ -1,10 +1,16 @@ | |||
1 | #!/usr/bin/perl | 1 | #!/usr/bin/perl |
2 | 2 | ||
3 | use strict; | 3 | use strict; |
4 | use DBI; | ||
4 | 5 | ||
6 | |||
7 | # IRC Server stuff | ||
5 | use POE; | 8 | use POE; |
6 | use POE::Component::IRC; | 9 | use POE::Component::IRC; |
7 | 10 | ||
11 | my $current_nick = "francoise"; | ||
12 | my $channel = '#test'; | ||
13 | |||
8 | POE::Component::IRC->new("irc_client"); | 14 | POE::Component::IRC->new("irc_client"); |
9 | 15 | ||
10 | POE::Session->new ( _start => \&irc_start, | 16 | POE::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 | ||
29 | my $dbh = DBI->connect("DBI:Pg:dbname='francoise'", 'francoise', 'kiffer') | ||
30 | or die "ohoh, datenbank b0rken: $!"; | ||
31 | |||
22 | sub irc_start { | 32 | sub 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 { | |||
40 | sub irc_connect { | 50 | sub 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 | ||
46 | sub irc_motd { | 56 | sub irc_motd { |
@@ -76,9 +86,15 @@ sub irc_part { | |||
76 | 86 | ||
77 | #user joined | 87 | #user joined |
78 | sub irc_join { | 88 | sub 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 | ||
102 | sub irc_priv_msg{ | 118 | sub 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 |