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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
#!/usr/bin/perl -w
# chops.pl: Simulates BitchX's /chops and /nops commands
# prints list with nickname and userhost
#
# Written by Jakub Jankowski <shasta@atn.pl>
# for irssi 0.7.98.CVS
#
# todo:
# - enhance the look of the script
#
# sample /chops output:
# [11:36:33] -!- Irssi: Information about chanops on #irssi
# [11:36:33] -!- Irssi: [nick] [hostmask]
# [11:36:33] -!- Irssi: shasta shasta@quasimodo.olsztyn.tpsa.pl
# [11:36:34] -!- Irssi: cras cras@xmunkki.org
# [11:36:34] -!- Irssi: fuchs fox@wh8043.stw.uni-rostock.de
# [11:36:34] -!- Irssi: End of listing
#
# sample /nops output:
# [11:40:34] -!- Irssi: Information about non-ops on #irssi
# [11:40:34] -!- Irssi: [nick] [hostmask]
# [11:40:34] -!- Irssi: globe_ ~globe@ui20i21hel.dial.kolumbus.fi
# [11:40:34] -!- Irssi: shastaBX shasta@thorn.kanal.olsztyn.pl
# [11:40:34] -!- Irssi: End of listing
use strict;
use vars qw($VERSION %IRSSI);
$VERSION = "20020223";
%IRSSI = (
authors => 'Jakub Jankowski',
contact => 'shasta@atn.pl',
name => 'chops',
description => 'Simulates BitchX\'s /CHOPS and /NOPS commands.',
license => 'GNU GPLv2 or later',
url => 'http://irssi.atn.pl/',
);
use Irssi;
use Irssi::Irc;
Irssi::theme_register([
'chops_nochan', 'You are not on a channel',
'chops_notsynced', 'Channel $0 is not fully synchronized yet',
'chops_noone', 'There are no $0 to list',
'chops_start', 'Information about $0 on $1',
'chops_end', 'End of listing',
'chops_header', '[nick] [hostmask]',
'chops_line', '$[!9]0 $[!50]1'
]);
sub cmd_chops {
my ($data, $server, $channel) = @_;
my @chanops = ();
# if we're not on a channel, print appropriate message and return
if (!$channel) {
Irssi::printformat(MSGLEVEL_CLIENTNOTICE, 'chops_nochan');
return;
}
# if channel is not fully synced yet, print appropriate message and return
if (!$channel->{synced}) {
Irssi::printformat(MSGLEVEL_CLIENTNOTICE, 'chops_notsynced', $channel->{name});
return;
}
# gather all opped people into an array
foreach my $nick ($channel->nicks()) {
push(@chanops, $nick) if ($nick->{op});
}
# if there are no chanops, print appropriate message and return
if (scalar(@chanops) < 1) {
Irssi::printformat(MSGLEVEL_CLIENTNOTICE, 'chops_noone', "chanops");
return;
}
# print a starting message
Irssi::printformat(MSGLEVEL_CLIENTNOTICE, 'chops_start', "chanops", $channel->{name});
# print listing header
Irssi::printformat(MSGLEVEL_CLIENTNOTICE, 'chops_header');
# print every chanop's nick, status (gone/here), userhost and hopcount
foreach my $nick (@chanops) {
my $userhost = $nick->{host};
# if user's host is longer than 50 characters, cut it to 47 to fit in column
$userhost = substr($userhost, 0, 47) if (length($userhost) > 50);
Irssi::printformat(MSGLEVEL_CLIENTNOTICE, 'chops_line', $nick->{nick}, $userhost);
}
# print listing footer
Irssi::printformat(MSGLEVEL_CLIENTNOTICE, 'chops_end');
}
sub cmd_nops {
my ($data, $server, $channel) = @_;
my @nonops = ();
# if we're not on a channel, print appropriate message and return
if (!$channel) {
Irssi::printformat(MSGLEVEL_CLIENTNOTICE, 'chops_nochan');
return;
}
# if channel is not fully synced yet, print appropriate message and return
if (!$channel->{synced}) {
Irssi::printformat(MSGLEVEL_CLIENTNOTICE, 'chops_notsynced', $channel->{name});
return;
}
# gather all not opped people into an array
foreach my $nick ($channel->nicks()) {
push(@nonops, $nick) if (!$nick->{op});
}
# if there are only chanops, print appropriate message and return
if (scalar(@nonops) < 1) {
Irssi::printformat(MSGLEVEL_CLIENTNOTICE, 'chops_noone', "non-ops");
return;
}
# print a starting message
Irssi::printformat(MSGLEVEL_CLIENTNOTICE, 'chops_start', "non-ops", $channel->{name});
# print listing header
Irssi::printformat(MSGLEVEL_CLIENTNOTICE, 'chops_header');
# print every chanop's nick, status (gone/here), userhost and hopcount
foreach my $nick (@nonops) {
my $userhost = $nick->{host};
# if user's host is longer than 50 characters, cut it to 47 to fit in column
$userhost = substr($userhost, 0, 47) if (length($userhost) > 50);
Irssi::printformat(MSGLEVEL_CLIENTNOTICE, 'chops_line', $nick->{nick}, $userhost);
}
# print listing footer
Irssi::printformat(MSGLEVEL_CLIENTNOTICE, 'chops_end');
}
Irssi::command_bind("chops", "cmd_chops");
Irssi::command_bind("nops", "cmd_nops");
|