diff --git a/doc/Factoids.md b/doc/Factoids.md index 47c044cb..03cd0106 100644 --- a/doc/Factoids.md +++ b/doc/Factoids.md @@ -715,9 +715,9 @@ To see a histogram of the top factoid submitters, use the `histogram` command. 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 to a channel. +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. -Usage: `top20 [ or 'recent']` +Usage: `top20 [ or 'added' or 'edited']` !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) @@ -725,6 +725,8 @@ Usage: `top20 [ or 'recent']` !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... - !top20 ##c recent + !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... + !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-] ... diff --git a/lib/PBot/Core/Commands/Factoids.pm b/lib/PBot/Core/Commands/Factoids.pm index 2e1a2064..0fecc74a 100644 --- a/lib/PBot/Core/Commands/Factoids.pm +++ b/lib/PBot/Core/Commands/Factoids.pm @@ -797,11 +797,19 @@ sub cmd_factadd($self, $context) { if ($self->{pbot}->{commands}->exists($keyword)) { return "/say $keyword_text already exists as a built-in command."; } + my $exists = $self->{pbot}->{factoids}->{data}->{storage}->exists($from_chan, $keyword); + $self->{pbot}->{factoids}->{data}->add('text', $from_chan, $context->{hostmask}, $keyword, $text); - $self->{pbot}->{logger}->log("$context->{hostmask} added [$from_chan] $keyword_text => $text\n"); + if ($force && $exists) { + $self->{pbot}->{factoids}->{data}->{storage}->set($from_chan, $keyword, 'edited_by', $context->{hostmask}); + $self->{pbot}->{factoids}->{data}->{storage}->set($from_chan, $keyword, 'edited_on', scalar gettimeofday); + $self->log_factoid($from_chan, $keyword, $context->{hostmask}, "force created: $text"); + } else { + $self->log_factoid($from_chan, $keyword, $context->{hostmask}, "created: $text"); + } - $self->log_factoid($from_chan, $keyword, $context->{hostmask}, "created: $text"); + $self->{pbot}->{logger}->log("$context->{hostmask} added [$from_chan] $keyword_text => $text\n"); return "/say $keyword_text added to " . ($from_chan eq '.*' ? 'global channel' : $from_chan) . "."; } @@ -1385,7 +1393,7 @@ 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 'recent']"; } + if (not defined $channel) { return "Usage: top20 [nick or 'added' or 'edited']"; } if (not defined $args) { my $iter = $factoids->get_each('type = text', "index1 = $channel", 'index2', 'ref_count > 0', '_sort = -ref_count'); @@ -1404,7 +1412,7 @@ sub cmd_top20($self, $context) { } } - if (lc $args eq "recent") { + if (lc $args eq 'recent' || lc $args eq 'added') { my $iter = $factoids->get_each('type = text', "index1 = $channel", 'index2', 'created_on', 'owner', '_sort = -created_on'); while (defined (my $factoid = $factoids->get_next($iter))) { my $ago = concise ago gettimeofday - $factoid->{'created_on'}; @@ -1414,11 +1422,26 @@ sub cmd_top20($self, $context) { last if $i >= 50; } - $channel = "global channel" if $channel eq '.*'; + $channel = 'global channel' if $channel eq '.*'; $text = "$i most recent $channel submissions:\n\n$text" if $i > 0; return $text; } + if (lc $args eq 'edited') { + my $iter = $factoids->get_each('type = text', "index1 = $channel", 'index2', 'edited_on', 'edited_by', '_sort = -edited_on'); + while (defined (my $factoid = $factoids->get_next($iter))) { + my $ago = concise ago gettimeofday - $factoid->{'edited_on'}; + my ($editor) = $factoid->{'edited_by'} =~ /^([^!]+)/; + $text .= ' ' . $factoids->get_data($factoid->{index1}, $factoid->{index2}, '_name') . " [$ago by $editor]\n"; + $i++; + last if $i >= 50; + } + + $channel = 'global channel' if $channel eq '.*'; + $text = "$i most recent $channel edits:\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} =~ /^([^!]+)/; diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index 07a17aa6..6381f5d8 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 => 4809, + BUILD_REVISION => 4810, BUILD_DATE => "2024-10-23", };