From 4529d37efa27f5443d9ee31beb5d1ab50c264876 Mon Sep 17 00:00:00 2001 From: dms Date: Thu, 26 Apr 2001 14:37:28 +0000 Subject: [PATCH] "~forget blah" now works. thanks to ElectricElf documented user flags public/private/notice send limit now configurable. thanks to EE added "countrystats" command. "blootbot: are you fixed now? :)" -- fixed. found by greycat use hasParam instead of IsParam in UserExtra.pl/userCommands() command "ord" handling fixed. git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@465 c11ca15a-4712-0410-83d8-924469b57eb5 --- src/DynaConfig.pl | 9 +++++ src/Factoids/Statement.pl | 2 +- src/IRC/Irc.pl | 27 ++++++++----- src/IRC/IrcHelpers.pl | 2 +- src/IRC/IrcHooks.pl | 19 +++++++++ src/IRC/Schedulers.pl | 2 +- src/Modules/News.pl | 2 +- src/Process.pl | 9 ++--- src/UserExtra.pl | 83 ++++++++++++++++++++++++++++++++++++--- src/core.pl | 6 +++ 10 files changed, 136 insertions(+), 25 deletions(-) diff --git a/src/DynaConfig.pl b/src/DynaConfig.pl index e23edf0..e1acb4d 100644 --- a/src/DynaConfig.pl +++ b/src/DynaConfig.pl @@ -776,3 +776,12 @@ my @regFlagsUser = ( ); # todo... 1; + +##### +# Userflags +# +r - ability to remove factoids +# +t - ability to teach factoids +# +m - ability to modify factoids +# +n - bot owner +# +o - authorised user of bot (like +m on eggdrop) +##### diff --git a/src/Factoids/Statement.pl b/src/Factoids/Statement.pl index ed58a44..ae0ffa4 100644 --- a/src/Factoids/Statement.pl +++ b/src/Factoids/Statement.pl @@ -65,7 +65,7 @@ sub doStatement { # break if either lhs or rhs is NULL. if ($lhs eq "" or $rhs eq "") { - return; + return "NOT-A-STATEMENT"; } # lets check if it failed. diff --git a/src/IRC/Irc.pl b/src/IRC/Irc.pl index 36d57aa..9d23905 100644 --- a/src/IRC/Irc.pl +++ b/src/IRC/Irc.pl @@ -136,6 +136,7 @@ sub irc { $conn->add_global_handler('disconnect', \&on_disconnect); $conn->add_global_handler([251,252,253,254,255], \&on_init); ### $conn->add_global_handler([251,252,253,254,255,302], \&on_init); + $conn->add_global_handler(315, \&on_endofwho); $conn->add_global_handler(324, \&on_modeis); $conn->add_global_handler(333, \&on_topicinfo); $conn->add_global_handler(352, \&on_who); @@ -191,11 +192,14 @@ sub say { $pubcount++; $pubsize += length $msg; - if ( ($pubcount % 4) == 0 and $pubcount) { + my $i = &getChanConfDefault("sendPublicLimitLines", 3); + my $j = &getChanConfDefault("sendPublicLimitBytes", 1000); + + if ( ($pubcount % $i) == 0 and $pubcount) { sleep 1; - } elsif ($pubsize > 1500) { + } elsif ($pubsize > $j) { sleep 1; - $pubsize -= 1500; + $pubsize -= $j; } } else { @@ -230,11 +234,13 @@ sub msg { $msgcount++; $msgsize += length $msg; - if ( ($msgcount % 4) == 0 and $msgcount) { + my $i = &getChanConfDefault("sendPrivateLimitLines", 3); + my $j = &getChanConfDefault("sendPrivateLimitBytes", 1000); + if ( ($msgcount % $i) == 0 and $msgcount) { sleep 1; - } elsif ($msgsize > 1000) { + } elsif ($msgsize > $j) { sleep 1; - $msgsize -= 1000; + $msgsize -= $j; } } else { @@ -283,11 +289,14 @@ sub notice { $notcount++; $notsize += length $txt; - if ( ($notcount % 3) == 0 and $notcount) { + my $i = &getChanConfDefault("sendNoticeLimitLines", 3); + my $j = &getChanConfDefault("sendNoticeLimitBytes", 1000); + + if ( ($notcount % $i) == 0 and $notcount) { sleep 1; - } elsif ($notsize > 1000) { + } elsif ($notsize > $j) { sleep 1; - $notsize -= 1000; + $notsize -= $j; } } else { diff --git a/src/IRC/IrcHelpers.pl b/src/IRC/IrcHelpers.pl index 52948dd..9d654f9 100644 --- a/src/IRC/IrcHelpers.pl +++ b/src/IRC/IrcHelpers.pl @@ -85,7 +85,7 @@ sub hookMsg { # addressing revamped by the xk. ### below needs to be fixed... if (&IsParam("addressCharacter")) { - if ($message =~ s/^$param{'addressCharacter'}//) { + if ($message =~ s/^\Q$param{'addressCharacter'}\E//) { $addrchar = 1; $addressed = 1; } diff --git a/src/IRC/IrcHooks.pl b/src/IRC/IrcHooks.pl index f04e08b..feac0db 100644 --- a/src/IRC/IrcHooks.pl +++ b/src/IRC/IrcHooks.pl @@ -190,6 +190,17 @@ sub on_endofmotd { &joinNextChan(); } +sub on_endofwho { + my ($self, $event) = @_; +# &DEBUG("endofwho: chan => $chan"); + $chan ||= ($event->args)[1]; +# &DEBUG("endofwho: chan => $chan"); + + if (exists $cache{countryStats}) { + &do_countrystats(); + } +} + sub on_dcc { my ($self, $event) = @_; my $type = uc( ($event->args)[1] ); @@ -977,6 +988,14 @@ sub on_version { sub on_who { my ($self, $event) = @_; my @args = $event->args; + my $str = $args[5]."!".$args[2]."\@".$args[3]; + + if ($cache{on_who_Hack}) { + $cache{nuhInfo}{lc $args[5]}{Nick} = $args[5]; + $cache{nuhInfo}{lc $args[5]}{User} = $args[2]; + $cache{nuhInfo}{lc $args[5]}{Host} = $args[3]; + return; + } $nuh{lc $args[5]} = $args[5]."!".$args[2]."\@".$args[3]; } diff --git a/src/IRC/Schedulers.pl b/src/IRC/Schedulers.pl index d14c12c..0412f85 100644 --- a/src/IRC/Schedulers.pl +++ b/src/IRC/Schedulers.pl @@ -365,7 +365,7 @@ sub chanlimitCheck { } next unless (!defined $limit); - if ($limit == $newlimit) { + if (defined $limit and $limit == $newlimit) { $cache{chanlimitChange}{$chan} = time(); next; } diff --git a/src/Modules/News.pl b/src/Modules/News.pl index 265da89..089ab07 100644 --- a/src/Modules/News.pl +++ b/src/Modules/News.pl @@ -58,7 +58,7 @@ sub Parse { } $chan = $chans[0]; - &::DEBUG("Guessed $::who being on chan $chan"); + &::VERB("Guessed $::who being on chan $chan",2); $::chan = $chan; # hack for IsChanConf(). } diff --git a/src/Process.pl b/src/Process.pl index 54ab15b..1862e7a 100644 --- a/src/Process.pl +++ b/src/Process.pl @@ -316,12 +316,9 @@ sub process { return 'SOMETHING 1'; } - ### FIXME: should this only apply to public messages? - if ($addrchar) { - &DEBUG("floodwho => '$floodwho'."); - delete $flood{$floodwho}{$message}; - &status("short return due to unknown command."); - return 'ADDR CHAR'; + if (0 and $addrchar) { + &msg($who, "I don't trust people to use the core commands while addressing me in a short-cut way."); + return; } } diff --git a/src/UserExtra.pl b/src/UserExtra.pl index f405a11..8f6aff3 100644 --- a/src/UserExtra.pl +++ b/src/UserExtra.pl @@ -34,7 +34,9 @@ use vars qw(%channels %chanstats %cmdstats); Cmdstats => 'Tell') ); &addCmdHook("main", 'news', ('CODEREF' => 'News::Parse', Module => 'news', ) ); -# Module => 'news', Identifier => 'news') ); +&addCmdHook("main", 'countrystats', ('CODEREF' => 'countryStats', +# Forker => "NULL", + ) ); &status("CMD: loaded ".scalar(keys %hooks_main)." MAIN command hooks."); @@ -410,6 +412,66 @@ sub DNS { &performReply($result); } +sub countryStats { + if (exists $cache{countryStats}) { + &msg($who,"countrystats is already running!"); + return; + } + + if ($chan eq "") { + $chan = $_[0]; + } + + if ($chan eq "") { + &help("countrystats"); + return; + } + + &rawout("WHO $chan"); + $cache{countryStats}{chan} = $chan; + $cache{countryStats}{mtype} = $msgType; + $cache{countryStats}{who} = $who; + $cache{on_who_Hack} = 1; +} + +sub do_countrystats { + $chan = $cache{countryStats}{chan}; + $msgType = $cache{countryStats}{mtype}; + $who = $cache{countryStats}{who}; + + my $total = 0; + my %cstats; + foreach (keys %{ $cache{nuhInfo} }) { + my $h = $cache{nuhInfo}{$_}{Host}; + + if ($h =~ /^.*\.(\D+)$/) { # host + $cstats{$1}++; + } else { # ip + $cstats{unresolve}++; + } + $total++; + } + my %count; + foreach (keys %cstats) { + $count{ $cstats{$_} }{$_} = 1; + } + + my @list; + foreach (sort {$b <=> $a} keys %count) { + my $str = join(", ", sort keys %{ $count{$_} }); +# push(@list, "$str ($_)"); + my $perc = sprintf("%.01f", 100 * $_ / $total); + $perc =~ s/\.0+$//; + push(@list, "$str ($_, $perc %)"); + } + + # todo: move this into a scheduler like nickometer + $msgType = "private"; + &pSReply( &formListReply(0, "Country Stats ", @list) ); + + delete $cache{countryStats}; + delete $cache{on_who_Hack}; +} ### ### amalgamated commands. @@ -418,7 +480,10 @@ sub DNS { sub userCommands { # conversion: ascii. if ($message =~ /^(asci*|chr) (\d+)$/) { - return unless (&IsParam("allowConv")); + &DEBUG("ascii/chr called ..."); + return unless (&hasParam("allowConv")); + + &DEBUG("ascii/chr called"); $arg = $2; $result = chr($arg); @@ -430,10 +495,16 @@ sub userCommands { } # conversion: ord. - if ($message =~ /^ord (.)$/) { - return unless (&IsParam("allowConv")); + if ($message =~ /^ord(\s+(.*))$/) { + return unless (&hasParam("allowConv")); + + $arg = $2; + + if (!defined $arg or length $arg != 1) { + &help("ord"); + return; + } - $arg = $1; if (ord($arg) < 32) { $arg = chr(ord($arg) + 64); if ($arg eq chr(64)) { @@ -449,7 +520,7 @@ sub userCommands { # hex. if ($message =~ /^hex(\s+(.*))?$/i) { - return unless (&IsParam("allowConv")); + return unless (&hasParam("allowConv")); my $arg = $2; if (!defined $arg) { diff --git a/src/core.pl b/src/core.pl index 4caf493..5d3a2b2 100644 --- a/src/core.pl +++ b/src/core.pl @@ -354,6 +354,12 @@ sub setup { &status("Setup: ". &countKeys("factoids") ." factoids."); &News::readNews() if (&ChanConfList("news")); + &getChanConfDefault("sendPrivateLimitLines", 3); + &getChanConfDefault("sendPrivateLimitBytes", 1000); + &getChanConfDefault("sendPublicLimitLines", 3); + &getChanConfDefault("sendPublicLimitBytes", 1000); + &getChanConfDefault("sendNoticeLimitLines", 3); + &getChanConfDefault("sendNoticeLimitBytes", 1000); $param{tempDir} =~ s#\~/#$ENV{HOME}/#; -- 2.39.2