/var/www/www.irssi.org-old/scripts/html/bantime.pl
1 use strict;
2 use Irssi; # developed using irssi 0.8.9.CVS
3 use Time::Duration; # calculates the ban duration.
4 # either of the following should install the module
5 # perl -MCPAN -e 'install Time::Duration'
6 # cpan -i Time::Duration
7 # apt-get install libtime-duration-perl
8
9 # I recommend rebinding irssi's default /BANS from 'ban' to 'bantimes' (/alias BANS BANTIME)
10
11 use vars qw($VERSION %IRSSI);
12 $VERSION = "0.5";
13 %IRSSI = (
14 authors => "David O\'Rourke",
15 contact => "phyber\@\#irssi",
16 name => "bantime",
17 description => "Print time when ban was set in a nicer way. eg. 23 mins, 40 secs ago.",
18 license => "GPLv2",
19 changed => "08.01.2004 02:46"
20 );
21
22 sub cmd_bans {
23 my ($args, $server, $witem) = @_;
24 return if not ($witem && $witem->{type} eq "CHANNEL");
25 my $currenttime = time;
26 my $channel = $witem->{name};
27 my $count = 1;
28 foreach my $ban ($witem->bans()) {
29 my ($bansetby, $bantime);
30 if ($ban->{setby}) {
31 $bansetby = $ban->{setby};
32 }
33 else { $bansetby = "*Unavailable"; }
34
35 if ($ban->{time}) {
36 $bantime = duration_exact($currenttime - $ban->{time}) . " ago";
37 }
38 else { $bantime = "*Unavailable"; }
39
40 $witem->printformat(MSGLEVEL_CLIENTCRAP, 'bantime_long', $count, $channel, $ban->{ban}, $bansetby, $bantime);
41 $count += 1;
42 }
43 }
44
45 Irssi::theme_register(['bantime_long', '{line_start}$0 - {channel $1}: ban {ban $2} {comment by {nick $3}, $4}']);
46 Irssi::command_bind('bantime', 'cmd_bans');
47 Irssi::print("Loaded $IRSSI{name} $VERSION");
48
49 #############
50 # ChangeLog #
51 #############
52 # 08.01.2004: Jan 08 2004: 02:46
53 # Fixed a bug which occured if the IRCd didn't tell us who set the bans at which time. eg. IRCNet if a user doesn't have +o.
54 # 08.01.2004: Jan 08 2004: 01:52
55 # Initial Release. Many thanks to coekie for helping me with my scripting.