]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - data/rbot/plugins/autoop.rb
Sat Jul 30 01:19:32 BST 2005 Tom Gilbert <tom@linuxbrit.co.uk>
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / autoop.rb
1 class AutoOP < Plugin
2     @@handlers = {
3         "addop" => "handle_addop",
4         "rmop" => "handle_rmop",
5         "listop" => "handle_listop"
6     }
7     
8     def help(plugin, topic="")
9         "perform autoop based on hostmask - usage: addop <hostmask>, rmop <hostmask>, listop"
10     end
11     
12     def join(m)
13         if(!m.address?)
14           @registry.each { |mask,channels|
15             if(Irc.netmaskmatch(mask, m.source) && channels.include?(m.channel))
16               @bot.mode(m.channel, "+o", m.sourcenick)
17             end
18           }
19         end
20     end
21     
22     def privmsg(m)
23         if(m.private?)
24           if (!m.params || m.params == "list")
25             handle_listop(m)
26           elsif (m.params =~ /^add\s+(.+)$/)
27             handle_addop(m, $1)
28           elsif (m.params =~ /^rm\s+(.+)$/)
29             handle_rmop(m, $1)
30           end
31         end
32     end
33
34     def handle_addop(m, params)
35         ma = /^(.+?)(\s+(.+))?$/.match(params)
36         channels = ma[2] ? ma[2] : @bot.config['JOIN_CHANNELS']
37         if(ma[1] && channels)
38             @registry[ma[1]] = channels.split(/,\s*/).collect { |x|
39                 x.strip
40             }
41             m.okay
42         else
43             m.reply @bot.lang.get('dunno')
44         end
45     end
46
47     def handle_rmop(m, params)
48        if(!@registry.delete(params))
49          m.reply @bot.lang.get('dunno')
50        else
51          m.okay
52        end
53     end
54
55     def handle_listop(m)
56         if(@registry.length)
57             @registry.each { |mask,channels|
58                 m.reply "#{mask} in #{channels.join(', ')}"
59             }
60         else
61             m.reply "No entrys"
62         end
63     end
64 end
65
66 plugin = AutoOP.new
67 plugin.register("autoop")
68