summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <>2005-07-23 17:38:59 +0000
committererdgeist <>2005-07-23 17:38:59 +0000
commit3672fa58704db16fdb0b2a95c2fe08b8ff1ae71c (patch)
tree80db8b4fbb582aa2211bcca39daaa9c24174cf7d
parent516c1f91af641f17bade476156ec0667a9b22857 (diff)
Zusammenfuehrung aller Nutzerqueries
-rw-r--r--bot.pl55
-rw-r--r--tables.sql3
2 files changed, 40 insertions, 18 deletions
diff --git a/bot.pl b/bot.pl
index 57ab3de..9f09cbd 100644
--- a/bot.pl
+++ b/bot.pl
@@ -110,14 +110,9 @@ sub irc_join {
110 my $host = (split /@/, $_[ARG0])[1]; 110 my $host = (split /@/, $_[ARG0])[1];
111 111
112 if( $nick eq $current_nick ) { 112 if( $nick eq $current_nick ) {
113 $kernel->post( 'irc_client', 'privmsg', $channel, 'Hier bin ich!'); 113 $kernel->post( 'irc_client', 'privmsg', $channel, 'Hier bin ich!');
114 } else { 114 } else {
115 my ($cnt) = $dbh->selectrow_array( "SELECT COUNT(*) FROM users WHERE nick='$nick'" ); 115 francoise_verifyuser( $nick, $host, 1 );
116 if ( $cnt == 0 ) {
117 $dbh->do( "INSERT INTO users(id, nick, words, lines, lastlogin, lasthost) VALUES ( '$nick', '$nick', 0, 0, now(), '$host' )");
118 } else {
119 $dbh->do( "UPDATE users SET lasthost = '$host', lastlogin = now() WHERE nick = '$nick'" );
120 }
121 } 116 }
122 117
123 print "#-> $nick has joined $channel\n"; 118 print "#-> $nick has joined $channel\n";
@@ -132,18 +127,21 @@ sub irc_quit {
132} 127}
133 128
134sub irc_pub_msg{ 129sub irc_pub_msg{
135 my $kernel = $_[KERNEL]; 130 my $kernel = $_[KERNEL];
136 my $nick = (split /!/, $_[ARG0])[0]; 131 my $nick = (split /!/, $_[ARG0])[0];
137 my $channel = $_[ARG1]->[0]; 132 my $channel = $_[ARG1]->[0];
138 my $msg = $_[ARG2]; 133 my $msg = $_[ARG2];
139 my $words = (split / /, $msg); 134 my @words = (split / /, $msg);
135 my $numwords = $#words;
140 136
141 if( $msg =~ /^!(\S+)(.*)$/ ) { 137 if( $msg =~ /^!(\S+)(.*)$/ ) {
142 &{$commands{ $1 } || \&francoise_donothing } ( $kernel, $channel, $msg ); 138 &{$commands{ $1 } || \&francoise_donothing } ( $kernel, $channel, $msg );
143 } 139 }
144 140
141 $nick = francoise_verifyuser( $nick, "", 0, $kernel );
142
145 if( $nick ne $current_nick ) { 143 if( $nick ne $current_nick ) {
146 $dbh->do( "UPDATE users SET lines = lines + 1, words = words + $words WHERE nick = '$nick'" ); 144 $dbh->do( "UPDATE users SET lines = lines + 1, words = words + $numwords + 1 WHERE nick = '$nick'" );
147 } 145 }
148 146
149 print "$channel: <$nick> $msg\n"; 147 print "$channel: <$nick> $msg\n";
@@ -154,7 +152,6 @@ sub irc_priv_msg{
154 my $nick = (split /!/, $_[ARG0])[0]; 152 my $nick = (split /!/, $_[ARG0])[0];
155 my $msg = $_[ARG2]; 153 my $msg = $_[ARG2];
156 154
157
158 if( $msg =~ /^!(\S+)(.*)$/ ) { 155 if( $msg =~ /^!(\S+)(.*)$/ ) {
159 &{$commands{ $1 } || \&francoise_donothing } ( $kernel, $nick, $msg ); 156 &{$commands{ $1 } || \&francoise_donothing } ( $kernel, $nick, $msg );
160 } 157 }
@@ -167,21 +164,43 @@ sub irc_whois{
167 my $host = (split / /, $_[ARG1])[2]; 164 my $host = (split / /, $_[ARG1])[2];
168 165
169 if( $nick ne $current_nick ) { 166 if( $nick ne $current_nick ) {
167 francoise_verifyuser( $nick, $host, 0 );
168 }
169}
170
171sub francoise_verifyuser {
172 my $nick_ = $_[0];
173 my $host = $_[1];
174 my $updtime = $_[2];
175 my $kernel = $_[3];
176
177 my $nick = ( split /_/, $nick_ )[0] || $nick_;
178
179 if( $host ) {
170 my ($cnt) = $dbh->selectrow_array( "SELECT COUNT(*) FROM users WHERE nick='$nick'" ); 180 my ($cnt) = $dbh->selectrow_array( "SELECT COUNT(*) FROM users WHERE nick='$nick'" );
171 if ( $cnt == 0 ) { 181 if ( $cnt == 0 ) {
172 $dbh->do( "INSERT INTO users(id, nick, words, lines, lastlogin, lasthost) VALUES ( '', '$nick', 0, 0, now(), '$host' )"); 182 $dbh->do( "INSERT INTO users(id, nick, words, lines, lastlogin, lasthost) VALUES ( '$nick', '$nick', 0, 0, now(), '$host' )");
173 } else { 183 } else {
174 $dbh->do( "UPDATE users SET lasthost = '$host' WHERE nick = '$nick'" ); 184 $dbh->do( "UPDATE users SET lasthost = '$host'" . ( $updtime ? ", lastlogin = now()" : "" ) . " WHERE nick = '$nick'" );
175 } 185 }
186 } else {
187 $kernel->post( 'irc_client', 'whois', $nick_);
176 } 188 }
189
190 return $nick;
177} 191}
178 192
179sub francoise_help { 193sub francoise_help {
180 my $kernel = $_[0]; 194 my $kernel = $_[0];
181 my $dest = $_[1]; 195 my $dest = $_[1];
182 196
183 $kernel->post( 'irc_client', 'privmsg', $dest, 'Ich bins doch.'); 197 $kernel->post( 'irc_client', 'privmsg', $dest, 'Hallo, ich bin Francoise, der freundliche Kifferchat-Bot.');
184 198 $kernel->post( 'irc_client', 'privmsg', $dest, 'Ich kann folgende Kommandos ausfuehren:');
199 $kernel->post( 'irc_client', 'privmsg', $dest, '!help Diese Hilfe anzeigen');
200 $kernel->post( 'irc_client', 'privmsg', $dest, '!stat Informationen ueber mich ausgeben');
201 $kernel->post( 'irc_client', 'privmsg', $dest, '!topten Die aktivsten Chatter anzeigen');
202 $kernel->post( 'irc_client', 'privmsg', $dest, '!topten0r Die 13370rsten Chatter anzeigen');
203 $kernel->post( 'irc_client', 'privmsg', $dest, '!forget Einen Trigger vergessen');
185} 204}
186 205
187sub francoise_stat { 206sub francoise_stat {
diff --git a/tables.sql b/tables.sql
index acb9e8f..533735a 100644
--- a/tables.sql
+++ b/tables.sql
@@ -13,6 +13,9 @@ create table users (
13 words integer, 13 words integer,
14 lines integer, 14 lines integer,
15 15
16 isaway bool default false,
17 awaymsg text,
18
16 lastlogin timestamp, 19 lastlogin timestamp,
17 lasthost text 20 lasthost text
18); 21);