]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/autoop.rb
demauro plugin: add is_italian? method (for use by other plugins)
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / autoop.rb
index 6187cf4dd3dfc3d793c3531c8274f9d290c2244c..a47375ca69d00e6ae5ccf096d07a4b1f961fdfa0 100644 (file)
@@ -1,19 +1,37 @@
 class AutoOP < Plugin
     def help(plugin, topic="")
-        "perform autoop based on hostmask - usage: addop <hostmask> [channel channel ...], rmop <hostmask> [channel], list - list current ops. If you don't specify which channels, all channels are assumed"
+        "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"
     end
     
     def join(m)
       return if m.address?
       @registry.each { |mask,channels|
-        if(Irc.netmaskmatch(mask, m.source) &&
-            (channels.empty? || channels.include?(m.channel)))
-          @bot.mode(m.channel, "+o", m.sourcenick)
+        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
       }
     end
 
+    def nick(m)
+      return if m.address?
+      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
+
     def add(m, params)
       @registry[params[:mask]] = params[:channels].dup
       m.okay