html/version-stat.pl
1 #!/usr/bin/perl -w
2 # shows top[0-9]+ irc client versions in a channel
3 # by c0ffee
4 # - http://www.penguin-breeder.org/?page=irssi
5
6 #<scriptinfo>
7 use vars qw($VERSION %IRSSI);
8
9 use Irssi 20020120;
10 $VERSION = "0.1";
11 %IRSSI = (
12 authors => "c0ffee",
13 contact => "c0ffee\@penguin-breeder.org",
14 name => "version-stats",
15 description => "shows top[0-9]+ irc client versions in a channel",
16 license => "Public Domain",
17 url => "http://www.penguin-breeder.org/?page=irssi",
18 changed => "Sun Apr 14 17:30 GMT 2002",
19 );
20 #</scriptinfo>
21
22 my %versions;
23 my $tag;
24 my $running = 0;
25
26 sub version_reply {
27 my ($server, $data, $nick, $addr, $target) = @_;
28
29 $versions{$data} = 1 + $versions{$data} if $running;
30
31 if (not Irssi::settings_get_bool('mute_version_reply') or not $running) {
32
33
34 Irssi::signal_emit("default ctcp reply", $server, "VERSION $data", $nick, $addr, $target);
35
36 }
37
38
39 }
40
41 sub show_stats {
42
43 my ($data) = @_;
44 my @stats = map "$versions{$_},$_", sort { $versions{$b} <=> $versions{$a} } keys %versions;
45 my ($top,$best,$cnt,$v,$foo,$bar);
46 $running = 0;
47
48 ($top,$best) = $data =~ /(.*)\/(.*)/;
49
50 Irssi::print("VERSION stats:");
51
52 Irssi::timeout_remove($tag);
53
54 foreach (1..$top) {
55 last if not defined $stats[$_ - 1];
56 ($cnt,$v) = $stats[$_ - 1] =~ /(.*?),(.*)/;
57 $bar = $cnt * 20 / $best;
58 $foo = "|" x $bar . "." x (20 - $bar),
59 Irssi::print("$_. [$foo]: ($cnt) $v");
60 }
61
62 }
63
64 sub cmd_vstat {
65 my ($data, $server, $channel) = @_;
66 my ($period, $top,@nicks,$num);
67
68 Irssi::print("usage: /vstat period-in-secs top-n"), return
69 if not (($period, $top) = $data =~ /(\d+)\s+(\d+)/);
70
71 @nicks = $channel->nicks();
72
73 $num = @nicks;
74
75 $tag = Irssi::timeout_add($period * 1000, 'show_stats', "$top/$num");
76
77 undef %versions;
78 $running = 1;
79
80 $server->send_raw("PRIVMSG $channel->{name} :\001VERSION\001");
81 Irssi::print("Starting version collection in $channel->{name}");
82
83 }
84
85 Irssi::signal_add_last('ctcp reply version', 'version_reply');
86 Irssi::command_bind('vstat', 'cmd_vstat');
87 Irssi::settings_add_bool('misc', 'mute_version_reply', 1);