From: octo Date: Sun, 10 Apr 2005 17:10:40 +0000 (+0000) Subject: Converted Onis::Plugins::Nicks X-Git-Tag: Release-0.8.0~20^2~29 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=c81dbe55d359c7d0820e0068ea74aa04348c60fa;p=onis.git Converted Onis::Plugins::Nicks Output of Onis::Plugins::Words now uses (user)name rather than nick. --- diff --git a/lib/Onis/Plugins/Nicks.pm b/lib/Onis/Plugins/Nicks.pm new file mode 100644 index 0000000..00d27da --- /dev/null +++ b/lib/Onis/Plugins/Nicks.pm @@ -0,0 +1,116 @@ +package Onis::Plugins::Nicks; + +use strict; +use warnings; + +use Onis::Html (qw(get_filehandle)); +use Onis::Language (qw(translate)); +use Onis::Data::Core (qw(register_plugin)); +use Onis::Data::Persistent (); +use Onis::Users (qw(nick_to_name)); + +register_plugin ('TEXT', \&add); +register_plugin ('ACTION', \&add); +register_plugin ('OUTPUT', \&output); + +our $MentionedNicksCache = Onis::Data::Persistent->new ('MentionedNicksCache', 'nick', qw(counter lastusedtime lastusedby)); +our $MentionedNicksData = []; + +my $VERSION = '$Id: Nicks.pm,v 1.7 2004/10/31 15:01:12 octo Exp $'; +print STDERR $/, __FILE__, ": $VERSION" if ($::DEBUG); + +return (1); + +sub add +{ + my $data = shift; + + my $nick = $data->{'nick'}; + my $text = $data->{'text'}; + my $time = $data->{'epoch'}; + + # All allowed chars according to RFC2812 + my @potential_nicks = split (/[^a-zA-Z0-9\[\]\\`_^{|}]+/, $text); + + for (@potential_nicks) + { + my $pot_nick = $_; + + # Not allowed according to RFC2812 + if ($pot_nick =~ m/^[0-9\-]/) + { + next; + } + + if (nick_to_ident ($pot_nick)) + { + my ($counter) = $MentionedNicksCache->get ($pot_nick); + $counter ||= 0; + $counter++; + $MentionedNicksCache->put ($pot_nick, $counter, $time, $nick); + } + } +} + +sub calculate +{ + my $max = 10; + my @data = (); + if (get_config ('plugin_max')) + { + my $tmp = get_config ('plugin_max'); + $tmp =~ s/\D//g; + + $max = $tmp if ($tmp); + } + + for ($MentionedNicksData->keys ()) + { + my $nick = $_; + my ($counter, $lastusedtime, $lastusedby) = $MentionedNicksData->get ($nick); + die unless (defined ($lastusedby)); + + $lastusedby = get_main_nick ($lastusedby); + push (@data, [$nick, $counter, $lastusedby, $lastusedtime]); + } + + @$MentionedNicksData = sort { $b->[0] <=> $a->[0] } (@data); + splice (@$MentionedNicksData, $max); +} + +sub output +{ + calculate (); + + my $fh = get_filehandle (); + + my $nick = translate ('Nick'); + my $times = translate ('Times used'); + my $last = translate ('Last used by'); + + print $fh < + +   + $nick + $times + $last + +EOF + my $i = 0; + foreach (@$MentionedNicksData) + { + $i++; + my ($nick, $count, $usedby) = @$_; + my $usedby_name = nick_to_name ($usedby) || $usedby; + + print $fh " \n", + qq# $i\n#, + qq# $nick\n#, + qq# $count\n#, + qq# $usedby_name\n#, + qq# \n#; + } + + print $fh "\n\n"; +} diff --git a/lib/Onis/Plugins/Words.pm b/lib/Onis/Plugins/Words.pm index 7707848..7171b75 100644 --- a/lib/Onis/Plugins/Words.pm +++ b/lib/Onis/Plugins/Words.pm @@ -8,6 +8,7 @@ use Onis::Html (qw(get_filehandle)); use Onis::Language (qw(translate)); use Onis::Data::Core (qw(register_plugin)); use Onis::Data::Persistent (); +use Onis::Users (qw(nick_to_name)); register_plugin ('TEXT', \&add); register_plugin ('ACTION', \&add); @@ -114,12 +115,13 @@ EOF $i++; my ($word, $count, $nick) = @$_; + my $name = nick_to_name ($nick) || $nick; print $fh " \n", qq# $i\n#, qq# $word\n#, qq# $count\n#, - qq# $nick\n#, + qq# $name\n#, qq# \n#; } print $fh "\n\n";