-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlastSpoke.pl
77 lines (61 loc) · 1.74 KB
/
lastSpoke.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/perl
use strict;
use warnings;
use Irssi;
use POSIX;
use Data::Dumper 'Dumper';
use vars qw($VERSION %IRSSI);
$VERSION = "0.01";
%IRSSI = (
authors => "Isaac Good",
contact => "irssi\@isaacgood.com",
name => "lastSpoke",
description => "Track when a user last spoke in a channel",
license => "Public Domain",
);
my %lastSpoke;
sub event_privmsg {
my ($server, $data, $nick, $address) = @_;
my ($target, $msg) = split(/ :/, $data, 2);
$lastSpoke{ lc( $target ) }{ lc( $nick ) } = time;
}
sub event_action {
my ($server, $data, $nick, $address, $target) = @_;
$lastSpoke{ lc( $target ) }{ lc( $nick ) } = time;
}
sub checkLastSpoke
{
my ( $nick, $server, $channelItem ) = @_;
$nick =~ / *$/;
if ( not ref ( $channelItem ) eq 'Irssi::Irc::Channel' )
{
Irssi::active_win()->print( "You need to run that command in a channel" );
return;
}
my $nickL = lc( $nick );
my $channel = lc( $channelItem->{'name'} );
if ( not defined( $lastSpoke{ $channel } ) )
{
Irssi::active_win()->print( "I don't have any info for this channel" );
return;
}
if ( not defined( $lastSpoke{ $channel }{ $nickL } ) )
{
Irssi::active_win()->print( "I don't have any info for that user" );
return;
}
my $last = $lastSpoke{ $channel }{ $nickL };
my $elapsed = time - $last;
my $message = sprintf(
"%s last spoke in this channel %d:%02d:%02d ago",
$nick,
int( ( $elapsed / 60 ) / 60 ),
int( ( $elapsed / 60 ) % 60 ),
int( ( $elapsed % 60 ) % 60 )
);
Irssi::active_win()->print( $message );
}
Irssi::command_bind( 'lspoke', \&checkLastSpoke );
Irssi::signal_add_last( "event privmsg", "event_privmsg" );
Irssi::signal_add_last( "message irc action", "event_action" );
# vim:set ts=4 sw=4 et: