From: dms Date: Sat, 14 Apr 2001 12:17:27 +0000 (+0000) Subject: IRC/IrcHooks.pl X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=b701505fbda7d956b757182c4916dc1cd9345853;p=infobot.git IRC/IrcHooks.pl - forgot to reset msgType/who/chan after hookMsg in on_msg and on_public. - on_join: if bot joins, don't do wingate/bans and other useless stuff - on_join: set msgType for ICC. - on_part: set msgType/chan/who - on_quit: set msgType/chan/who - on_public: make chan global for ICC => should fix all bugs. => I have no idea how this worked so brokenly. News.pl - more more changes git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@440 c11ca15a-4712-0410-83d8-924469b57eb5 --- diff --git a/src/IRC/Irc.pl b/src/IRC/Irc.pl index 3fab991..a0f48a0 100644 --- a/src/IRC/Irc.pl +++ b/src/IRC/Irc.pl @@ -484,9 +484,11 @@ sub nick { my ($nick) = @_; if ($nick =~ /^$mask{nick}$/) { + &DEBUG("Changing nick to $nick (from $ident)"); rawout("NICK ".$nick); return 1; } + &DEBUG("nick failed... why oh why (nick => $nick)"); return 0; } diff --git a/src/IRC/IrcHooks.pl b/src/IRC/IrcHooks.pl index 2b73053..6e45115 100644 --- a/src/IRC/IrcHooks.pl +++ b/src/IRC/IrcHooks.pl @@ -404,12 +404,11 @@ sub on_invite { } sub on_join { - my ($self, $event) = @_; - my ($user,$host) = split(/\@/, $event->userhost); - $chan = lc( ($event->to)[0] ); # CASING!!!! - $who = $event->nick(); -# doesn't work properly, for news :( -# $msgType = "private"; # for &IsChanConf(). + my ($self, $event) = @_; + my ($user,$host) = split(/\@/, $event->userhost); + $chan = lc( ($event->to)[0] ); # CASING!!!! + $who = $event->nick(); + $msgType = "public"; $chanstats{$chan}{'Join'}++; $userstats{lc $who}{'Join'} = time() if (&IsChanConf("seenStats")); @@ -478,6 +477,19 @@ sub on_join { # no need to go further. return if ($netsplit); + # who == bot. + if ($who eq $ident or $who =~ /^$ident$/i) { + if (defined( my $whojoin = $cache{join}{$chan} )) { + &msg($chan, "Okay, I'm here. (courtesy of $whojoin)"); + delete $cache{join}{$chan}; + } + + ### TODO: move this to &joinchan()? + $cache{jointime}{$chan} = &gettimeofday(); + rawout("WHO $chan"); + + return; + } ### ROOTWARN: &rootWarn($who,$user,$host,$chan) @@ -486,8 +498,6 @@ sub on_join { $channels{$chan}{'o'}{$ident}); ### NEWS: - # why isn't this "enabled" just as someone joins? - if (&IsChanConf("news") && &IsChanConf("newsKeepRead")) { if (!&loadMyModule("news")) { # just in case. &DEBUG("could not load news."); @@ -499,21 +509,8 @@ sub on_join { ### chanlimit check. &chanLimitVerify($chan); - # used to determine sync time. - if ($who =~ /^$ident$/i) { - if (defined( my $whojoin = $cache{join}{$chan} )) { - &msg($chan, "Okay, I'm here. (courtesy of $whojoin)"); - delete $cache{join}{$chan}; - } - - ### TODO: move this to &joinchan()? - $cache{jointime}{$chan} = &gettimeofday(); - rawout("WHO $chan"); - } else { - ### TODO: this may go wild on a netjoin :) - ### WINGATE: - &wingateCheck(); - } + ### wingate: + &wingateCheck(); } sub on_kick { @@ -582,6 +579,9 @@ sub on_msg { } &hookMsg('private', undef, $nick, $msg); + $who = ""; + $chan = ""; + $msgType = ""; } sub on_names { @@ -614,11 +614,20 @@ sub on_nick { $channels{$chan}{$mode}{$newnick} = $channels{$chan}{$mode}{$nick}; } } + # todo: do %flood* aswell. + &DeleteUserInfo($nick,keys %channels); $nuh{lc $newnick} = $nuh{lc $nick}; delete $nuh{lc $nick}; # successful self-nick change. + if ($ident eq "$nick-" or "$ident-" eq $nick) { + &DEBUG("on_nick: well... we need this bug fixed."); + &DEBUG("ident => $ident"); + &DEBUG("nick => $nick"); + $ident = $newnick; + } + if ($nick eq $ident) { &status(">>> I materialized into $b_green$newnick$ob from $nick"); $ident = $newnick; @@ -632,7 +641,7 @@ sub on_nick_taken { my $nick = $self->nick; my $newnick = substr($nick,0,7)."-"; - &status("nick taken; changing to temporary nick."); + &status("nick taken; changing to temporary nick ($nick -> $newnick)."); &nick($newnick); &getNickInUse(1); } @@ -688,9 +697,11 @@ sub on_other { sub on_part { my ($self, $event) = @_; - my $chan = lc( ($event->to)[0] ); # CASING!!! - my $nick = $event->nick; + $chan = lc( ($event->to)[0] ); # CASING!!! + my $nick = $event->nick; my $userhost = $event->userhost; + $who = $nick; + $msgType = "public"; if (exists $floodjoin{$chan}{$nick}{Time}) { delete $floodjoin{$chan}{$nick}; @@ -724,11 +735,14 @@ sub on_ping_reply { sub on_public { my ($self, $event) = @_; - my $msg = ($event->args)[0]; - my $chan = lc( ($event->to)[0] ); # CASING. - my $nick = $event->nick; - $uh = $event->userhost(); - $nuh = $nick."!".$uh; + 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"; + # todo: move this out of hookMsg to here? ($user,$host) = split(/\@/, $uh); if ($bot_pid != $$) { @@ -763,12 +777,19 @@ sub on_public { &hookMsg('public', $chan, $nick, $msg); $chanstats{$chan}{'PublicMsg'}++; + $who = ""; + $chan = ""; + $msgType = ""; } sub on_quit { my ($self, $event) = @_; my $nick = $event->nick(); my $reason = ($event->args)[0]; + # hack for ICC. + $msgType = "public"; + $who = $nick; + $chan = $reason; # not in split! my $count = 0; foreach (keys %channels) { diff --git a/src/IRC/Schedulers.pl b/src/IRC/Schedulers.pl index c63ee26..e509902 100644 --- a/src/IRC/Schedulers.pl +++ b/src/IRC/Schedulers.pl @@ -669,6 +669,7 @@ sub ircCheck { } if ($ident !~ /^\Q$param{ircNick}\E$/) { + # this does not work unfortunately. &WARN("ircCheck: ident($ident) != param{ircNick}($param{IrcNick})."); if (! &IsNickInAnyChan( $param{ircNick} ) ) { &DEBUG("$param{ircNick} not in use... changing!"); @@ -747,9 +748,9 @@ sub miscCheck { } # make backup of important files. - &mkBackup( $bot_misc_dir."/blootbot.chan", 60*60*24*1); - &mkBackup( $bot_misc_dir."/blootbot.users", 60*60*24*1); - &mkBackup( $bot_base_dir."/blootbot-news.txt", 60*60*24*1); + &mkBackup( $bot_misc_dir."/blootbot.chan", 60*60*24*7); + &mkBackup( $bot_misc_dir."/blootbot.users", 60*60*24*7); + &mkBackup( $bot_base_dir."/blootbot-news.txt", 60*60*24*7); # flush cache{lobotomy} foreach (keys %{ $cache{lobotomy} }) { @@ -846,6 +847,11 @@ sub shmFlush { ### this is semi-scheduled sub getNickInUse { + if ($ident eq $param{'ircNick'}) { + &status("okay, got my nick back."); + return; + } + if (@_) { &ScheduleThis(30, "getNickInUse"); return if ($_[0] eq "2"); # defer. @@ -853,11 +859,6 @@ sub getNickInUse { delete $sched{"getNickInUse"}{RUNNING}; } - if ($ident eq $param{'ircNick'}) { - &status("okay, got my nick back."); - return; - } - &status("Trying to get my nick back."); &nick( $param{'ircNick'} ); } diff --git a/src/Modules/News.pl b/src/Modules/News.pl index fda441d..0aba4be 100644 --- a/src/Modules/News.pl +++ b/src/Modules/News.pl @@ -99,6 +99,8 @@ sub Parse { } elsif ($what =~ /^(un)?notify$/i) { my $state = ($1) ? 0 : 1; + &::DEBUG("chan => $chan"); + &::DEBUG("::chan => $::chan"); # todo: don't notify even if "news" is called. if (!&::IsChanConf("newsNotifyAll")) { @@ -354,7 +356,8 @@ sub list { } } - &::msg($::who, "|==== News for \002$chan\002:"); + my $count = scalar keys %{ $::news{$chan} }; + &::msg($::who, "|==== News for \002$chan\002: ($count items)"); my $newest = 0; foreach (keys %{ $::news{$chan} }) { my $t = $::news{$chan}{$_}{Time}; @@ -656,12 +659,17 @@ sub latest { my $t = $::newsuser{$chan}{$::who}; if (defined $t and ($t == 0 or $t == -1)) { - &::DEBUG("not displaying any new news for $::who"); + if ($flag) { + &::msg($::who, "if you want to read news, try /msg $::ident news or /msg $::ident news notify"); + } else { + &::DEBUG("not displaying any new news for $::who"); + } + return; } + my $x = &::IsChanConf("newsNotifyAll"); if (&::IsChanConf("newsNotifyAll") and !defined $t) { -# $::newsuser{$chan}{$::who} = 1; $t = 1; } @@ -679,24 +687,28 @@ sub latest { push(@new, $_); } + # !scalar @new, $flag if (!scalar @new and $flag) { &::msg($::who, "no new news for $chan."); return; } + # scalar @new, !$flag + my $unread = scalar @new; + my $total = scalar keys %{ $::news{$chan} }; if (!$flag) { - my $unread = scalar @new; - my $total = scalar keys %{ $::news{$chan} }; return unless ($unread); - &::msg($::who, "There are unread news in $chan ($unread unread, $total total). /msg $::ident news latest. If you don't want further news notification, /msg $::ident news unnotify"); + my $reply = "There are unread news in $chan ($unread unread, $total total). /msg $::ident news latest."; + $reply .= " If you don't want further news notification, /msg $::ident news unnotify" if ($unread == $total); + &::msg($::who, $reply); return; } + # scalar @new, $flag if (scalar @new) { - &::msg($::who, "+==== New news for \002$chan\002 (". - scalar(@new)." new items):"); + &::msg($::who, "+==== New news for \002$chan\002 ($unread new; $total total):"); if ($::newsuser{$chan}{$::who}) { my $timestr = &::Time2String( time() - $::newsuser{$chan}{$::who} ); diff --git a/src/Process.pl b/src/Process.pl index 55da57b..259fcdb 100644 --- a/src/Process.pl +++ b/src/Process.pl @@ -591,6 +591,7 @@ sub FactoidStuff { for ($question) { # fix the string. s/^hey([, ]+)where/where/i; + s/\s+\?$/?/; s/whois/who is/ig; s/where can i find/where is/i; s/how about/where is/i; diff --git a/src/core.pl b/src/core.pl index 20be5c2..aec5aff 100644 --- a/src/core.pl +++ b/src/core.pl @@ -175,41 +175,53 @@ sub getChanConfList { # Return: 1 for enabled, 0 for passive disable, -1 for active disable. sub IsChanConf { my($param) = shift; + my $debug = 0; # knocked tons of bugs with this! :) if (!defined $param) { - &WARN("param == NULL."); + &WARN("IsChanConf: param == NULL."); return 0; } + if ($chan =~ tr/A-Z/a-z/) { + &WARN("IsChanConf: lowercased chan."); + } + ### TODO: VERBOSITY on how chanconf returned 1 or 0 or -1. my %chan = &getChanConfList($param); - if (!defined $msgType) { -# &DEBUG("icc: !def msgType..."); - return $chan{_default} || 0; + if (!defined $msgType or $msgType eq "") { + if ($chan{$chan}) { + &DEBUG("ICC: !msgType: $chan{$chan} (_default/$param)") if ($debug); + } elsif ($chan{_default}) { + &DEBUG("ICC: !msgType: $chan{_default} (_default/$param)") if ($debug); + } else { + &DEBUG("ICC: !msgType: 0 ($param)") if ($debug); + } + + return $chan{$chan} || $chan{_default} || 0; } if ($msgType eq "public") { - if ($chan{lc $chan}) { -# &DEBUG("iCC: public: $chan/$param"); + if ($chan{$chan}) { + &DEBUG("ICC: public: $chan{$chan} ($chan/$param)") if ($debug); } elsif ($chan{_default}) { -# &DEBUG("iCC: public: _default/$param") + &DEBUG("ICC: public: $chan{_default} (_default/$param)") if ($debug); } else { -# &DEBUG("iCC: public: 0/$param"); + &DEBUG("ICC: public: 0 ($param)") if ($debug); } - return $chan{lc $chan} || $chan{_default} || 0; + return $chan{$chan} || $chan{_default} || 0; } if ($msgType eq "private") { if ($chan{_default}) { -# &DEBUG("iCC: private: _default/$param"); - } elsif ($chan{lc $chan}) { -# &DEBUG("iCC: private: $chan/$param"); + &DEBUG("ICC: private: $chan{_default} (_default/$param)") if ($debug); + } elsif ($chan{$chan}) { + &DEBUG("ICC: private: $chan{$chan} ($chan/$param) (hack)") if ($debug); } else { -# &DEBUG("iCC: private: 0/$param"); + &DEBUG("ICC: private: 0 ($param)") if ($debug); } - return $chan{lc $chan} || $chan{_default} || 0; + return $chan{$chan} || $chan{_default} || 0; } ### debug purposes only. @@ -218,7 +230,7 @@ sub IsChanConf { # &DEBUG(" $_ => $chan{$_}"); # } - &DEBUG("icc: returning 0..."); + &DEBUG("ICC: no-match: 0/$param (msgType = $msgType)"); return 0; }