1 package Onis::Plugins::Words;
6 use Onis::Config (qw(get_config));
7 use Onis::Html (qw(get_filehandle));
8 use Onis::Language (qw(translate));
9 use Onis::Data::Core (qw(register_plugin get_main_nick nick_to_ident nick_to_name));
10 use Onis::Data::Persistent ();
12 register_plugin ('TEXT', \&add);
13 register_plugin ('ACTION', \&add);
14 register_plugin ('OUTPUT', \&output);
16 our $WordCache = Onis::Data::Persistent->new ('WordCache', 'word', qw(counter lastusedtime lastusedby));
21 if (get_config ('ignore_words'))
23 my $tmp = get_config ('ignore_words');
26 $MIN_LENGTH = $tmp if ($tmp);
30 print STDERR $/, __FILE__, ": $VERSION" if ($::DEBUG);
37 my $text = $data->{'text'};
38 my $nick = $data->{'nick'};
39 my $words = $data->{'words'};
40 my $time = $data->{'epoch'};
46 next if (length ($word) < $MIN_LENGTH);
48 my ($counter) = $WordCache->get ($word);
51 $WordCache->put ($word, $counter, $time, $nick);
59 if (get_config ('plugin_max'))
61 my $tmp = get_config ('plugin_max');
64 $max = $tmp if ($tmp);
67 for ($WordCache->keys ())
70 my $ident = nick_to_ident ($word);
74 $WordCache->del ($word);
78 my ($counter, $lastusedtime, $lastusedby) = $WordCache->get ($word);
79 die unless (defined ($lastusedby));
81 my $nick = get_main_nick ($lastusedby);
82 push (@data, [$word, $counter, $nick, $lastusedtime]);
85 @$WordData = sort { $b->[1] <=> $a->[1] } (@data);
86 splice (@$WordData, $max);
92 return (undef) unless (@$WordData);
94 my $fh = get_filehandle ();
96 my $word = translate ('Word');
97 my $times = translate ('Times used');
98 my $last = translate ('Last used by');
101 <table class="plugin">
103 <td class="invis"> </td>
115 my ($word, $count, $nick) = @$_;
116 my $name = nick_to_name ($nick) || $nick;
119 qq# <td class="numeration">$i</td>\n#,
120 qq# <td>$word</td>\n#,
121 qq# <td>$count</td>\n#,
122 qq# <td class="nick">$name</td>\n#,
125 print $fh "</table>\n\n";