return;
}
- # text counters.
- # warn: lets process it anyway.
- if (1 and $_ = &getChanConf("ircTextCounters")) {
- s/([^\w\s])/\\$1/g;
- my $z = join '|', split ' ';
+ # text counters. (eg: hehstats)
+ my $itc;
+ $itc = &getChanConf("ircTextCounters");
+ $itc = &findChanConf("ircTextCounters") unless ($itc);
+ if ($itc) {
+ $itc =~ s/([^\w\s])/\\$1/g;
+ my $z = join '|', split ' ', $itc;
if ($message =~ /^($z)stats(\s+(\S+))?$/i) {
my $type = $1;
my $arg = $3;
+ # even more uglier with channel/time arguments.
+ my $c = $chan;
+# my $c = $chan || "PRIVATE";
+ my $where = "type=".&dbQuote($type);
+ $where .= " AND channel=".&dbQuote($c) if (defined $c);
+ &DEBUG("not using chan arg") if (!defined $c);
+ my $sum = (&dbRawReturn("SELECT SUM(counter) FROM stats"
+ ." WHERE ".$where ))[0];
+ &DEBUG("type => $type, arg => $arg");
+
if (!defined $arg or $arg =~ /^\s*$/) {
# this is way fucking ugly.
- my $x = (&dbRawReturn("SELECT SUM(counter) FROM stats WHERE type=".&dbQuote($type) ))[0];
- my %hash = &dbGetCol("stats", "nick,counter", "type=".&dbQuote($type).
- " ORDER BY counter DESC LIMIT 3", 1);
+
+ my %hash = &dbGetCol("stats", "nick,counter",
+ $where." ORDER BY counter DESC LIMIT 3", 1);
my $i;
my @top;
my $tp = 0;
foreach $i (sort { $b <=> $a } keys %hash) {
foreach (keys %{ $hash{$i} }) {
- my $p = sprintf("%.01f", 100*$i/$x);
+ my $p = sprintf("%.01f", 100*$i/$sum);
$tp += $p;
push(@top, "\002$_\002 -- $i ($p%)");
}
$topstr = ". Top ".scalar(@top).": ".join(', ', @top);
}
- if (defined $x) {
- &pSReply("total count of '$type': $x$topstr");
+ if (defined $sum) {
+ &pSReply("total count of '$type' on $c: $sum$topstr");
} else {
&pSReply("zero counter for '$type'.");
}
} else {
- my $x = (&dbRawReturn("SELECT SUM(counter) FROM stats WHERE type=".
- &dbQuote($type)." AND nick=".&dbQuote($arg) ))[0];
+ my $x = (&dbRawReturn("SELECT SUM(counter) FROM stats".
+ " WHERE $where AND nick=".&dbQuote($arg) ))[0];
- if (defined $x) { # defined.
- &pSReply("$arg has said $type $x times");
- } else { # !defined.
+ if (!defined $x) { # !defined.
&pSReply("$arg has not said $type yet.");
+ return;
+ }
+
+ # defined.
+ my @array = &dbGet("stats", "nick",
+ $where." ORDER BY counter", 1);
+ my $good = 0;
+ my $i = 0;
+ for($i=0; $i<scalar @array; $i++) {
+ next unless ($array[0] =~ /^\Q$who\E$/);
+ $good++;
+ last;
}
+ $i++;
+
+ my $total = scalar(@array);
+ my $xtra = "";
+ if ($total and $good) {
+ my $pct = sprintf("%.01f", 100*(1+$total-$i)/$total);
+ $xtra = ", ranked $i/$total (percentile: $pct %)";
+ }
+
+ my $pct1 = sprintf("%.01f", 100*$x/$sum);
+ &pSReply("$arg has said $type $x times ($pct1 %)$xtra");
}
return;
if (&IsChanConf("factoidArguments")) {
$result = &factoidArgs($query[0]);
+
return $result if (defined $result);
}
my @vals;
my $arg = $_;
+ # todo: <greycat> ~punish apt for (Eating) (Parentheses)
+ # how the hell do I fix the above?
+
# todo: make eval work with $$i's :(
# fuck this is an ugly hack. it works though.
eval {
&status("Question: factoid Arguments for '$str'");
# todo: use getReply() - need to modify it :(
my $i = 0;
- my $r = &getFactoid("CMD: $_");
+ my $q = "CMD: $_";
+ my $r = &getFactoid($q);
if (!defined $r) {
&DEBUG("question: !result... should this happen?");
return;
}
+ # update stats.
+ my $count = &getFactInfo($q, "requested_count") || 0;
+ $count++;
+ &setFactInfo($q, "requested_by", $nuh);
+ &setFactInfo($q, "requested_time", time());
+ &setFactInfo($q, "requested_count", $count);
+ # end of update stats.
+
$result = $r;
$result =~ s/^\((.*?)\): //;
my $done = 0;
my $old = $result;
while (1) {
-# &DEBUG("Q: result => $result (1)");
+# &DEBUG("Q: result => $result (1before)");
$result = &substVars($result);
-# &DEBUG("Q: result => $result (1)");
+# &DEBUG("Q: result => $result (1after)");
last if ($old eq $result);
$old = $result;
$conn->add_handler('nick', \&on_nick);
$conn->add_handler('quit', \&on_quit);
$conn->add_handler('notice', \&on_notice);
- $conn->add_handler('whoisuser', \&on_whoisuser);
+ $conn->add_handler('whoischannels', \&on_whoischannels);
+ $conn->add_handler('useronchannel', \&on_useronchannel);
+ $conn->add_handler('whois', \&on_whois);
$conn->add_handler('other', \&on_other);
$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(422, \&on_endofwho); # nomotd.
$conn->add_global_handler(324, \&on_modeis);
$conn->add_global_handler(333, \&on_topicinfo);
$conn->add_global_handler(352, \&on_who);
$chan = lc $1;
}
- &status("joining $b_blue$chan$ob");
-
+ # hopefully validChan is right.
if (&validChan($chan)) {
&status("join: already on $chan");
} else {
+ &status("joining $b_blue$chan$ob");
if (!$conn->join($chan)) {
&DEBUG("joinchan: join failed. trying connect!");
$conn->connect();
next if ($chan eq "");
$chan =~ tr/A-Z/a-z/; # lowercase.
+ if ($chan !~ /^$mask{chan}$/) {
+ &WARN("part: chan is invalid ($chan)");
+ next;
+ }
+
&status("parting $chan");
if (!&validChan($chan)) {
&WARN("part: not on $chan; doing anyway");
### Clean it up.
my $delete = 0;
+ my $time = time();
foreach $chan (keys %floodjoin) {
foreach $who (keys %{ $floodjoin{$chan} }) {
- my $time = time() - $floodjoin{$chan}{$who}{Time};
- next unless ($time > 10);
+ my $t = $floodjoin{$chan}{$who}{Time};
+ next unless (defined $t);
+
+ my $delta = $time - $t;
+ next unless ($delta > 10);
+
delete $floodjoin{$chan}{$who};
$delete++;
}
# sync time should be done in on_endofwho like in BitchX
if (exists $cache{jointime}{$chan}) {
my $delta_time = sprintf("%.03f", &timedelta($cache{jointime}{$chan}) );
- $delta_time = 0 if ($delta_time < 0);
+ $delta_time = 0 if ($delta_time <= 0);
if ($delta_time > 100) {
&WARN("endofnames: delta_time > 100 ($delta_time)");
}
&status("$b_blue$chan$ob: sync in ${delta_time}s.");
}
- rawout("MODE $chan");
+ &rawout("MODE $chan");
my $txt;
my @array;
$who = $nick;
$msgType = "public";
+ if (0 and !exists $channels{$chan}) {
+ &DEBUG("on_part: found out we're on $chan!");
+ $channels{$chan} = 1;
+ }
+
if (exists $floodjoin{$chan}{$nick}{Time}) {
delete $floodjoin{$chan}{$nick};
}
# would this slow things down?
if ($_ = &getChanConf("ircTextCounters")) {
+ my $time = time();
+
foreach (split /[\s]+/) {
- next unless ($msg =~ /^\Q$_\E$/i);
- &VERB("textcounters: $_ matched for $who",2);
+ my $x = $_;
+
+ # either full word or ends with a space, etc...
+ next unless ($msg =~ /^\Q$x\E[\$\s!.]/i);
+
+ &VERB("textcounters: $x matched for $who",2);
+ my $c = $chan || "PRIVATE";
- my $v = &dbGet("stats", "counter", "nick=".&dbQuote($who).
- " AND type='$msg'");
+ my ($v,$t) = &dbGet("stats", "counter,time",
+ "nick=". &dbQuote($who)
+ ." AND type=".&dbQuote($x)
+ ." AND channel=".&dbQuote($c)
+ );
$v++;
- &dbReplace("stats", (nick => $who, type => $_, counter => $v) );
+ # don't allow ppl to cheat the stats :-)
+ next unless ($time - $t > 10);
+
+ my %hash = (
+ nick => $who,
+ type => $x,
+ channel => $c,
+
+ time => $time,
+ counter => $v,
+ );
+
+
+ &dbReplace("stats", %hash);
# does not work, atleast with old mysql!!! :(
-# &dbReplace("stats", (nick => $who, type => $_, -counter => "counter+1") );
+# &dbReplace("stats", (nick => $who, type => $x, -counter => "counter+1") );
}
}
$nuh{lc $args[5]} = $args[5]."!".$args[2]."\@".$args[3];
}
-sub on_whoisuser {
+sub on_whois {
my ($self, $event) = @_;
my @args = $event->args;
- &DEBUG("on_whoisuser: @args");
-
$nuh{lc $args[1]} = $args[1]."!".$args[2]."\@".$args[3];
}
+sub on_whoischannels {
+ my ($self, $event) = @_;
+ my @args = $event->args;
+
+ &DEBUG("on_whoischannels: @args");
+}
+
+sub on_useronchannel {
+ my ($self, $event) = @_;
+ my @args = $event->args;
+
+ &DEBUG("on_useronchannel: @args");
+ &joinNextChan();
+}
+
###
### since joinnextchan is hooked onto on_endofnames, these are needed.
###
&leakCheck(2); # mandatory
&ignoreCheck(1); # mandatory
&seenFlushOld(2);
- &ircCheck(2); # mandatory
+# &ircCheck(2); # mandatory
+ &ircCheck(1); # mandatory
&miscCheck(1); # mandatory
&miscCheck2(2); # mandatory
&shmFlush(1); # mandatory
my @keys = sort keys %{ $files{$file} };
my $i = scalar(@keys);
+ if (scalar @keys > 3) {
+ pop @keys while (scalar @keys > 3);
+ push(@keys, "...");
+ }
+
if ($i > 1) {
$file .= "\002{\002". join("\002|\002", @keys) ."\002}\002";
} else {
# symbols.
/(\"\*)/ and last;
/, / and last;
- /^\'/ and last;
+ (/^'/ and /'$/) and last;
+ (/^"/ and /"$/) and last;
# delimiters.
/\=\>/ and last; # '=>'.
/ also$/ and last;
/ and$/ and last;
/^because / and last;
+ /^but / and last;
/^gives / and last;
/^h(is|er) / and last;
/^if / and last;
/ is,/ and last;
/ it$/ and last;
+ /^or / and last;
/ says$/ and last;
/^should / and last;
/^so / and last;
foreach (keys %cmdstats) {
my $type = $_;
- my $i = &dbGet("stats", "counter", "nick=".&dbQuote($type).
+ my $i = &dbGet("stats", "counter", "nick=".&dbQuote($type).
" AND type='cmdstats'");
+ my $z = 0;
+ $z++ unless ($i);
+
$i += $cmdstats{$type};
- &dbReplace("stats",
- (nick => $type, type => "cmdstats", counter => $i)
- );
+ my %hash = (
+ nick => $type,
+ type => "cmdstats",
+ counter => $i
+ );
+ $hash{time} = time() if ($z);
+
+ &dbReplace("stats", %hash);
}
}
&::msg($::who, "|= Last updated $timestr ago.");
&::msg($::who, " \037Num\037 \037Item ".(" "x40)." \037");
- &::DEBUG("list: expire = $expire");
+ &DEBUG("list: expire = $expire");
&::DEBUG("list: eno = $eno");
my $i = 1;
$i = $j = 0;
}
+sub AUTOLOAD { &::AUTOLOAD(@_); }
+
1;
&msg($who,"resetting...");
my @done;
foreach ( keys %channels, keys %chanconf ) {
- &DEBUG("reset: c => $c");
- next if (grep /^\Q$_\E$/i, @done);
+ my $c = $_;
+ next if (grep /^\Q$c\E$/i, @done);
- &DEBUG("reset: should part... c => $c");
&part($_);
push(@done, $_);
&joinchan($chankey);
&status("JOIN $chankey <$who>");
&msg($who, "joining $chankey");
+ &joinNextChan(); # hack.
return;
}
return $chanconf{"_default"}{$param};
}
+#####
+# Usage: &findChanConf($param);
+# About: Retrieve value for 'param' value from any chan.
+# Return: scalar for success, undef for failure.
+sub findChanConf {
+ my($param) = @_;
+
+ if (!defined $param) {
+ &WARN("param == NULL.");
+ return 0;
+ }
+
+ my $c;
+ foreach $c (keys %chanconf) {
+ foreach (keys %{ $chanconf{$c} }) {
+ next unless (/^$param$/);
+
+ &DEBUG("chanconf{$c}{$_} ...");
+ return $chanconf{$c}{$_};
+ }
+ }
+
+ return;
+}
+
sub showProc {
my ($prefix) = $_[0] || "";
$query .= " WHERE ".$where if ($where);
my %retval;
- &DEBUG("dbGetCol: query => '$query'.");
-
my $sth = $dbh->prepare($query);
&SQLDebug($query);
if (!$sth->execute) {
&ERROR("GetCol: execute: '$query'");
-# &ERROR("GetCol => $DBI::errstr");
$sth->finish;
return;
}