2 BotConfig.register BotConfigBooleanValue.new('autoop.on_nick',
4 :desc => "Determines if the bot should auto-op when someone changes nick and the new nick matches a listed netmask")
6 def help(plugin, topic="")
7 return "perform autoop based on hostmask - usage: add <hostmask> [channel channel ...], rm <hostmask> [channel], list - list current ops. If you don't specify which channels, all channels are assumed"
12 @registry.each { |mask,channels|
13 if m.source.matches?(mask.to_irc_netmask(:server => m.server)) &&
14 (channels.empty? || channels.include?(m.channel.to_s))
15 @bot.mode(m.channel, "+o", m.source.nick)
23 return unless @bot.config['autoop.on_nick']
24 is_on = m.server.channels.inject(ChannelList.new) { |list, ch|
25 list << ch if ch.users.include?(m.source)
28 is_on.each { |channel|
30 @registry.each { |mask,channels|
31 if m.source.matches?(mask.to_irc_netmask(:server => m.server)) &&
32 (channels.empty? || channels.include?(ch))
33 @bot.mode(ch, "+o", m.source.nick)
41 if params[:channels].empty? || !@registry.has_key?(params[:mask])
42 # if the channels parameter is omitted (meaning all channels), or the
43 # hostmask isn't present in the registry, we just (over)write the channels
45 @registry[params[:mask]] = params[:channels].dup
48 # otherwise, merge the channels with the ones existing in the registry
49 current_channels = @registry[params[:mask]]
50 if current_channels.empty?
51 m.reply "#{params[:mask]} is already being auto-opped on all channels"
53 # merge the already set channels
54 @registry[params[:mask]] = (params[:channels] | current_channels).uniq
61 unless @registry.has_key?(params[:mask])
62 m.reply @bot.lang.get('dunno')
65 if (!params[:channels].empty? && @registry[params[:mask]] != nil)
66 params[:channels].each do |c|
67 @registry[params[:mask]] = @registry[params[:mask]].reject {|ele| ele =~ /^#{c}$/i}
69 if @registry[params[:mask]].empty?
70 @registry.delete(params[:mask])
73 @registry.delete(params[:mask])
79 debug @registry.length
80 if(@registry.length > 0)
81 @registry.each { |mask,channels|
82 m.reply "#{mask} in #{channels.empty? ? 'all channels' : channels.join(', ')}"
92 plugin.map 'autoop list', :action => 'list'
93 plugin.map 'autoop add :mask [*channels]', :action => 'add'
94 plugin.map 'autoop rm :mask [*channels]', :action => 'rm'