]> git.donarmstrong.com Git - infobot.git/commitdiff
IRC/IrcHooks.pl
authordms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Sat, 14 Apr 2001 12:17:27 +0000 (12:17 +0000)
committerdms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Sat, 14 Apr 2001 12:17:27 +0000 (12:17 +0000)
- 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

src/IRC/Irc.pl
src/IRC/IrcHooks.pl
src/IRC/Schedulers.pl
src/Modules/News.pl
src/Process.pl
src/core.pl

index 3fab9912474cdc8784810b3bf862b1642a0d758e..a0f48a0967f2cc98b1aac2efabb323d64e7588a5 100644 (file)
@@ -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;
 }
index 2b73053ea96a19038f1a0567f0a243cc8e0edcae..6e451155a6815d85c5a749151fa9f835d2383fe0 100644 (file)
@@ -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) {
index c63ee2693cb25dcd45c87be91a946bce7417c163..e509902361aa965a86e5942e7ce050c4aba180aa 100644 (file)
@@ -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'} );
 }
index fda441d8281108761fa1a8c672a72c1b8cf35e07..0aba4bea386e22bc2de0b31b96d0d95948ac1fc3 100644 (file)
@@ -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} );
index 55da57b038e49fa11aaf82d4a02bdfffb445e835..259fcdb422db7b75d064ab825a3ec5c2ebc89c56 100644 (file)
@@ -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;
index 20be5c22e15c56c57f81af830237c0e4a57f7c37..aec5affb884601762386f3c726e5851d7e5c9a92 100644 (file)
@@ -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;
 }