]> git.donarmstrong.com Git - infobot.git/blobdiff - src/IRC/IrcHooks.pl
- irctextcounter: ORDER by counter, not nick!
[infobot.git] / src / IRC / IrcHooks.pl
index e90d26745842a8fb7c1403e493f4ef8ea8df6712..304246b81fb0926ecf0d1f12db0e5fb8c1da5249 100644 (file)
@@ -63,6 +63,11 @@ sub on_chat {
        my $crypto      = $users{$userHandle}{PASS};
        my $success     = 0;
 
+       if ($userHandle eq "_default") {
+           &WARN("DCC CHAT: _default/guest not allowed.");
+           return;
+       }
+
        ### TODO: prevent users without CRYPT chatting.
        if (!defined $crypto) {
            &DEBUG("todo: dcc close chat");
@@ -139,13 +144,15 @@ sub on_endofmotd {
 
     # first time run.
     if (!exists $users{_default}) {
-       &status("First time run... adding _default user.");
+       &status("!!! First time run... adding _default user.");
        $users{_default}{FLAGS} = "mrt";
-       $users{_default}{HOSTS} = "*!*@*";
+       $users{_default}{HOSTS}{"*!*@*"} = 1;
     }
 
     if (scalar keys %users < 2) {
-       &status("Ok... now /msg $ident PASS <pass> to get master access through DCC CHAT.");
+       &status("!"x40);
+       &status("!!! Ok.  Now type '/msg $ident PASS <pass>' to get master access through DCC CHAT.");
+       &status("!"x40);
     }
     # end of first time run.
 
@@ -227,9 +234,11 @@ sub on_dcc {
     } elsif ($type eq 'GET') { # SEND for us?
        &status("DCC: Initializing SEND for $nick.");
        $self->new_send($event->args);
+
     } elsif ($type eq 'CHAT') {
        &status("DCC: Initializing CHAT for $nick.");
        $self->new_chat($event);
+
     } else {
        &WARN("${b_green}DCC $type$ob (1)");
     }
@@ -294,7 +303,6 @@ sub on_dcc_open {
 
     } else {
        &WARN("${b_green}DCC $type$ob (3)");
-
     }
 }
 
@@ -314,17 +322,25 @@ sub on_dcc_open_chat {
 
     if (!exists $users{$userHandle}{HOSTS}) {
        &pSReply("you have no hosts defined in my user file; rejecting.");
-       ### TODO: $sock->close();
+       $sock->close();
        return;
     }
 
     my $crypto = $users{$userHandle}{PASS};
     $dcc{'CHAT'}{$nick} = $sock;
 
+    # todo: don't make DCC CHAT established in the first place.
+    if ($userHandle eq "_default") {
+       &dccsay($nick, "_default/guest not allowed");
+       $sock->close();
+       return;
+    }
+
     if (defined $crypto) {
+       &status("DCC CHAT: going to use ".$nick."'s crypt.");
        &dccsay($nick,"Enter your password.");
     } else {
-       &dccsay($nick,"Welcome to blootbot DCC CHAT interface, $userHandle.");
+#      &dccsay($nick,"Welcome to blootbot DCC CHAT interface, $userHandle.");
     }
 }
 
@@ -433,6 +449,7 @@ sub on_join {
     if (exists $netsplit{lc $who}) {
        delete $netsplit{lc $who};
        $netsplit = 1;
+
        if (!scalar keys %netsplit) {
            &DEBUG("on_join: netsplit hash is now empty!");
            undef %netsplitservers;
@@ -442,7 +459,7 @@ sub on_join {
     }
 
     if ($netsplit and !exists $cache{netsplit}) {
-       &DEBUG("on_join: ok.... re-running chanlimitCheck in 60.");
+       &VERB("on_join: ok.... re-running chanlimitCheck in 60.",2);
        $conn->schedule(60, sub {
                &chanlimitCheck();
                delete $cache{netsplit};
@@ -464,7 +481,8 @@ sub on_join {
     ### on-join bans.
     my @bans;
     push(@bans, keys %{ $bans{$chan} }) if (exists $bans{$chan});
-    push(@bans, keys %{ $bans{"*"} })  if (exists $bans{"*"});
+    push(@bans, keys %{ $bans{"*"} })   if (exists $bans{"*"});
+
     foreach (@bans) {
        my $ban = $_;
        s/\?/./g;
@@ -512,10 +530,10 @@ sub on_join {
     }
 
     ### ROOTWARN:
-    &rootWarn($who,$user,$host,$chan)
-               if (&IsChanConf("rootWarn") &&
-                   $user =~ /^r(oo|ew|00)t$/i &&
-                   $channels{$chan}{'o'}{$ident});
+    &rootWarn($who,$user,$host,$chan) if (
+               &IsChanConf("rootWarn") &&
+               $user =~ /^r(oo|ew|00)t$/i
+    );
 
     ### NEWS:
     if (&IsChanConf("news") && &IsChanConf("newsKeepRead")) {
@@ -574,8 +592,8 @@ sub on_mode {
 
 sub on_modeis {
     my ($self, $event) = @_;
-    my $nick = $event->nick();
     my ($myself, undef,@args) = $event->args();
+    my $nick   = $event->nick();
     $chan      = ($event->args())[1];
 
     &hookMode($nick, @args);
@@ -683,6 +701,7 @@ sub on_notice {
 
        if ($check) {
            &status("nickserv told us to register; doing it.");
+
            if (&IsParam("nickServ_pass")) {
                &status("NickServ: ==> Identifying.");
                &rawout("PRIVMSG NickServ :IDENTIFY $param{'nickServ_pass'}");
@@ -707,6 +726,7 @@ sub on_notice {
        }
     } elsif ($nick =~ /^ChanServ$/i) {         # chanserv.
        &status("ChanServ: <== '$args'.");
+
     } else {
        if ($chan =~ /^$mask{chan}$/) { # channel notice.
            &status("-$nick/$chan- $args");
@@ -740,7 +760,11 @@ sub on_part {
 
     $chanstats{$chan}{'Part'}++;
     &delUserInfo($nick,$chan);
-    &clearChanVars($chan) if ($nick eq $ident);
+    if ($nick eq $ident) {
+       &DEBUG("on_part: ok, I left $chan... clearChanVars...");
+       &clearChanVars($chan);
+    }
+
     if (!&IsNickInAnyChan($nick) and &IsChanConf("seenStats")) {
        delete $userstats{lc $nick};
     }
@@ -790,9 +814,20 @@ sub on_public {
        $userstats{lc $nick}{'Time'} = time();
     }
 
-#    if (&IsChanConf("hehCounter")) {
-#      #...
-#    }
+    # would this slow things down?
+    if ($_ = &getChanConf("ircTextCounters")) {
+       foreach (split /[\s]+/) {
+           next unless ($msg =~ /^\Q$_\E$/i);
+           &status("textcounters: $_ matched for $who");
+
+           my $v = &dbGet("stats", "counter", "nick='$who' and type='$msg'");
+           $v++;
+
+           &dbReplace("stats", (nick => $who, type => $_, counter => $v) );
+           # does not work, atleast with old mysql!!! :(
+#          &dbReplace("stats", (nick => $who, type => $_, -counter => "counter+1") );
+       }
+    }
 
     &hookMsg('public', $chan, $nick, $msg);
     $chanstats{$chan}{'PublicMsg'}++;
@@ -825,32 +860,17 @@ sub on_quit {
        &DEBUG("on_quit: nick $nick was not found in any chan.");
     }
 
-    &delUserInfo($nick, keys %channels);
-
-    if (exists $nuh{lc $nick}) {
-       delete $nuh{lc $nick};
-    } else {
-       &DEBUG("on_quit: nuh{lc $nick} does not exist! FIXME");
-    }
-    delete $userstats{lc $nick} if (&IsChanConf("seenStats"));
-    delete $chanstats{lc $nick};
-
     # should fix chanstats inconsistencies bug #2.
     if ($reason =~ /^($mask{host})\s($mask{host})$/) { # netsplit.
        $reason = "NETSPLIT: $1 <=> $2";
 
        # chanlimit code.
-       if (!scalar keys %netsplit) {
-           my @l = &getNickInChans($nick);
-           &DEBUG("on_quit: l => ".scalar(@l) );
+       foreach $chan ( &getNickInChans($nick) ) {
+           next unless ( &IsChanConf("chanlimitcheck") );
+           next unless ( exists $channels{$_}{'l'} );
 
-           foreach ( &getNickInChans($nick) ) {
-               next unless ( &IsChanConf("chanlimitcheck") );
-               next unless ( exists $channels{$_}{'l'} );
-
-               &status("on_quit: netsplit detected on $_; disabling chan limit.");
-               &rawout("MODE $_ -l");
-           }
+           &DEBUG("on_quit: netsplit detected on $_; disabling chan limit.");
+           &rawout("MODE $_ -l");
        }
 
        $netsplit{lc $nick} = time();
@@ -866,6 +886,20 @@ sub on_quit {
        &ERROR("^^^ THIS SHOULD NEVER HAPPEN (10).");
     }
 
+    ###
+    ### ok... lets clear out the cache
+    ###
+    &delUserInfo($nick, keys %channels);
+    if (exists $nuh{lc $nick}) {
+       delete $nuh{lc $nick};
+    } else {
+       # well.. it's good but weird that this has happened - lets just
+       # be quiet about it.
+    }
+    delete $userstats{lc $nick} if (&IsChanConf("seenStats"));
+    delete $chanstats{lc $nick};
+    ###
+
     # does this work?
     if ($nick !~ /^\Q$ident\E$/ and $nick =~ /^\Q$param{'ircNick'}\E$/i) {
        &status("nickchange: own nickname became free; changing.");
@@ -1027,6 +1061,7 @@ sub on_who {
        $cache{nuhInfo}{lc $args[5]}{Nick} = $args[5];
        $cache{nuhInfo}{lc $args[5]}{User} = $args[2];
        $cache{nuhInfo}{lc $args[5]}{Host} = $args[3];
+       $cache{nuhInfo}{lc $args[5]}{NUH}  = "$args[5]!$args[2]\@$args[3]";
        return;
     }