X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fautoop.rb;h=c45419066a5bd585ec2cc56a1e48580ff1cc8ec8;hb=7b7f1309e8c3dbc3bb4408d56489ae5fba77d57a;hp=fdbcf6e01d1d0536eba1ffd91da657bd01fcac06;hpb=21949774b91eaec6ecde4eaa8ad121e2c0a36b87;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/autoop.rb b/data/rbot/plugins/autoop.rb index fdbcf6e0..c4541906 100644 --- a/data/rbot/plugins/autoop.rb +++ b/data/rbot/plugins/autoop.rb @@ -1,68 +1,79 @@ class AutoOP < Plugin - @@handlers = { - "addop" => "handle_addop", - "rmop" => "handle_rmop", - "listop" => "handle_listop" + BotConfig.register BotConfigBooleanValue.new('autoop.on_nick', + :default => true, + :desc => "Determines if the bot should auto-op when someone changes nick and the new nick matches a listed netmask") + + def help(plugin, topic="") + return "perform autoop based on hostmask - usage: add [channel channel ...], rm [channel], list - list current ops. If you don't specify which channels, all channels are assumed" + end + + def join(m) + return if m.address? + @registry.each { |mask,channels| + if m.source.matches?(mask.to_irc_netmask(:server => m.server)) && + (channels.empty? || channels.include?(m.channel.to_s)) + @bot.mode(m.channel, "+o", m.source.nick) + return + end } - - def help(plugin, topic="") - "perform autoop based on hostmask - usage: addop , rmop , listop" - end - - def join(m) - if(!m.address?) - @registry.each { |mask,channels| - if(Irc.netmaskmatch(mask, m.source) && channels.include?(m.channel)) - @bot.mode(m.channel, "+o", m.sourcenick) - end - } - end - end - - def privmsg(m) - if(m.private?) - if (!m.params || m.params == "list") - handle_listop(m) - elsif (m.params =~ /^add\s+(.+)$/) - handle_addop(m, $1) - elsif (m.params =~ /^rm\s+(.+)$/) - handle_rmop(m, $1) - end - end - end + end - def handle_addop(m, params) - ma = /^(.+?)(\s+(.+))?$/.match(params) - channels = ma[2] ? ma[2] : @bot.config['JOIN_CHANNELS'] - if(ma[1] && channels) - @registry[ma[1]] = channels.split(/,\s*/).collect { |x| - x.strip - } - m.okay - else - m.reply @bot.lang.get('dunno') + def nick(m) + return if m.address? + return unless @bot.config['autoop.on_nick'] + is_on = m.server.channels.inject(ChannelList.new) { |list, ch| + list << ch if ch.users.include?(m.source) + list + } + is_on.each { |channel| + ch = channel.to_s + @registry.each { |mask,channels| + if m.source.matches?(mask.to_irc_netmask(:server => m.server)) && + (channels.empty? || channels.include?(ch)) + @bot.mode(ch, "+o", m.source.nick) + return end - end + } + } + end - def handle_rmop(m, params) - if(!@registry.delete(params)) - m.reply @bot.lang.get('dunno') - else - m.okay - end + def add(m, params) + @registry[params[:mask]] = params[:channels].dup + m.okay + end + + def rm(m, params) + unless @registry.has_key?(params[:mask]) + m.reply @bot.lang.get('dunno') + return + end + if (!params[:channels].empty? && @registry[params[:mask]] != nil) + params[:channels].each do |c| + @registry[params[:mask]] = @registry[params[:mask]].reject {|ele| ele =~ /^#{c}$/i} + end + if @registry[params[:mask]].empty? + @registry.delete(params[:mask]) + end + else + @registry.delete(params[:mask]) end + m.okay + end - def handle_listop(m) - if(@registry.length) - @registry.each { |mask,channels| - m.reply "#{mask} in #{channels.join(', ')}" - } - else - m.reply "No entrys" - end + def list(m, params) + debug @registry.length + if(@registry.length > 0) + @registry.each { |mask,channels| + m.reply "#{mask} in #{channels.empty? ? 'all channels' : channels.join(', ')}" + } + else + m.reply "No entries" end + end end plugin = AutoOP.new -plugin.register("autoop") +plugin.map 'autoop list', :action => 'list' +plugin.map 'autoop add :mask [*channels]', :action => 'add' +plugin.map 'autoop rm :mask [*channels]', :action => 'rm'