]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - data/rbot/plugins/modes.rb
remove whitespace
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / modes.rb
1 class ModesPlugin < Plugin
2
3   def help(plugin, topic="")
4     return "'op [<user>] [<channel>]' => grant user> (if ommitted yourself) ops in <channel> (or in the current channel if no channel is specified). Use deop instead of op to remove the privilege."
5   end
6
7   def op(m, params)
8     channel = params[:channel]
9     user = params[:user]
10     do_mode(m, channel, user, "+o")
11   end
12
13   def opme(m, params)
14     params[:user] = m.sourcenick
15     op(m, params)
16   end
17
18   def deop(m, params)
19     channel = params[:channel]
20     user = params[:user]
21     do_mode(m, channel, user, "-o")
22   end
23
24   def deopme(m, params)
25     params[:user] = m.sourcenick
26     deop(m, params)
27   end
28
29   def hop(m, params)
30     channel = params[:channel]
31     user = params[:user]
32     do_mode(m, channel, user, "+h")
33   end
34
35   def hopme(m, params)
36     params[:user] = m.sourcenick
37     hop(m, params)
38   end
39
40   def dehop(m, params)
41     channel = params[:channel]
42     user = params[:user]
43     do_mode(m, channel, user, "-h")
44   end
45
46   def dehopme(m, params)
47     params[:user] = m.sourcenick
48     dehop(m, params)
49   end
50
51   def voice(m, params)
52     channel = params[:channel]
53     user = params[:user]
54     do_mode(m, channel, user, "+v")
55   end
56
57   def voiceme(m, params)
58     params[:user] = m.sourcenick
59     voice(m, params)
60   end
61
62   def devoice(m, params)
63     channel = params[:channel]
64     user = params[:user]
65     do_mode(m, channel, user, "-v")
66   end
67
68   def devoiceme(m, params)
69     params[:user] = m.sourcenick
70     devoice(m, params)
71   end
72
73   def do_mode(m, channel, user, mode)
74     unless channel
75       if m.private?
76         target = user.nil? ? "you" : user
77         m.reply "You should tell me where you want me to #{mode} #{target}."
78         return
79       else
80         channel = m.channel
81       end
82     else
83       channel = m.server.channel(channel)
84
85       unless channel.has_user?(@bot.nick)
86         m.reply "I am not in that channel"
87         return
88       end
89     end
90
91     unless user
92       user = m.sourcenick
93     end
94
95     m.okay unless channel == m.channel.to_s
96     @bot.mode(channel, mode, user)
97   end
98 end
99
100 plugin = ModesPlugin.new
101 plugin.map("op [:user] [:channel]")
102 plugin.map("opme [:channel]") # For backwards compatibility with 0.9.10
103 plugin.map("deop [:user] [:channel]")
104 plugin.map("deopme [:channel]") # For backwards compatibility with 0.9.10
105 plugin.map("hop [:user] [:channel]")
106 plugin.map("hopme [:channel]")
107 plugin.map("dehop [:user] [:channel]")
108 plugin.map("dehopme [:channel]")
109 plugin.map("voice [:user] [:channel]")
110 plugin.map("voiceme [:channel]")
111 plugin.map("devoice [:user] [:channel]")
112 plugin.map("devoiceme [:channel]")
113 plugin.default_auth("*",false)
114