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;
}
}
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"));
# 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)
$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.");
### 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 {
}
&hookMsg('private', undef, $nick, $msg);
+ $who = "";
+ $chan = "";
+ $msgType = "";
}
sub on_names {
$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;
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);
}
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};
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 != $$) {
&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) {
}
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!");
}
# 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} }) {
### 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.
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'} );
}
} 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")) {
}
}
- &::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};
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;
}
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} );
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;
# 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.
# &DEBUG(" $_ => $chan{$_}");
# }
- &DEBUG("icc: returning 0...");
+ &DEBUG("ICC: no-match: 0/$param (msgType = $msgType)");
return 0;
}