diff options
author | erdgeist <> | 2005-07-21 02:59:52 +0000 |
---|---|---|
committer | erdgeist <> | 2005-07-21 02:59:52 +0000 |
commit | 937f46fb74c72e829a015ed196bb87c86fee3435 (patch) | |
tree | 701458b9cc6316f1ce8eec6b2252c86910ab819c | |
parent | b1dc1d7a6254a68d3001f55c310d9ea4361ef3d3 (diff) |
erster datenbankshiat: userhandling
-rw-r--r-- | bot.pl | 49 |
1 files changed, 42 insertions, 7 deletions
@@ -21,6 +21,7 @@ POE::Session->new ( _start => \&irc_start, | |||
21 | irc_376 => \&irc_connect, #end of motd | 21 | irc_376 => \&irc_connect, #end of motd |
22 | irc_372 => \&irc_motd, | 22 | irc_372 => \&irc_motd, |
23 | irc_353 => \&irc_names, | 23 | irc_353 => \&irc_names, |
24 | irc_311 => \&irc_whois, | ||
24 | irc_public => \&irc_pub_msg, | 25 | irc_public => \&irc_pub_msg, |
25 | irc_msg => \&irc_priv_msg, | 26 | irc_msg => \&irc_priv_msg, |
26 | ); | 27 | ); |
@@ -60,12 +61,18 @@ sub irc_motd { | |||
60 | } | 61 | } |
61 | 62 | ||
62 | sub irc_names { | 63 | sub irc_names { |
64 | my $kernel = $_[KERNEL]; | ||
63 | my $names = (split /:/, $_[ARG1])[1]; | 65 | my $names = (split /:/, $_[ARG1])[1]; |
64 | my $channel = (split /:/, $_[ARG1])[0]; | 66 | my $channel = (split /:/, $_[ARG1])[0]; |
65 | 67 | ||
66 | $channel =~ s/[@|=] (.*?) /$1/; | 68 | $channel =~ s/[@|=] (.*?) /$1/; |
67 | 69 | ||
68 | print "#-> Users on $channel [ $names ]\n"; | 70 | print "#-> Users on $channel [ $names ]\n"; |
71 | |||
72 | for my $user (split / /, $names) { | ||
73 | $user =~ s/^@|%|\+//; | ||
74 | $kernel->post( 'irc_client', 'whois', $user); | ||
75 | } | ||
69 | } | 76 | } |
70 | 77 | ||
71 | #nick change | 78 | #nick change |
@@ -73,6 +80,10 @@ sub irc_nick { | |||
73 | my $oldnick = (split /!/, $_[ARG0])[0]; | 80 | my $oldnick = (split /!/, $_[ARG0])[0]; |
74 | my $newnick = $_[ARG1]; | 81 | my $newnick = $_[ARG1]; |
75 | 82 | ||
83 | if( $newnick ne $current_nick ) { | ||
84 | $dbh->do( "UPDATE users SET nick = '$newnick' WHERE nick = '$oldnick'" ); | ||
85 | } | ||
86 | |||
76 | print "#-> $oldnick is now known as $newnick\n"; | 87 | print "#-> $oldnick is now known as $newnick\n"; |
77 | } | 88 | } |
78 | 89 | ||
@@ -89,12 +100,19 @@ sub irc_join { | |||
89 | my $kernel = $_[KERNEL]; | 100 | my $kernel = $_[KERNEL]; |
90 | my $nick = (split /!/, $_[ARG0])[0]; | 101 | my $nick = (split /!/, $_[ARG0])[0]; |
91 | my $channel = $_[ARG1]; | 102 | my $channel = $_[ARG1]; |
103 | my $host = (split /@/, $_[ARG0])[1]; | ||
92 | 104 | ||
93 | if( $nick eq $current_nick ) { | 105 | if( $nick eq $current_nick ) { |
94 | print "I JOIN JOIN JOIN\n"; | ||
95 | $kernel->post( 'irc_client', 'privmsg', $channel, 'Hier bin ich!'); | 106 | $kernel->post( 'irc_client', 'privmsg', $channel, 'Hier bin ich!'); |
107 | } else { | ||
108 | my ($cnt) = $dbh->selectrow_array( "SELECT COUNT(*) FROM users WHERE nick='$nick'" ); | ||
109 | if ( $cnt == 0 ) { | ||
110 | $dbh->do( "INSERT INTO users(id, nick, words, lines, lastlogin, lasthost) VALUES ( '$nick', '$nick', 0, 0, now(), '$host' )"); | ||
111 | } else { | ||
112 | $dbh->do( "UPDATE users SET lasthost = '$host', lastlogin = now() WHERE nick = '$nick'" ); | ||
113 | } | ||
96 | } | 114 | } |
97 | 115 | ||
98 | print "#-> $nick has joined $channel\n"; | 116 | print "#-> $nick has joined $channel\n"; |
99 | } | 117 | } |
100 | 118 | ||
@@ -107,10 +125,15 @@ sub irc_quit { | |||
107 | } | 125 | } |
108 | 126 | ||
109 | sub irc_pub_msg{ | 127 | sub irc_pub_msg{ |
110 | my $kernel = $_[KERNEL]; | 128 | my $kernel = $_[KERNEL]; |
111 | my $nick = (split /!/, $_[ARG0])[0]; | 129 | my $nick = (split /!/, $_[ARG0])[0]; |
112 | my $channel = $_[ARG1]->[0]; | 130 | my $channel = $_[ARG1]->[0]; |
113 | my $msg = $_[ARG2]; | 131 | my $msg = $_[ARG2]; |
132 | my $words = (split / /, $msg); | ||
133 | |||
134 | if( $nick ne $current_nick ) { | ||
135 | $dbh->do( "UPDATE users SET lines = lines + 1, words = words + $words WHERE nick = '$nick'" ); | ||
136 | } | ||
114 | 137 | ||
115 | print "$channel: <$nick> $msg\n"; | 138 | print "$channel: <$nick> $msg\n"; |
116 | } | 139 | } |
@@ -122,10 +145,22 @@ sub irc_priv_msg{ | |||
122 | 145 | ||
123 | $kernel->post( 'irc_client', 'privmsg', $nick, 'Ich dich auch!'); | 146 | $kernel->post( 'irc_client', 'privmsg', $nick, 'Ich dich auch!'); |
124 | 147 | ||
125 | $dbh->do( "INSERT INTO strings VALUES ('$nick', '$msg')" ); | ||
126 | |||
127 | print "PRIV: [$nick] $msg\n"; | 148 | print "PRIV: [$nick] $msg\n"; |
128 | } | 149 | } |
129 | 150 | ||
151 | sub irc_whois{ | ||
152 | my $nick = (split / /, $_[ARG1])[0]; | ||
153 | my $host = (split / /, $_[ARG1])[2]; | ||
154 | |||
155 | if( $nick ne $current_nick ) { | ||
156 | my ($cnt) = $dbh->selectrow_array( "SELECT COUNT(*) FROM users WHERE nick='$nick'" ); | ||
157 | if ( $cnt == 0 ) { | ||
158 | $dbh->do( "INSERT INTO users(id, nick, words, lines, lastlogin, lasthost) VALUES ( '', '$nick', 0, 0, now(), '$host' )"); | ||
159 | } else { | ||
160 | $dbh->do( "UPDATE users SET lasthost = '$host' WHERE nick = '$nick'" ); | ||
161 | } | ||
162 | } | ||
163 | } | ||
164 | |||
130 | #start everything | 165 | #start everything |
131 | $poe_kernel->run(); | 166 | $poe_kernel->run(); |