]> git.donarmstrong.com Git - infobot.git/blobdiff - src/IRC/IrcHooks.pl
take a few more things literally
[infobot.git] / src / IRC / IrcHooks.pl
index fc71c18011dd64c899fe6f3bf5d44894fc952335..cf873ce130051354bb93a1de350b44444b3e7dbf 100644 (file)
@@ -50,7 +50,7 @@ sub on_chat {
     }
 
     ### set vars that would have been set in hookMsg.
-    $userHandle                = "";   # reset.
+    $userHandle                = '';   # reset.
     $who               = lc $nick;
     $message           = $msg;
     $orig{who}         = $nick;
@@ -66,7 +66,7 @@ sub on_chat {
        my $crypto      = $users{$userHandle}{PASS};
        my $success     = 0;
 
-       if ($userHandle eq "_default") {
+       if ($userHandle eq '_default') {
            &WARN("DCC CHAT: _default/guest not allowed.");
            return;
        }
@@ -84,7 +84,7 @@ sub on_chat {
            $conn->privmsg($sock, "Commands start with '.' (like '.quit' or '.help')");
            $conn->privmsg($sock, "Everything else goes out to the party line.");
 
-           &dccStatus(2) unless (exists $sched{"dccStatus"}{RUNNING});
+           &dccStatus(2) unless (exists $sched{'dccStatus'}{RUNNING});
 
            $success++;
 
@@ -103,7 +103,7 @@ sub on_chat {
 
            $dcc{'CHATvrfy'}{$nick} = $userHandle;
 
-           return if ($userHandle eq "_default");
+           return if ($userHandle eq '_default');
 
            &dccsay($nick,"Flags: $users{$userHandle}{FLAGS}");
        }
@@ -115,9 +115,9 @@ sub on_chat {
 
     if ($message =~ s/^\.//) { # dcc chat commands.
        ### TODO: make use of &Forker(); here?
-       &loadMyModule( $myModules{'UserDCC'} );
+       &loadMyModule('UserDCC');
 
-       &DCCBroadcast("#$who# $message","m");
+       &DCCBroadcast("#$who# $message",'m');
 
        my $retval      = &userDCC();
        return unless (defined $retval);
@@ -160,7 +160,7 @@ sub on_endofmotd {
     # first time run.
     if (!exists $users{_default}) {
        &status("!!! First time run... adding _default user.");
-       $users{_default}{FLAGS} = "mrt";
+       $users{_default}{FLAGS} = 'amrt';
        $users{_default}{HOSTS}{"*!*@*"} = 1;
     }
 
@@ -171,7 +171,7 @@ sub on_endofmotd {
     }
     # end of first time run.
 
-    if (&IsChanConf("wingate")) {
+    if (&IsChanConf('Wingate') > 0) {
        my $file = "$bot_base_dir/$param{'ircUser'}.wingate";
        open(IN, $file);
        while (<IN>) {
@@ -183,11 +183,11 @@ sub on_endofmotd {
     }
 
     if ($firsttime) {
-       &ScheduleThis(1, "setupSchedulers");
+       &ScheduleThis(1, 'setupSchedulers');
        $firsttime = 0;
     }
 
-    if (&IsParam("ircUMode")) {
+    if (&IsParam('ircUMode')) {
        &VERB("Attempting change of user modes to $param{'ircUMode'}.", 2);
        if ($param{'ircUMode'} !~ /^[-+]/) {
            &WARN("ircUMode had no +- prefix; adding +");
@@ -204,7 +204,7 @@ sub on_endofmotd {
     $conn->ison($conn->nick());
 
     # Q, as on quakenet.org.
-    if (&IsParam("Q_pass")) {
+    if (&IsParam('Q_pass')) {
        &status("Authing to Q...");
        &rawout("PRIVMSG Q\@CServe.quakenet.org :AUTH $param{'Q_user'} $param{'Q_pass'}");
     }
@@ -231,6 +231,8 @@ sub on_dcc {
     my $type = uc( ($event->args)[1] );
     my $nick = lc $event->nick();
 
+    &status("on_dcc type=$type nick=$nick sock=$sock");
+
     # pity Net::IRC doesn't store nuh. Here's a hack :)
     if (!exists $nuh{lc $nick}) {
        $conn->whois($nick);
@@ -241,12 +243,16 @@ sub on_dcc {
     if ($type eq 'SEND') {     # GET for us.
        # incoming DCC SEND. we're receiving a file.
        my $get = ($event->args)[2];
-       open(DCCGET,">$get");
-
-       $conn->new_get($event, \*DCCGET);
+       &status("DCC: not Initializing GET from $nick to '$param{tempDir}/$get'");
+       # FIXME: do we want to get anything?
+       return;
+       #open(DCCGET,">$param{tempDir}/$get");
+       #$conn->new_get($event, \*DCCGET);
 
     } elsif ($type eq 'GET') { # SEND for us?
-       &status("DCC: Initializing SEND for $nick.");
+       &status("DCC: not Initializing SEND for $nick.");
+       # FIXME: do we want to do anything?
+       return;
        $conn->new_send($event->args);
 
     } elsif ($type eq 'CHAT') {
@@ -274,7 +280,7 @@ sub on_dcc_close {
     if (exists $dcc{'SEND'}{$nick} and -f "$param{tempDir}/$nick.txt") {
        &status("${b_green}DCC SEND$ob close from $b_cyan$nick$ob");
 
-       &status("dcc_close: purging $nick.txt from Debian.pl");
+       &status("dcc_close: purging DCC send $nick.txt");
        unlink "$param{tempDir}/$nick.txt";
 
        delete $dcc{'SEND'}{$nick};
@@ -294,6 +300,8 @@ sub on_dcc_open {
     my $nick = lc $event->nick();
     my $sock = ($event->to)[0];
 
+    &status("on_dcc_open type=$type nick=$nick sock=$sock");
+
     $msgType = 'chat';
     $type ||= "???";
     ### BUG: who is set to bot's nick?
@@ -307,15 +315,15 @@ sub on_dcc_open {
        ### TODO: run ScheduleThis inside on_dcc_open_chat recursively
        ###     1,3,5,10 seconds then fail.
        if ($nuh{$nick} eq "GETTING-NOW") {
-           &ScheduleThis(3/60, "on_dcc_open_chat", $nick, $sock);
+           &ScheduleThis(3/60, 'on_dcc_open_chat', $nick, $sock);
        } else {
            on_dcc_open_chat(undef, $nick, $sock);
        }
 
     } elsif ($type eq 'SEND') {
-       &DEBUG("Starting DCC receive.");
+       &status("Starting DCC receive.");
        foreach ($event->args) {
-           &DEBUG("  => '$_'.");
+           &status("  => '$_'.");
        }
 
     } else {
@@ -338,7 +346,7 @@ sub on_dcc_open_chat {
     &verifyUser($nick, $nuh{lc $nick});
 
     if (!exists $users{$userHandle}{HOSTS}) {
-       &pSReply("you have no hosts defined in my user file; rejecting.");
+       &performStrictReply("you have no hosts defined in my user file; rejecting.");
        $sock->close();
        return;
     }
@@ -347,7 +355,7 @@ sub on_dcc_open_chat {
     $dcc{'CHAT'}{$nick} = $sock;
 
     # TODO: don't make DCC CHAT established in the first place.
-    if ($userHandle eq "_default") {
+    if ($userHandle eq '_default') {
        &dccsay($nick, "_default/guest not allowed");
        $sock->close();
        return;
@@ -389,7 +397,7 @@ sub on_disconnect {
 
     &WARN("scheduling call ircCheck() in 60s");
     &clearIRCVars();
-    &ScheduleThis(1, "ircCheck");
+    &ScheduleThis(1, 'ircCheck');
 }
 
 sub on_endofnames {
@@ -412,13 +420,13 @@ sub on_endofnames {
 
     my $txt;
     my @array;
-    foreach ("o","v","") {
+    foreach ('o','v','') {
        my $count = scalar(keys %{ $channels{$chan}{$_} });
        next unless ($count);
 
-       $txt = "total" if ($_ eq "");
-       $txt = "voice" if ($_ eq "v");
-       $txt = "ops"   if ($_ eq "o");
+       $txt = 'total' if ($_ eq '');
+       $txt = 'voice' if ($_ eq 'v');
+       $txt = 'ops'   if ($_ eq 'o');
 
        push(@array, "$count $txt");
     }
@@ -469,17 +477,17 @@ sub on_join {
     my ($user,$host)   = split(/\@/, $event->userhost);
     $chan              = lc( ($event->to)[0] ); # CASING!!!!
     $who               = $event->nick();
-    $msgType           = "public";
+    $msgType           = 'public';
     my $i              = scalar(keys %{ $channels{$chan} });
     my $j              = $cache{maxpeeps}{$chan} || 0;
 
-    if (!&IsParam("noSHM") && time() > ($sched{shmFlush}{TIME} || time()) + 3600) {
+    if (!&IsParam('noSHM') && time() > ($sched{shmFlush}{TIME} || time()) + 3600) {
        &DEBUG("looks like schedulers died somewhere... restarting...");
        &setupSchedulers();
     }
 
     $chanstats{$chan}{'Join'}++;
-    $userstats{lc $who}{'Join'} = time() if (&IsChanConf("seenStats") > 0);
+    $userstats{lc $who}{'Join'} = time() if (&IsChanConf('seenStats') > 0);
     $cache{maxpeeps}{$chan}    = $i if ($i > $j);
 
     &joinfloodCheck($who, $chan, $event->userhost);
@@ -510,7 +518,7 @@ sub on_join {
 
     # how to tell if there's a netjoin???
 
-    my $netsplitstr = "";
+    my $netsplitstr = '';
     $netsplitstr = " $b_yellow\[${ob}NETSPLIT VICTIM$b_yellow]$ob" if ($netsplit);
     &status(">>> join/$b_blue$chan$ob $b_cyan$who$ob $b_yellow($ob$user\@$host$b_yellow)$ob$netsplitstr");
 
@@ -521,7 +529,7 @@ 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 = $_;
@@ -536,7 +544,7 @@ sub on_join {
        }
 
        my $reason = "no reason";
-       foreach ($chan, "*") {
+       foreach ($chan, '*') {
            next unless (exists $bans{$_});
            next unless (exists $bans{$_}{$ban});
 
@@ -572,21 +580,24 @@ sub on_join {
 
     ### ROOTWARN:
     &rootWarn($who,$user,$host,$chan) if (
-               &IsChanConf('RootWarn') &&
+               &IsChanConf('RootWarn') > 0 &&
                $user =~ /^~?r(oo|ew|00)t$/i
     );
 
+    ### emit a message based on who just joined
+        &onjoin($who,$user,$host,$chan) if (&IsChanConf('OnJoin') > 0);
+
     ### NEWS:
-    if (&IsChanConf("news") && &IsChanConf("newsKeepRead")) {
-       if (!&loadMyModule("news")) {   # just in case.
-           &DEBUG("could not load news.");
+    if (&IsChanConf('News') > 0 && &IsChanConf('newsKeepRead') > 0) {
+       if (!&loadMyModule('News')) {   # just in case.
+           &DEBUG('could not load news.');
        } else {
            &News::latest($chan);
        }
     }
 
     ### botmail:
-    if (&IsChanConf("botmail")) {
+    if (&IsChanConf('botmail') > 0) {
        &botmail::check(lc $who);
     }
 
@@ -626,7 +637,7 @@ sub on_mode {
     $chan      = ($event->to)[0];
 
     # last element is empty... so nuke it.
-    pop @args while ($args[$#args] eq "");
+    pop @args while ($args[$#args] eq '');
 
     if ($nick eq $chan) {      # UMODE
        &status(">>> mode $b_yellow\[$ob$b@args$b_yellow\]$ob by $b_cyan$nick$ob");
@@ -659,7 +670,7 @@ sub on_msg {
     $h         = $host;
 
     if ($nick eq $ident) { # hopefully ourselves.
-       if ($msg eq "TEST") {
+       if ($msg eq 'TEST') {
            &status("IRCTEST: Yes, we're alive.");
            delete $cache{connect};
            return;
@@ -667,9 +678,9 @@ sub on_msg {
     }
 
     &hookMsg('private', undef, $nick, $msg);
-    $who       = "";
-    $chan      = "";
-    $msgType   = "";
+    $who       = '';
+    $chan      = '';
+    $msgType   = '';
 }
 
 sub on_names {
@@ -711,9 +722,10 @@ sub on_nick {
     $nuh{lc $newnick} = $nuh{lc $nick};
     delete $nuh{lc $nick};
 
-    if ($nick eq $ident) {
+    if ($nick eq $conn->nick()) {
        &status(">>> I materialized into $b_green$newnick$ob from $nick");
-       $ident  = $newnick;
+       $ident = $newnick;
+       $conn->nick($newnick);
     } else {
        &status(">>> $b_cyan$nick$ob materializes into $b_green$newnick$ob");
        my $mynick=$conn->nick();
@@ -727,7 +739,7 @@ sub on_nick_taken {
     $conn = shift(@_);
     my $nick   = $conn->nick();
     #my $newnick = $nick . int(rand 10);
-    my $newnick = $nick . "_";
+    my $newnick = $nick . '_';
 
     &DEBUG("on_nick_taken: nick => $nick");
 
@@ -757,7 +769,7 @@ sub on_notice {
        if ($check) {
            &status("nickserv told us to register; doing it.");
 
-           if (&IsParam("nickServ_pass")) {
+           if (&IsParam('nickServ_pass')) {
                &status("NickServ: ==> Identifying.");
                &rawout("PRIVMSG NickServ :IDENTIFY $param{'nickServ_pass'}");
                return;
@@ -770,7 +782,7 @@ sub on_notice {
        if ($args =~ /^Password a/i) {
            my $done    = 0;
 
-           foreach ( &ChanConfList("chanServ_ops") ) {
+           foreach ( &ChanConfList('chanServ_ops') ) {
                next unless &chanServCheck($_);
                next if ($done);
                &DEBUG("nickserv activated or restarted; doing chanserv check.");
@@ -811,7 +823,7 @@ sub on_part {
     my $nick   = $event->nick;
     my $userhost = $event->userhost;
     $who       = $nick;
-    $msgType   = "public";
+    $msgType   = 'public';
 
     if (!exists $channels{$chan}) {
        &DEBUG("on_part: found out $mynick is on $chan!");
@@ -828,7 +840,7 @@ sub on_part {
        &clearChanVars($chan);
     }
 
-    if (!&IsNickInAnyChan($nick) and &IsChanConf("seenStats") > 0) {
+    if (!&IsNickInAnyChan($nick) and &IsChanConf('seenStats') > 0) {
        delete $userstats{lc $nick};
     }
 
@@ -862,13 +874,13 @@ sub on_ping_reply {
 sub on_public {
     $conn = shift(@_);
     my ($event) = @_;
-    my $msg    = ($event->args)[0];
+    my $msg    = ($event->args)[0];
     $chan      = lc( ($event->to)[0] );        # CASING.
     my $nick   = $event->nick;
     $who       = $nick;
     $uh                = $event->userhost();
     $nuh       = $nick."!".$uh;
-    $msgType   = "public";
+    $msgType   = 'public';
     # TODO: move this out of hookMsg to here?
     ($user,$host) = split(/\@/, $uh);
     $h         = $host;
@@ -882,7 +894,7 @@ sub on_public {
     $msgtime           = time();
     $lastWho{$chan}    = $nick;
     ### TODO: use $nick or lc $nick?
-    if (&IsChanConf("seenStats") > 0) {
+    if (&IsChanConf('seenStats') > 0) {
        $userstats{lc $nick}{'Count'}++;
        $userstats{lc $nick}{'Time'} = time();
     }
@@ -891,7 +903,7 @@ sub on_public {
     my $time   = time();
     if (!$cache{ircTextCounters}) {
        &DEBUG("caching ircTextCounters for first time.");
-       my @str = split(/\s+/, &getChanConf("ircTextCounters"));
+       my @str = split(/\s+/, &getChanConf('ircTextCounters'));
        for (@str) { $_ = quotemeta($_); }
        $cache{ircTextCounters} = join('|', @str);
     }
@@ -901,11 +913,11 @@ sub on_public {
        my $x = $1;
 
        &VERB("textcounters: $x matched for $who",2);
-       my $c = $chan || "PRIVATE";
+       my $c = $chan || 'PRIVATE';
 
        # better to do "counter=counter+1".
        # but that will avoid time check.
-       my ($v,$t) = &sqlSelect("stats", "counter,time", {
+       my ($v,$t) = &sqlSelect('stats', "counter,time", {
                        nick    => $who,
                        type    => $x,
                        channel => $c,
@@ -914,8 +926,7 @@ sub on_public {
 
        # don't allow ppl to cheat the stats :-)
        if (defined $t && $time - $t > 60) {
-           &sqlReplace("stats", {
-               nick    => $who,
+           &sqlSet('stats', {'nick' => $who}, {
                type    => $x,
                channel => $c,
                time    => $time,
@@ -926,9 +937,9 @@ sub on_public {
 
     &hookMsg('public', $chan, $nick, $msg);
     $chanstats{$chan}{'PublicMsg'}++;
-    $who       = "";
-    $chan      = "";
-    $msgType   = "";
+    $who       = '';
+    $chan      = '';
+    $msgType   = '';
 }
 
 sub on_quit {
@@ -938,7 +949,7 @@ sub on_quit {
     my $reason = ($event->args)[0];
 
     # hack for ICC.
-    $msgType   = "public";
+    $msgType   = 'public';
     $who       = $nick;
 ###    $chan   = $reason;      # no.
 
@@ -962,7 +973,7 @@ sub on_quit {
 
        # chanlimit code.
        foreach $chan ( &getNickInChans($nick) ) {
-           next unless ( &IsChanConf("chanlimitcheck") );
+           next unless ( &IsChanConf('chanlimitcheck') > 0);
            next unless ( exists $channels{$_}{'l'} );
 
            &DEBUG("on_quit: netsplit detected on $_; disabling chan limit.");
@@ -989,7 +1000,7 @@ sub on_quit {
        # well.. it's good but weird that this has happened - lets just
        # be quiet about it.
     }
-    delete $userstats{lc $nick} if (&IsChanConf("seenStats") > 0);
+    delete $userstats{lc $nick} if (&IsChanConf('seenStats') > 0);
     delete $chanstats{lc $nick};
     ###
 
@@ -1058,7 +1069,7 @@ sub on_topic {
        &status(">>> topic/$b_blue$chan$ob by $b_cyan$nick$ob -> $topic");
     } else {                                           # join.
        my ($nick, $chan, $topic) = $event->args;
-       if (&IsChanConf('Topic')) {
+       if (&IsChanConf('Topic') > 0) {
            $topic{$chan}{'Current'}    = $topic;
            &topicAddHistory($chan,$topic);
        }