Skip to content

Commit 0c9a298

Browse files
committed
Merge pull request weechat#101 from arza-zara/samechannel
samechannel.rb 0.1: option -m/--minimum for minimum count of mutual channels, fixed completion
2 parents 89e7281 + bc23638 commit 0c9a298

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

ruby/samechannel.rb

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#
22
# (c) 2013 Hendrik 'henk' Jaeger <[email protected]>
3+
# (c) 2015 arza <[email protected]>
34
#
45
# This program is free software; you can redistribute it and/or modify
56
# it under the terms of the GNU General Public License as published by
@@ -15,11 +16,18 @@
1516
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1617
#
1718

19+
# Changelog:
20+
# 2013-10-19 0.0.1 henk:
21+
# - initial release
22+
# 2015-09-24 0.1 arza:
23+
# - option -m/--minimum for minimum count of mutual channels
24+
# - fixed completion
25+
1826
def weechat_init
1927
Weechat.register(
2028
"samechannel",
2129
"henk",
22-
"0.0.1",
30+
"0.1",
2331
"GPL3",
2432
"Lists multiple occurences of the same nick(s) in a set of channels.",
2533
"",
@@ -29,34 +37,33 @@ def weechat_init
2937
Weechat.hook_command(
3038
"samechannel",
3139
"Lists multiple occurences of the same nick(s) in a set of channels.",
32-
"[[-s|--servers] servername[,...]] [[-c|--channels] channelname[,...]] [[-n|--nicks] nickname[,...]]",
40+
"[-s/--servers servername[,...]] [-c/--channels channelname[,...]] [-n/--nicks nickname[,...]] [-m/--minimum minimum]",
3341
"--servers servername[,servername],...]
3442
--channels channelname[@servername][,channelname[@servername],...]
3543
--nicks nickname[,nickname,...]
36-
Options used to set filters. All given names are treated as regular expressions. If no names are given, no filters are set.
44+
--minimum minimum (default: 2)
3745
38-
WARNING: If you are joined to MANY or even just a few very crowded channels, this script may have to do a lot of comparisons!
46+
Options used to set filters. All given names are treated as regular expressions. If no names are given, no filters are set.
3947
4048
NOTE: Only nicknames from channels the client is joined to are available for comparison!
4149
4250
EXAMPLES:
51+
52+
/samechannel -m 5 -s freenode,IRCnet
53+
Lists nicks found on at least five channels in freenode and IRCnet combined.
54+
4355
/samechannel --channels foo
44-
Lists nicks found in more than two channels on all servers.
56+
Lists nicks found on at least two channels that include 'foo' on all servers.
4557
4658
/samechannel --nicks barbaz,hons --servers example,foobarbaz
4759
Lists channels from the servers example and foobarbaz for each given nick.
4860
4961
/samechannel --nicks foo --channels ^#example.*@.*free.*$
5062
Lists channels you share with nick foo that begin with 'example' from every server with 'free' in their names.",
51-
"-servers %(irc_servers)
52-
|| -servers %(irc_servers) -channels %(irc_channels)
53-
|| -servers %(irc_servers) -nicks %(irc_server_nicks)
54-
|| -channels %(irc_channels)
55-
|| -channels %(irc_channels) -servers %(irc_servers)
56-
|| -channels %(irc_channels) -nicks %(irc_server_nicks)
57-
|| -nicks %(irc_server_nicks)
58-
|| -nicks %(irc_server_nicks) -servers %(irc_servers)
59-
|| -nicks %(irc_server_nicks) -channels %(irc_channels)",
63+
"--minimum" +
64+
"|| --servers %(irc_servers) --minimum --channels %(irc_channels)" +
65+
"|| --channels %(irc_channels) --servers %(irc_servers)" +
66+
"|| --nicks %(irc_server_nicks) --servers %(irc_servers)",
6067
"samechannel_cb",
6168
""
6269
)
@@ -98,8 +105,11 @@ def samechannel_cb( data, buffer, args )
98105
end
99106
end
100107

108+
minimum = options[:minimumfilter].to_i
109+
minimum = 2 if minimum==0
110+
101111
duplicate_nicks = nickcount.delete_if do |nickname, nickpaths|
102-
nickpaths.length <= 1
112+
nickpaths.length < minimum
103113
end
104114
duplicate_nicks_sorted = duplicate_nicks.sort do |a, b|
105115
a[1].length <=> b[1].length
@@ -168,6 +178,7 @@ def get_options( args )
168178
options = Hash.new
169179

170180
opt_parser = OptionParser.new do |opts|
181+
171182
opts.on("-c", "--channels channelname[,channelname,...]",
172183
"Only channels matching the given (partial) channelname(s) will be considered.)") do |channels|
173184
options[:channelfilter] = channels.split(',')
@@ -182,6 +193,12 @@ def get_options( args )
182193
"Only servers matching the given (partial) servername(s) will be considered.)") do |servers|
183194
options[:serverfilter] = servers.split(',')
184195
end
196+
197+
opts.on("-m", "--minimum minimum",
198+
"Only nicks with at least this many matches will be considered.") do |minimum|
199+
options[:minimumfilter] = minimum
200+
end
201+
185202
end
186203

187204
opt_parser.parse(args)

0 commit comments

Comments
 (0)