]> git.donarmstrong.com Git - infobot.git/commitdiff
- added support/hack for channel +o as "+o" in bot user file.
authordms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Sat, 2 Nov 2002 15:41:32 +0000 (15:41 +0000)
committerdms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Sat, 2 Nov 2002 15:41:32 +0000 (15:41 +0000)
  requires +O in user file for this to be activated.
- converted most instances of &rawout() to $conn->function();
- typo for default userHandle. woops.
- uptimeWriteFile() should work now; use IsChanConf() instead.
- fixed channel key support. forgot about it when we changed over to
  Net::IRC.
- added support for Q on quakenet.org - can be adapted for other servers
  I guess.
- added el-cheapo throttling to $conn->notice() in News module.
  TODO: implement this in our &notice() + &msg() functions.

git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@593 c11ca15a-4712-0410-83d8-924469b57eb5

14 files changed:
src/Factoids/Question.pl
src/IRC/Irc.pl
src/IRC/IrcHelpers.pl
src/IRC/IrcHooks.pl
src/IRC/Schedulers.pl
src/Modules/News.pl
src/Modules/RootWarn.pl
src/Modules/Topic.pl
src/Modules/Uptime.pl
src/Modules/UserDCC.pl
src/Process.pl
src/UserExtra.pl
src/core.pl
src/modules.pl

index e05fe6ad782762969be397b1228de4a1bcb43776..2c1a6e5c5dc5232b6b6dca25109ec2b014d7bf85 100644 (file)
@@ -170,7 +170,7 @@ sub factoidArgs {
     # which will make it less than linear => quicker!
     # todo: cache this, update cache when altered. !!! !!! !!!
 #    my $t = &timeget();
-    my @list = &searchTable("factoids", "factoid_key", "factoid_key", "CMD: ");
+    my @list = &searchTable("factoids", "factoid_key", "factoid_key", "^CMD: ");
 #    my $delta_time = &timedelta($t);
 #    &DEBUG("factArgs: delta_time = $delta_time s");
 #    &DEBUG("factArgs: list => ".scalar(@list) );
index cdc98fa1c5d3b59aa765de94218e9672fb564588..d7adf87238273869d0143cc55db94025a464a5a0 100644 (file)
@@ -277,16 +277,13 @@ sub action {
        return;
     }
 
-    my $rawout = "PRIVMSG $target :\001ACTION $txt\001";
-    if (length $rawout > 510) {
+    if (length $txt > 480) {
        &status("action: txt too long; truncating.");
-
-       chop($rawout) while (length($rawout) > 510);
-       $rawout .= "\001";
+       chop($txt) while (length $txt > 480);
     }
 
     &status("* $ident/$target $txt");
-    rawout($rawout);
+    $conn->me($target, $txt);
 }
 
 # Usage: &notice(nick || chan, txt);
@@ -428,23 +425,23 @@ sub dcc_close {
 }
 
 sub joinchan {
-    my ($chankey) = @_;
-    my $chan = lc $chankey;
+    my ($chan) = @_;
+    my $key    = &getChanConf("chankey", $chan) || "";
 
-    if ($chankey =~ s/^($mask{chan}),\S+/ /) {
-       $chan = lc $1;
-    }
+    # forgot for about 2 years to implement channel keys when moving
+    # over to Net::IRC...
 
     # hopefully validChan is right.
     if (&validChan($chan)) {
        &status("join: already on $chan");
     } else {
        &status("joining $b_blue$chan$ob");
-       if (!$conn->join($chan)) {
-           &DEBUG("joinchan: join failed. trying connect!");
-           &clearIRCVars();
-           $conn->connect();
-       }
+
+       return if ($conn->join($chan, $key));
+
+       &DEBUG("joinchan: join failed. trying connect!");
+       &clearIRCVars();
+       $conn->connect();
     }
 }
 
@@ -466,7 +463,7 @@ sub part {
 #          next;
        }
 
-       rawout("PART $chan");
+       $conn->part($chan);
        # deletion of $channels{chan} is done in &entryEvt().
     }
 }
@@ -482,6 +479,7 @@ sub mode {
 
     &DEBUG("mode: MODE $chan $modes");
 
+    # should move to use Net::IRC's $conn->mode()... but too lazy.
     rawout("MODE $chan $modes");
 }
 
@@ -512,21 +510,17 @@ sub kick {
 
     foreach $chan (@chans) {
        if (!&IsNickInChan($nick,$chan)) {
-           &status("Kick: $nick is not on $chan.") if (scalar @chans == 1);
+           &status("kick: $nick is not on $chan.") if (scalar @chans == 1);
            next;
        }
 
        if (!exists $channels{$chan}{o}{$ident}) {
-           &status("Kick: do not have ops on $chan :(");
+           &status("kick: do not have ops on $chan :(");
            next;
        }
 
        &status("Kicking $nick from $chan.");
-       if ($msg eq "") {
-           &rawout("KICK $chan $nick");
-       } else {
-           &rawout("KICK $chan $nick :$msg");
-       }
+       $conn->kick($chan, $nick, $msg);
     }
 }
 
@@ -542,7 +536,7 @@ sub ban {
 
     foreach $chan (@chans) {
        if (!exists $channels{$chan}{o}{$ident}) {
-           &status("Ban: do not have ops on $chan :(");
+           &status("ban: do not have ops on $chan :(");
            next;
        }
 
@@ -629,9 +623,10 @@ sub nick {
 
 sub invite {
     my($who, $chan) = @_;
-    rawout("INVITE $who $chan");
-}
+    # todo: check if $who or $chan are invalid.
 
+    $conn->invite($who, $chan);
+}
 
 ##########
 # Channel related functions...
@@ -894,7 +889,7 @@ sub getHostMask {
        return &makeHostMask($nuh{$n});
     } else {
        $cache{on_who_Hack} = 1;
-       &rawout("WHO $n");
+       $conn->who($n);
     }
 }
 
index 53d3db7f71b19895f7b43d2b44ce607ba15c7a8f..68ea16466d0e8da05ca4da29635fe2a711448dea 100644 (file)
@@ -314,7 +314,7 @@ sub chanLimitVerify {
     &status("clc: big change in limit for $chan ($delta);".
                "going for it. (was: $l; now: ".($count+$plus).")");
 
-    &rawout("MODE $chan +l ".($count+$plus) );
+    $conn->mode($chan, "+l", $count+$plus);
     $cache{chanlimitChange}{$chan} = time();
 }
 
@@ -338,7 +338,7 @@ sub chanServCheck {
 
     if ( &IsParam("nickServ_pass") and !$nickserv) {
        &DEBUG("chanServ_ops($chan): nickserv enabled but not alive? (ircCheck)");
-       &rawout("WHO NickServ");
+       $conn->who("NickServ");
        return 0;
     }
     # check for first hash then for next hash.
index 8370a2178650f8c54d8a14dfa2e30ad33bc31e7f..117daa2d3f03ca0889b2d1e45be3d001f372727f 100644 (file)
@@ -192,10 +192,14 @@ sub on_endofmotd {
     # ok, we're free to do whatever we want now. go for it!
     $running = 1;
 
-    # unfortunately, Net::IRC does not implement this :(
-    # invalid command... what is it?
-#    &rawout("NOTIFY $ident");
-#    &DEBUG("adding self to NOTIFY list.");
+    $conn->ison($ident);
+    &DEBUG("adding self to NOTIFY/ISON.");
+
+    # Q, as on quakenet.org.
+    if (&IsParam("Q_pass")) {
+       &status("Authing to Q...");
+       &rawout("PRIVMSG Q\@CServe.quakenet.org :AUTH $param{'Q_user'} $param{'Q_pass'}");
+    }
 
     &joinNextChan();
 }
@@ -228,13 +232,8 @@ sub on_dcc {
        my $get = ($event->args)[2];
        open(DCCGET,">$get");
 
-       $self->new_get($nick,
-               ($event->args)[2],
-               ($event->args)[3],
-               ($event->args)[4],
-               ($event->args)[5],
-               \*DCCGET
-       );
+       $self->new_get($event, \*DCCGET);
+
     } elsif ($type eq 'GET') { # SEND for us?
        &status("DCC: Initializing SEND for $nick.");
        $self->new_send($event->args);
@@ -242,6 +241,7 @@ sub on_dcc {
     } elsif ($type eq 'CHAT') {
        &status("DCC: Initializing CHAT for $nick.");
        $self->new_chat($event);
+#      $self->new_chat(1, $nick, $event->host);
 
     } else {
        &WARN("${b_green}DCC $type$ob (1)");
@@ -397,7 +397,7 @@ sub on_endofnames {
        &status("$b_blue$chan$ob: sync in ${delta_time}s.");
     }
 
-    &rawout("MODE $chan");
+    $conn->mode($chan);
 
     my $txt;
     my @array;
@@ -459,7 +459,7 @@ sub on_join {
     my $i              = scalar(keys %{ $channels{$chan} });
     my $j              = $cache{maxpeeps}{$chan} || 0;
 
-    if (time() > $sched{shmFlush}{TIME} + 3600) {
+    if (time() > ($sched{shmFlush}{TIME} || time()) + 3600) {
        &DEBUG("looks like schedulers died somewhere... restarting...");
        &setupSchedulers();
     }
@@ -551,7 +551,7 @@ sub on_join {
 
        ### TODO: move this to &joinchan()?
        $cache{jointime}{$chan} = &timeget();
-       rawout("WHO $chan");
+       $conn->who($chan);
 
        return;
     }
@@ -752,6 +752,7 @@ sub on_notice {
 
            $nickserv++;
        }
+
     } elsif ($nick =~ /^ChanServ$/i) {         # chanserv.
        &status("ChanServ: <== '$args'.");
 
@@ -934,7 +935,7 @@ sub on_quit {
            next unless ( exists $channels{$_}{'l'} );
 
            &DEBUG("on_quit: netsplit detected on $_; disabling chan limit.");
-           &rawout("MODE $_ -l");
+           $conn->mode($_, "-l");
        }
 
        $netsplit{lc $nick} = time();
index be8099133cd41a0dac84dc74f0ea369882e4689c..9c5bbeda5409c2b045f0601ff120b5096504abb0 100644 (file)
@@ -386,7 +386,7 @@ sub chanlimitCheck {
        if (scalar keys %netsplitservers) {
            if (defined $limit) {
                &status("chanlimit: netsplit; removing it for $chan.");
-               &rawout("MODE $chan -l");
+               $conn->mode($chan, "-l");
                $cache{chanlimitChange}{$chan} = time();
                &status("chanlimit: netsplit; removed.");
            }
@@ -405,7 +405,7 @@ sub chanlimitCheck {
        }
 
        if (!exists $channels{$chan}{'o'}{$ident}) {
-           &status("ChanLimit: dont have ops on $chan.") unless (exists $cache{warn}{chanlimit}{$chan});
+           &status("chanlimit: dont have ops on $chan.") unless (exists $cache{warn}{chanlimit}{$chan});
            $cache{warn}{chanlimit}{$chan} = 1;
            &chanServCheck($chan);
            next;
@@ -413,18 +413,18 @@ sub chanlimitCheck {
        delete $cache{warn}{chanlimit}{$chan};
 
        if (!defined $limit) {
-           &status("chanLimit: setting for first time or from netsplit, for $chan");
+           &status("chanlimit: setting for first time or from netsplit, for $chan");
        }
 
        if (exists $cache{chanlimitChange}{$chan}) {
            my $delta = time() - $cache{chanlimitChange}{$chan};
            if ($delta < $interval*60) {
-               &DEBUG("chanLimit: not going to change chanlimit! ($delta<$interval*60)");
+               &DEBUG("chanlimit: not going to change chanlimit! ($delta<$interval*60)");
                return;
            }
        }
 
-       &rawout("MODE $chan +l $newlimit");
+       $conn->mode($chan, "+l", $newlimit);
        $cache{chanlimitChange}{$chan} = time();
     }
 }
index 478c86104b8782e96101a4fc76278c8bb04baa16..54e5591fc9098fb77a9e097f6feb87b86ee57816 100644 (file)
@@ -812,23 +812,29 @@ sub latest {
            &::notice($who, "|= Last time read $timestr ago");
        }
 
+       my $i;
        my @sorted;
        foreach (@new) {
-           my $i   = &newsS2N($_);
+           $i   = &newsS2N($_);
            $sorted[$i] = $_;
        }
-
-       for (my $i=0; $i<=scalar(@sorted); $i++) {
+       
+       for ($i=0; $i<=scalar(@sorted); $i++) {
            my $news = $sorted[$i];
            next unless (defined $news);
 
            my $age = time() - $::news{$chan}{$news}{Time};
-           &::notice($who, sprintf("\002[\002%2d\002]\002 %s",
-               $i, $news) );
-#              $i, $_, &::Time2String($age) ) );
+           $::conn->schedule(int((2+$i)/2), sub {
+               &::notice($who, sprintf("\002[\002%2d\002]\002 %s",
+                       $i, $news) );
+#                      $i, $_, &::Time2String($age) ) );
+           } );
        }
 
-       &::notice($who, "|= to read, do \002news $chan read <#>\002 or \002news $chan read <keyword>\002");
+       # todo: implement throttling via schedule into &notice() / &msg().
+       $::conn->schedule(int((2+$i)/2), sub {
+           &::notice($who, "|= to read, do \002news $chan read <#>\002 or \002news $chan read <keyword>\002");
+       } );
 
        # lame hack to prevent dupes if we just ignore it.
        my $x = $::newsuser{$chan}{$who};
index 5c2cf62d9680e4ff6196698eeba442010dcc55ab..086cac506af6663c06a90f44f767dd0967e816fb 100644 (file)
@@ -18,7 +18,7 @@ sub rootWarn {
            &status("rootwarn: Detected root user; notifying user");
        } else {
            &status("rootwarn: Detected root user; notifying nick and channel.");
-           rawout("PRIVMSG $chan :ROO".("O" x int(rand 68))."T has landed!");
+           &msg($chan, "ROO".("O" x int(rand 68))."T has landed!");
        }
 
        if ($_ = &getFactoid("root")) {
index c0d9d95c879abd62284936ae3aa6781389dd857a..4e7e9aac740f438dbe4e050ce79b2536fb4e3d09 100644 (file)
@@ -110,7 +110,7 @@ sub topicNew {
   $topic{$chan}{'Last'} = $topic;
   $topic{$chan}{'Who'}  = $orig{who}."!".$uh;
   $topic{$chan}{'Time'} = time();
-  rawout("TOPIC $chan :$topic");
+  $conn->topic($chan, $topic);
   &topicAddHistory($chan,$topic);
   return 1;
 }
index 1d8e927c6b6cf86190ecdb5eb778449f09a609d1..8be74bf6a7eaacbd6ad4f34d0c29a729c7fa1c18 100644 (file)
@@ -29,6 +29,8 @@ sub uptimeGetInfo {
   my @results;
   my $file = $file{utm};
 
+  &::DEBUG("uGI: reading $file...");
+
   if (!open(IN, $file)) {
     &status("Writing uptime file for first time usage (nothing special).");
     open(OUT,">$file");
index 6648f2bff51aca56ff8b77bf81395aa65d23be3f..578cbc72a1f0ae94c1f1587f81ec135d0b1047b1 100644 (file)
@@ -429,7 +429,7 @@ sub userDCC {
        }
 
        &status("jumping servers... $server...");
-       &rawout("QUIT :jumping to $server");
+       $conn->quit("jumping to $server");
 
        if (&irc($server,$port) == 0) {
            &ircloop();
index 894ef86049a7486bae6a807bbce0ed02319163c6..cbdb6cabbf4dca06e6087781745b1b1ce490efa4 100644 (file)
@@ -22,6 +22,15 @@ sub process {
 
     &shmFlush();               # hack.
 
+    # hack to support channel +o as "+o" in bot user file.
+    # requires +O in user file.
+    # is $who arg lowercase?
+    if (exists $channels{$chan}{o}{ $orig{who} } && &IsFlag("O") eq "O") {
+       &status("Gave $who/$chan +o (+O)\'ness");
+       $users{$userHandle}{FLAGS} =~ s/o//g;
+       $users{$userHandle}{FLAGS} .= "o";
+    }
+
     # check if we have our head intact.
     if ($lobotomized) {
        if ($addressed and IsFlag("o") eq "o") {
index bd2ed73fd986bfce1205c7d7ec74d22f78a4201f..2e2dc643fa8ffd1229e9a4e0aee1e23e89fdb99b 100644 (file)
@@ -443,7 +443,7 @@ sub countryStats {
        return;
     }
 
-    &rawout("WHO $chan");
+    $conn->who($chan);
     $cache{countryStats}{chan} = $chan;
     $cache{countryStats}{mtype}        = $msgType;
     $cache{countryStats}{who}  = $who;
index 2f7e7f3792912f8ae5a0e603ed1c21c201eb8137..bf03587fb5b1fb9bb2503431509f44b6db1bc515 100644 (file)
@@ -49,7 +49,7 @@ $SIG{'__WARN__'} = 'doWarn';
 $last{buflen}  = 0;
 $last{say}     = "";
 $last{msg}     = "";
-$userHandle    = "default";
+$userHandle    = "_default";
 $wingaterun    = time();
 $firsttime     = 1;
 $utime_userfile        = 0;
@@ -100,14 +100,20 @@ sub doExit {
        &status("--- Start of quit.");
        $ident ||= "blootbot";  # lame hack.
 
-       &closeDCC() if (&whatInterface() =~ /IRC/); 
        &closePID();
        &closeStats();
-       &seenFlush() if (&whatInterface() =~ /IRC/);
-       &quit($param{'quitMsg'}) if (&whatInterface() =~ /IRC/);
+       # shutdown IRC and related components.
+       if (&whatInterface() =~ /IRC/) {
+           &closeDCC();
+           &seenFlush();
+           &quit($param{'quitMsg'});
+       }
        &writeUserFile();
        &writeChanFile();
-       &uptimeWriteFile()      if (&ChanConfList("uptime"));
+       if (&IsChanConf("uptime")) {
+           &DEBUG("going to write uptime file info.");
+       }
+       &uptimeWriteFile()      if (&IsChanConf("uptime"));
        &News::writeNews()      if (&ChanConfList("news"));
        &closeDB();
        &closeSHM($shm);
@@ -278,7 +284,7 @@ sub getChanConf {
     my($param,$c)      = @_;
 
     if (!defined $param) {
-       &WARN("param == NULL.");
+       &WARN("gCC: param == NULL.");
        return 0;
     }
 
@@ -436,7 +442,7 @@ sub setupConfig {
     $param{'VERBOSITY'} = 1;
     &loadConfig($bot_config_dir."/blootbot.config");
 
-    foreach ("ircNick", "ircUser", "ircName", "DBType", "tempDir") {
+    foreach ( qw(ircNick ircUser ircName DBType tempDir) ) {
        next if &IsParam($_);
        &ERROR("Parameter $_ has not been defined.");
        exit 1;
index 9d54aa1204f1dfbcc171a50177b4ac10ea08a8f7..0861982c778e89fe1a43388ea6d27d340947df56 100644 (file)
@@ -160,7 +160,9 @@ sub loadIRCModules {
     foreach ( &getPerlFiles("$bot_src_dir/$interface") ) {
        my $mod = "$bot_src_dir/$interface/$_";
 
-       &status("Loading Modules \"$mod\"");
+       # hrm... use another config option besides DEBUG to display
+       # change in memory usage.
+       &status("Loading Modules \"$mod\"") if (!&IsParam("DEBUG"));
        eval "require \"$mod\"";
        if ($@) {
            &ERROR("require \"$mod\" => $@");