From 5b661567bd6bdb15cc1e48e102bda3a26d03bd65 Mon Sep 17 00:00:00 2001 From: dms Date: Thu, 6 Mar 2003 19:21:36 +0000 Subject: [PATCH] - nice patch from Phil Edwards . Thanks! - W3Search regex now doesn't catch "smile for me" for example. - allow +o users to have no restrictions on factoid searching. - updated comments for user flags. - join: check validity of channel name. - karma: update if statement and comment. - core: if channel contains regex, *boom*. fixed. - rename factoids: logic fixed. - irc: prevent perl warnings in flood check code. - norm: cosmetic clean up. - added config check ("logColors") to retain control characters in log files. - forgot to commit a fix for learn == HUNGRY. git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@774 c11ca15a-4712-0410-83d8-924469b57eb5 --- src/CommandStubs.pl | 7 ++++--- src/Factoids/Core.pl | 36 +++++++++++++++++++----------------- src/IRC/Irc.pl | 5 ++++- src/Process.pl | 32 +++++++++++++++++--------------- src/core.pl | 2 +- src/logger.pl | 1 + 6 files changed, 46 insertions(+), 37 deletions(-) diff --git a/src/CommandStubs.pl b/src/CommandStubs.pl index 54035db..cc0a3fb 100644 --- a/src/CommandStubs.pl +++ b/src/CommandStubs.pl @@ -14,6 +14,7 @@ use vars qw(%channels %cache %mask %userstats %myModules %cmdstats use vars qw($total $x $type $i $good); $babel_lang_regex = "fr|sp|es|po|pt|it|ge|de|gr|en|zh|ja|jp|ko|kr|ru"; +$w3search_regex = "google"; ### COMMAND HOOK IMPLEMENTATION. # addCmdHook("SECTION", 'TEXT_HOOK', @@ -294,7 +295,7 @@ sub Modules { } # google searching. Simon++ - if ($message =~ /^(?:search\s+)?(\S+)\s+for\s+['"]?(.*?)["']?\s*\?*$/i) { + if ($message =~ /^(?:search\s+)?($w3search_regex)\s+for\s+['"]?(.*?)["']?\s*\?*$/i) { return unless (&hasParam("wwwsearch")); &Forker("wwwsearch", sub { &W3Search::W3Search($1,$2); } ); @@ -431,8 +432,8 @@ sub Modules { $args =~ s/^["']|["']$//g; } - if (length $args == 1) { - &msg($who,"search string is too short."); + if (length $args < 2 && &IsFlag("o") ne "o") { + &msg($who, "search string is too short."); return; } diff --git a/src/Factoids/Core.pl b/src/Factoids/Core.pl index 59932d0..fde06aa 100644 --- a/src/Factoids/Core.pl +++ b/src/Factoids/Core.pl @@ -300,7 +300,7 @@ sub FactoidStuff { my $faqtoid = $message; if ($faqtoid eq "") { - &help("undelete"); + &help("unforget"); return; } @@ -377,29 +377,31 @@ sub FactoidStuff { } if ($message =~ /^'(.*)'\s+'(.*)'$/) { - my($from,$to) = (lc $1, lc $2); + my ($from,$to) = (lc $1, lc $2); my $result = &getFactoid($from); if (defined $result) { - my $author = &getFactInfo($from, "created_by"); - - if (0 and !&IsFlag("m") or $author !~ /^\Q$who\E\!/i) { - &msg($who, "It's not yours to modify."); - return; - } + &performReply("i didn't have anything called '$from'"); + return; + } - if ($_ = &getFactoid($to)) { - &performReply("destination factoid already exists."); - return; - } + my $author = &getFactInfo($from, "created_by"); - &setFactInfo($from,"factoid_key",$to); + # who == nick!user@host. + if (&IsFlag("m") ne "m" and $author !~ /^\Q$who\E\!/i) { + &msg($who, "factoid '$form' is not yours to modify."); + return; + } - &status("rename: <$who> '$from' is now '$to'"); - &performReply("i renamed '$from' to '$to'"); - } else { - &performReply("i didn't have anything called '$from'"); + if ($_ = &getFactoid($to)) { + &performReply("destination factoid already exists."); + return; } + + &setFactInfo($from,"factoid_key",$to); + + &status("rename: <$who> '$from' is now '$to'"); + &performReply("i renamed '$from' to '$to'"); } else { &msg($who,"error: wrong format. ask me about 'help rename'."); } diff --git a/src/IRC/Irc.pl b/src/IRC/Irc.pl index 8350e4d..a73a51a 100644 --- a/src/IRC/Irc.pl +++ b/src/IRC/Irc.pl @@ -868,7 +868,10 @@ sub joinfloodCheck { my $time; foreach (keys %{ $floodjoin{$c} }) { - $time += $floodjoin{$c}{$_}{Time}; + my $t = $floodjoin{$c}{$_}{Time}; + next unless (defined $t); + + $time += $t; } &DEBUG("joinflood: time => $time"); $time /= $count; diff --git a/src/Process.pl b/src/Process.pl index 0418982..40f4e70 100644 --- a/src/Process.pl +++ b/src/Process.pl @@ -24,7 +24,12 @@ sub process { return 'addressedother set' if ($addressedother); $talkok = ($param{'addressing'} =~ /^OPTIONAL$/i or $addressed); - $learnok = ($param{'learn'} =~ /^HUNGRY$/i or $addressed); + $learnok = 1 if ($addressed); + if ($param{'learn'} =~ /^HUNGRY$/i) { + $learnok = 1; + $addressed = 1; + $talkok = 1; + } &shmFlush(); # hack. @@ -70,6 +75,11 @@ sub process { return; } + if ($thischan !~ /^$mask{chan}$/) { + &msg($who, "$thischan is not a valid channel name."); + return; + } + if (&IsFlag("o") ne "o") { if (!exists $chanconf{$thischan}) { &msg($who, "I am not allowed to join $thischan."); @@ -77,8 +87,7 @@ sub process { } if (&validChan($thischan)) { - &msg($who,"warn: I'm already on $thischan, joining anyway..."); -# return; + &msg($who,"warn: I'm already on $thischan, joining anyway..."); } } $cache{join}{$thischan} = $who; # used for on_join self. @@ -290,18 +299,11 @@ sub process { ### # karma. set... - if ($message =~ /^(\S+)(--|\+\+)\s*$/ and $addressed) { - return '' unless (&hasParam("karma")); - # well... since it is policy to do bot functions before factoids - # karma gets hit if, for example, "g++" is issued. - # only way to request it is to put a question mark at the end. - - my($term,$inc) = (lc $1,$2); - - if ($msgType !~ /public/i) { - &msg($who, "karma must be done in public!"); - return; - } + if ($message =~ /^(\S+)(--|\+\+)\s*$/ && $addressed && + &hasParam("karma") && $msgType =~ /public/i + ) { + # to request factoids such as "g++" or "libstdc++", append "?" to the query. + my ($term,$inc) = (lc $1,$2); if (lc $term eq lc $who) { &msg($who, "please don't karma yourself"); diff --git a/src/core.pl b/src/core.pl index c82c47e..9bcaccd 100644 --- a/src/core.pl +++ b/src/core.pl @@ -301,7 +301,7 @@ sub getChanConf { $c ||= $chan; $c ||= "_default"; $c = "_default" if ($c eq "*"); # fix! - my @c = grep /^$c$/i, keys %chanconf; + my @c = grep /^\Q$c\E$/i, keys %chanconf; if (@c) { if (0 and $c[0] ne $c) { diff --git a/src/logger.pl b/src/logger.pl index bcf7673..c7593a7 100644 --- a/src/logger.pl +++ b/src/logger.pl @@ -347,6 +347,7 @@ sub status { # remove control characters from logging to LOGFILE. for ($input) { + last if (&IsParam("logColors")); s/\e\[[0-9;]+m//g; # escape codes. s/[\cA-\c_]//g; # control chars. } -- 2.39.2