2 Config.register Config::BooleanValue.new('autoop.on_nick',
4 :desc => "Determines if the bot should auto-op when someone changes nick " +
5 "and the new nick matches a listed netmask")
7 Config.register Config::StringValue.new('autoop.seed_format',
8 :default => "*!%{user}@*",
9 :desc => "Hostmask format used when seeding channels. Recognized tokens: " +
12 def help(plugin, topic="")
13 return "perform autoop based on hostmask - usage:" +
14 "add <hostmask> [channel channel ...], rm <hostmask> [channel], " +
15 "If you don't specify which channels, all channels are assumed, " +
16 "list - list current ops, " +
17 "restore [channel] - op anybody that would " +
18 "have been opped if they had just joined, " +
19 "seed [channel] - Find current ops and make sure they will " +
20 "continue to be autoopped"
25 @registry.each { |mask,channels|
26 if m.source.matches?(mask.to_irc_netmask(:server => m.server)) &&
27 (channels.empty? || channels.include?(m.channel.to_s))
28 @bot.mode(m.channel, "+o", m.source.nick)
36 return unless @bot.config['autoop.on_nick']
37 is_on = m.server.channels.inject(ChannelList.new) { |list, ch|
38 list << ch if ch.users.include?(m.source)
41 is_on.each { |channel|
43 @registry.each { |mask,channels|
44 if m.source.matches?(mask.to_irc_netmask(:server => m.server)) &&
45 (channels.empty? || channels.include?(ch))
46 @bot.mode(ch, "+o", m.source.nick)
54 if params[:channels].empty? || !@registry.has_key?(params[:mask])
55 # if the channels parameter is omitted (meaning all channels), or the
56 # hostmask isn't present in the registry, we just (over)write the channels
58 @registry[params[:mask]] = params[:channels].dup
61 # otherwise, merge the channels with the ones existing in the registry
62 current_channels = @registry[params[:mask]]
63 if current_channels.empty?
64 m.reply "#{params[:mask]} is already being auto-opped on all channels"
66 # merge the already set channels
67 @registry[params[:mask]] = (params[:channels] | current_channels).uniq
74 chan = params[:channel]
79 m.reply _("Either specify a channel to seed, or ask in public")
83 current_ops = @bot.server.channel(chan).users.select { |u|
84 u.is_op?(chan) and u.nick != @bot.nick
87 netmasks = current_ops.map { |u|
88 @bot.config['autoop.seed_format'] % {
95 to_add = netmasks.select { |mask|
96 @registry.key?(mask) == false or @registry[mask].empty? == false
100 m.reply _("Nobody to add")
106 if @registry.key? mask
107 if @registry[mask].include? chan
110 current_channels = @registry[mask].dup
111 @registry[mask] = ([chan] | current_channels).uniq
112 results << _("Added #{mask} in #{chan}")
115 @registry[mask] = [chan]
116 results << _("Created autoop entry for #{mask} and added #{chan}")
119 m.reply results.join ". "
123 unless @registry.has_key?(params[:mask])
124 m.reply @bot.lang.get('dunno')
127 if (!params[:channels].empty? && @registry[params[:mask]] != nil)
128 params[:channels].each do |c|
129 @registry[params[:mask]] = @registry[params[:mask]].reject {|ele| ele =~ /^#{c}$/i}
131 if @registry[params[:mask]].empty?
132 @registry.delete(params[:mask])
135 @registry.delete(params[:mask])
141 debug @registry.length
142 if(@registry.length > 0)
143 @registry.each { |mask,channels|
144 m.reply "#{mask} in #{channels.empty? ? 'all channels' : channels.join(', ')}"
151 def restore(m, params)
152 chan = params[:channel]
157 m.reply _("Either specify a channel to restore, or ask in public")
161 current_non_ops = @bot.server.channel(chan).users.select { |u|
162 u.is_op?(chan) == nil and u.nick != @bot.nick
165 @registry.each { |mask,channels|
166 if channels.empty? || channels.include?(chan)
167 current_non_ops.each { |victim|
168 if victim.matches?(mask.to_irc_netmask(:server => m.server))
169 @bot.mode(chan, "+o", victim)
179 plugin.map 'autoop list', :action => 'list'
180 plugin.map 'autoop add :mask [*channels]', :action => 'add'
181 plugin.map 'autoop rm :mask [*channels]', :action => 'rm'
182 plugin.map 'autoop seed [:channel]', :action => 'seed'
183 plugin.map 'autoop restore [:channel]', :action => 'restore'
185 plugin.default_auth('*',false)