diff --git a/doc/Commands.md b/doc/Commands.md index 3a61aba7..388c1f2b 100644 --- a/doc/Commands.md +++ b/doc/Commands.md @@ -126,7 +126,7 @@ * [factlog](Factoids.md#factlog) * [count](Factoids.md#count) * [histogram](Factoids.md#histogram) - * [top20](Factoids.md#top20) + * [top50](Factoids.md#top50) ## Command interpreter @@ -656,4 +656,4 @@ to have the command remember your location. ##### [factlog](Factoids.md#factlog) ##### [count](Factoids.md#count) ##### [histogram](Factoids.md#histogram) -##### [top20](Factoids.md#top20) +##### [top50](Factoids.md#top50) diff --git a/doc/Factoids.md b/doc/Factoids.md index 7bce4c96..b8786be6 100644 --- a/doc/Factoids.md +++ b/doc/Factoids.md @@ -56,7 +56,7 @@ * [factset](#factset-1) * [count](#count) * [histogram](#histogram) - * [top20](#top20) + * [top50](#top50) ## About @@ -739,19 +739,19 @@ To see a histogram of the top factoid submitters, use the `histogram` command. !histogram 268 factoids, top 10 submitters: twkm: 74 (27%) Major-Willard: 64 (23%) pragma-: 40 (14%) prec: 39 (14%) defrost: 14 (5%) PoppaVic: 10 (3%) infobahn: 7 (2%) orbitz: 3 (1%) mauke: 3 (1%) Tom^: 2 (1%) -### top20 -To see the top 20 most popular factoids, use the `top20` command. It can also show you the 50 most recent factoids that were added or edited in a channel. +### top50 +To see the top 50 most popular factoids, use the `top50` command. It can also show you the 50 most recent factoids that were added or edited in a channel. -Usage: `top20 [ or 'added' or 'edited']` +Usage: `top50 [ | 'added' | 'edited' | 'referenced']` - !top20 ##c - Top 20 referenced factoids for ##c: explain (3459) c11 (2148) book (1070) books (1049) K&R (1000) dontcastmalloc (991) notC (696) standard (655) c99 (506) scanf (501) declare (453) std (434) cstd (344) tias (305) parens (291) int (287) c1x (272) UB (263) H&S (257) binky (236) + !top50 #c + Top 50 referenced factoids for ##c: explain (3459) c11 (2148) book (1070) books (1049) K&R (1000) dontcastmalloc (991) notC (696) standard (655) c99 (506) scanf (501) declare (453) std (434) cstd (344) tias (305) parens (291) int (287) c1x (272) UB (263) H&S (257) binky (236) - !top20 ##c pragma- - 20 factoids last referenced by pragma- (pragma-!~chaos@unaffiliated/pragmatic-chaos): to [1d20h ago] realloc [3d15h ago] deport [4d16h ago] long [4d16h ago] decay [6d17h ago] x [6d16h ago] sizeof [13d18h ago] ENOQUESTION [13d19h ago] main [13d10h ago] cfaq [14d22h ago] heap [14d23h ago] malloc [15d15h ago] _ [16d20h ago] declareuse [17d15h ago] rot13 [17... + !top50 #c pragma- + 50 factoids last referenced by pragma- (pragma-!~chaos@unaffiliated/pragmatic-chaos): to [1d20h ago] realloc [3d15h ago] deport [4d16h ago] long [4d16h ago] decay [6d17h ago] x [6d16h ago] sizeof [13d18h ago] ENOQUESTION [13d19h ago] main [13d10h ago] cfaq [14d22h ago] heap [14d23h ago] malloc [15d15h ago] _ [16d20h ago] declareuse [17d15h ago] rot13 [17... - !top20 ##c added - 50 most recent ##c submissions: barometer [9h ago by kurahaupo] glib-pcre [21h ago by aozt] unspecified [1d13h ago by pragma-] rules [1d17h ago by oldlaptop] pjp [2d3h ago by d3738] gnu-errno-name-num [2d21h ago by aozt] cbreak [5d8h ago by jp] test case [5d9h ago by pragma-] googlearn [6d2h ago by glacial] threads [8d10h ago by glacial] cjeopard... + !top50 #c added + 50 most recent #c submissions: barometer [9h ago by kurahaupo] glib-pcre [21h ago by aozt] unspecified [1d13h ago by pragma-] rules [1d17h ago by oldlaptop] pjp [2d3h ago by d3738] gnu-errno-name-num [2d21h ago by aozt] cbreak [5d8h ago by jp] test case [5d9h ago by pragma-] googlearn [6d2h ago by glacial] threads [8d10h ago by glacial] cjeopard... - !top20 ##c edited - 50 most recent ##c edits: sanitizers [14h ago by nitrix] testing [1d6h ago by pragma-] typedef [1d8h ago by pragma-] license [2d4h ago by nitrix] diagnostics [2d19h ago by nitrix] tias [3d5h ago by pragma-] kr_lovecraft [4d1h ago by pragma-] cjeopardy [5d3h ago by pragma-] ... + !top50 #c edited + 50 most recent #c edits: sanitizers [14h ago by nitrix] testing [1d6h ago by pragma-] typedef [1d8h ago by pragma-] license [2d4h ago by nitrix] diagnostics [2d19h ago by nitrix] tias [3d5h ago by pragma-] kr_lovecraft [4d1h ago by pragma-] cjeopardy [5d3h ago by pragma-] ... diff --git a/doc/README.md b/doc/README.md index f30937f5..682a322f 100644 --- a/doc/README.md +++ b/doc/README.md @@ -228,7 +228,7 @@ * [factset](Factoids.md#factset-1) * [count](Factoids.md#count) * [histogram](Factoids.md#histogram) - * [top20](Factoids.md#top20) + * [top50](Factoids.md#top50) * [Registry](Registry.md#registry) diff --git a/lib/PBot/Core/Commands/Factoids.pm b/lib/PBot/Core/Commands/Factoids.pm index a414bd96..96751a29 100644 --- a/lib/PBot/Core/Commands/Factoids.pm +++ b/lib/PBot/Core/Commands/Factoids.pm @@ -62,7 +62,7 @@ sub initialize($self, %conf) { $self->{pbot}->{commands}->register(sub { $self->cmd_call_factoid(@_) }, "fact", 0); $self->{pbot}->{commands}->register(sub { $self->cmd_as_factoid(@_) }, "factoid", 0); $self->{pbot}->{commands}->register(sub { $self->cmd_factfind(@_) }, "factfind", 0); - $self->{pbot}->{commands}->register(sub { $self->cmd_top20(@_) }, "top20", 0); + $self->{pbot}->{commands}->register(sub { $self->cmd_top50(@_) }, "top50", 0); $self->{pbot}->{commands}->register(sub { $self->cmd_histogram(@_) }, "histogram", 0); $self->{pbot}->{commands}->register(sub { $self->cmd_count(@_) }, "count", 0); $self->{pbot}->{commands}->register(sub { $self->cmd_add_regex(@_) }, "regex", 1); @@ -1456,7 +1456,7 @@ sub cmd_factchange($self, $context) { return "Changed: $trigger_name is $action"; } -sub cmd_top20($self, $context) { +sub cmd_top50($self, $context) { my $factoids = $self->{pbot}->{factoids}->{data}->{storage}; my %hash = (); my $text = ""; @@ -1464,14 +1464,16 @@ sub cmd_top20($self, $context) { my ($channel, $args) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2); - if (not defined $channel) { return "Usage: top20 [nick or 'added' or 'edited']"; } + if (!defined $channel || $channel ne '.*' && $channel !~ m/^#/) { + return "Usage: top50 [ | 'added' | 'edited' | 'referenced']"; + } if (not defined $args) { my $iter = $factoids->get_each('type = text', "index1 = $channel", 'index2', 'ref_count > 0', '_sort = -ref_count'); while (defined (my $factoid = $factoids->get_next($iter))) { $text .= $factoids->get_data($factoid->{index1}, $factoid->{index2}, '_name') . " ($factoid->{ref_count}) "; $i++; - last if $i >= 20; + last if $i >= 50; } $channel = "the global channel" if $channel eq '.*'; @@ -1514,6 +1516,22 @@ sub cmd_top20($self, $context) { return $text; } + if (lc $args eq 'referenced') { + my $iter = $factoids->get_each('type = text', "index1 = $channel", 'index2', 'last_referenced_on', 'ref_user', '_sort = -last_referenced_on'); + while (defined (my $factoid = $factoids->get_next($iter))) { + last if not defined $factoid->{'last_referenced_on'}; + my $ago = concise ago gettimeofday - $factoid->{'last_referenced_on'}; + my ($ref_by) = $factoid->{'ref_user'} =~ /^([^!]+)/; + $text .= ' ' . $factoids->get_data($factoid->{index1}, $factoid->{index2}, '_name') . " [$ago by $ref_by]\n"; + $i++; + last if $i >= 50; + } + + $channel = 'the global channel' if $channel eq '.*'; + $text = "$i most recent references for $channel:\n\n$text" if $i > 0; + return $text; + } + my $iter = $factoids->get_each('type = text', "index1 = $channel", 'index2', 'ref_user', 'last_referenced_on', '_sort = -last_referenced_on'); while (defined (my $factoid = $factoids->get_next($iter))) { my ($ref_user) = $factoid->{ref_user} =~ /^([^!]+)/; @@ -1521,13 +1539,15 @@ sub cmd_top20($self, $context) { my $ago = $factoid->{'last_referenced_on'} ? concise ago(gettimeofday - $factoid->{'last_referenced_on'}) : "unknown"; $text .= ' ' . $factoids->get_data($factoid->{index1}, $factoid->{index2}, '_name') . " [$ago]\n"; $i++; - last if $i >= 20; + last if $i >= 50; } } if ($i > 0) { + $channel = 'global channel' if $channel eq '.*'; return "$i $channel factoids last referenced by $args:\n\n$text"; } else { + $channel = 'the global channel' if $channel eq '.*'; return "No factoids last referenced by $args in $channel."; } } diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index 3435969c..513000a5 100644 --- a/lib/PBot/VERSION.pm +++ b/lib/PBot/VERSION.pm @@ -25,7 +25,7 @@ use PBot::Imports; # These are set by the /misc/update_version script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 4864, + BUILD_REVISION => 4865, BUILD_DATE => "2024-11-30", };