-
Notifications
You must be signed in to change notification settings - Fork 235
/
betterlist.pl
81 lines (66 loc) · 1.91 KB
/
betterlist.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
78
79
80
81
use Irssi;
use strict;
use warnings;
use Text::ParseWords;
use vars qw($VERSION %IRSSI);
$VERSION = "2.2";
%IRSSI = (
authors => "Liam Hopkins",
contact => "we.hopkins\@gmail.com",
commands => "betterlist",
name => "betterlist",
description => "/betterlist <perl-regexp>",
license => "GPL",
modules => "Text::ParseWords",
);
my $running = 0; # flag to prevent overlapping requests.
my $match;
sub call_list_cmd {
my ($server, $args) = @_;
# set a one-time redirect for handling responses of a given command
$server->redirect_event('list', 1, '', -1, 'redir my_timeout',
{
'event 321' => 'redir my_liststart',
'event 322' => 'redir my_list',
'event 323' => 'redir my_listend',
'' => 'event empty',
});
# execute the command
$server->send_raw("LIST");
}
sub event_list {
my ($server, $data) = @_;
my $channel = ( split / +/, $data)[1];
Irssi::active_win->print("Matched $channel", MSGLEVEL_CLIENTCRAP) if ($channel =~ /$match/)
}
sub event_liststart {
Irssi::active_win->print("Looking for $match", MSGLEVEL_CLIENTCRAP);
}
sub event_listend {
Irssi::active_win->print("End of /LIST", MSGLEVEL_CLIENTCRAP);
$running = 0;
}
sub event_timeout {
my ($server, $data) = @_;
Irssi::print("timeout", MSGLEVEL_CLIENTCRAP);
$running = 0;
}
sub betterlist {
my ($data, $server, $witem) = @_;
if ($running) {
Irssi::active_win->print("please try again shortly.", MSGLEVEL_CLIENTCRAP);
return;
}
$running = 1;
my (@args) = "ewords(' ', 1, $data);
($match) = "ewords(' ', 0, shift(@args));
call_list_cmd($server);
Irssi::signal_stop();
}
Irssi::signal_add_first ({
'redir my_liststart' => 'event_liststart',
'redir my_list' => 'event_list',
'redir my_listend' => 'event_listend',
});
Irssi::command_bind("betterlist", \&betterlist);
# vim:set ts=2 sw=2 expandtab: