From 8653377807cbd80bd24c5cc7741d0e42b82a526c Mon Sep 17 00:00:00 2001 From: dms Date: Sat, 2 Nov 2002 15:41:32 +0000 Subject: [PATCH] - added support/hack for channel +o as "+o" in bot user file. 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 ¬ice() + &msg() functions. git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@593 c11ca15a-4712-0410-83d8-924469b57eb5 --- src/Factoids/Question.pl | 2 +- src/IRC/Irc.pl | 51 ++++++++++++++++++---------------------- src/IRC/IrcHelpers.pl | 4 ++-- src/IRC/IrcHooks.pl | 31 ++++++++++++------------ src/IRC/Schedulers.pl | 10 ++++---- src/Modules/News.pl | 20 ++++++++++------ src/Modules/RootWarn.pl | 2 +- src/Modules/Topic.pl | 2 +- src/Modules/Uptime.pl | 2 ++ src/Modules/UserDCC.pl | 2 +- src/Process.pl | 9 +++++++ src/UserExtra.pl | 2 +- src/core.pl | 20 ++++++++++------ src/modules.pl | 4 +++- 14 files changed, 91 insertions(+), 70 deletions(-) diff --git a/src/Factoids/Question.pl b/src/Factoids/Question.pl index e05fe6a..2c1a6e5 100644 --- a/src/Factoids/Question.pl +++ b/src/Factoids/Question.pl @@ -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) ); diff --git a/src/IRC/Irc.pl b/src/IRC/Irc.pl index cdc98fa..d7adf87 100644 --- a/src/IRC/Irc.pl +++ b/src/IRC/Irc.pl @@ -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: ¬ice(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); } } diff --git a/src/IRC/IrcHelpers.pl b/src/IRC/IrcHelpers.pl index 53d3db7..68ea164 100644 --- a/src/IRC/IrcHelpers.pl +++ b/src/IRC/IrcHelpers.pl @@ -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. diff --git a/src/IRC/IrcHooks.pl b/src/IRC/IrcHooks.pl index 8370a21..117daa2 100644 --- a/src/IRC/IrcHooks.pl +++ b/src/IRC/IrcHooks.pl @@ -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(); diff --git a/src/IRC/Schedulers.pl b/src/IRC/Schedulers.pl index be80991..9c5bbed 100644 --- a/src/IRC/Schedulers.pl +++ b/src/IRC/Schedulers.pl @@ -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(); } } diff --git a/src/Modules/News.pl b/src/Modules/News.pl index 478c861..54e5591 100644 --- a/src/Modules/News.pl +++ b/src/Modules/News.pl @@ -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 \002"); + # todo: implement throttling via schedule into ¬ice() / &msg(). + $::conn->schedule(int((2+$i)/2), sub { + &::notice($who, "|= to read, do \002news $chan read <#>\002 or \002news $chan read \002"); + } ); # lame hack to prevent dupes if we just ignore it. my $x = $::newsuser{$chan}{$who}; diff --git a/src/Modules/RootWarn.pl b/src/Modules/RootWarn.pl index 5c2cf62..086cac5 100644 --- a/src/Modules/RootWarn.pl +++ b/src/Modules/RootWarn.pl @@ -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")) { diff --git a/src/Modules/Topic.pl b/src/Modules/Topic.pl index c0d9d95..4e7e9aa 100644 --- a/src/Modules/Topic.pl +++ b/src/Modules/Topic.pl @@ -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; } diff --git a/src/Modules/Uptime.pl b/src/Modules/Uptime.pl index 1d8e927..8be74bf 100644 --- a/src/Modules/Uptime.pl +++ b/src/Modules/Uptime.pl @@ -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"); diff --git a/src/Modules/UserDCC.pl b/src/Modules/UserDCC.pl index 6648f2b..578cbc7 100644 --- a/src/Modules/UserDCC.pl +++ b/src/Modules/UserDCC.pl @@ -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(); diff --git a/src/Process.pl b/src/Process.pl index 894ef86..cbdb6ca 100644 --- a/src/Process.pl +++ b/src/Process.pl @@ -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") { diff --git a/src/UserExtra.pl b/src/UserExtra.pl index bd2ed73..2e2dc64 100644 --- a/src/UserExtra.pl +++ b/src/UserExtra.pl @@ -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; diff --git a/src/core.pl b/src/core.pl index 2f7e7f3..bf03587 100644 --- a/src/core.pl +++ b/src/core.pl @@ -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; diff --git a/src/modules.pl b/src/modules.pl index 9d54aa1..0861982 100644 --- a/src/modules.pl +++ b/src/modules.pl @@ -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\" => $@"); -- 2.39.2