-
Notifications
You must be signed in to change notification settings - Fork 235
/
cap-extjoin.pl
87 lines (71 loc) · 2.4 KB
/
cap-extjoin.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
82
83
84
85
86
87
# Support extended-joins in Irssi
# (c) 2012 Mike Quin <[email protected]>
#
# Licensed under GNU General Public License version 2
# <https://www.gnu.org/licenses/gpl-2.0.html>
use strict;
use warnings;
use Irssi;
our $VERSION = '0.9.0';
our %IRSSI = (
authors => 'Mike Quin, Krytarik Raido',
url => 'https://github.com/mquin/irssi-scripts',
name => 'cap-extjoin',
description => 'Print account and realname information on joins where extended-join is available',
license => 'GPLv2',
changed => 'Tue 12 Dec 16:12:24 GMT 2017'
);
Irssi::theme_register([
'join_extended' => '{channick_hilight $0} ({hilight $1}) {chanhost_hilight $2} has joined {channel $3}',
'join_extended_account' => '{channick_hilight $0 [$1]} ({hilight $2}) {chanhost_hilight $3} has joined {channel $4}'
]);
my %servers;
sub event_join {
my ($server, $data, $nick, $host) = @_;
unless ($servers{$server->{tag}}->{'EXTENDED-JOIN'}
and ! $server->netsplit_find($nick, $host)) {
return;
}
Irssi::signal_stop();
$data =~ /^(\S+) (\S+) :(.+)$/;
my ($channel, $account, $realname) = ($1, $2, $3);
if ($server->ignore_check($nick, $host, $channel, '', MSGLEVEL_JOINS)) {
return;
}
my $chanrec = $server->channel_find($channel);
if ($account ne '*') {
$chanrec->printformat(MSGLEVEL_JOINS, 'join_extended_account', $nick, $account, $realname, $host, $channel);
} else {
$chanrec->printformat(MSGLEVEL_JOINS, 'join_extended', $nick, $realname, $host, $channel);
}
}
sub extjoin_cap_reply {
my ($server, $data) = @_;
if ($data =~ /^\S+ ACK :extended-join\s*$/) {
$servers{$server->{tag}}->{'EXTENDED-JOIN'} = 1;
}
elsif ($data =~ /^\S+ NAK :extended-join\s*$/) {
$servers{$server->{tag}}->{'EXTENDED-JOIN'} = 0;
Irssi::signal_stop();
}
}
sub extjoin_connected {
my ($server) = @_;
$servers{$server->{tag}}->{'EXTENDED-JOIN'} = 0;
$server->command("quote cap req :extended-join");
}
sub extjoin_disconnected {
my ($server) = @_;
delete $servers{$server->{tag}};
}
Irssi::signal_add_first('event cap', 'extjoin_cap_reply');
Irssi::signal_add({
'event join' => 'event_join',
'event connected' => 'extjoin_connected',
'server disconnected' => 'extjoin_disconnected'
});
# On load enumerate the servers and try to turn on extended-join
foreach my $server (Irssi::servers()) {
extjoin_connected($server);
}