]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - lib/rbot/core/basics.rb
Relocate help strings to proper locations, add help for 'mode' command
[user/henk/code/ruby/rbot.git] / lib / rbot / core / basics.rb
1 #-- vim:sw=2:et\r
2 #++\r
3 #\r
4 # :title: rbot basic management from IRC\r
5 #\r
6 # Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>\r
7 # Copyright:: (C) 2006,2007 Giuseppe Bilotta\r
8 # License:: GPL v2\r
9 \r
10 class BasicsModule < CoreBotModule\r
11 \r
12   def listen(m)\r
13     return unless m.kind_of?(PrivMessage)\r
14     if m.message =~ /^\001PING\s+(.+)\001/\r
15       ping_id = $1\r
16       if m.private?\r
17         @bot.notice m.source, "\001PING #{ping_id}\001"\r
18         @bot.irclog "@ #{m.source} pinged me"\r
19       else\r
20         @bot.notice m.source, "\001PING #{ping_id}\001"\r
21         @bot.irclog "@ #{m.source} pinged #{m.target}"\r
22       end\r
23     end\r
24   end\r
25 \r
26   def bot_join(m, param)\r
27     if param[:pass]\r
28       @bot.join param[:chan], param[:pass]\r
29     else\r
30       @bot.join param[:chan]\r
31     end\r
32   end\r
33 \r
34   def bot_part(m, param)\r
35     if param[:chan]\r
36       @bot.part param[:chan]\r
37     else\r
38       @bot.part m.target if m.public?\r
39     end\r
40   end\r
41 \r
42   def bot_quit(m, param)\r
43     @bot.quit(param[:msg] ? param[:msg].join(" ") : nil)\r
44   end\r
45 \r
46   def bot_restart(m, param)\r
47     @bot.restart(param[:msg] ? param[:msg].join(" ") : nil)\r
48   end\r
49 \r
50   def bot_hide(m, param)\r
51     @bot.join 0\r
52   end\r
53 \r
54   def bot_say(m, param)\r
55     @bot.say param[:where], param[:what].join(" ")\r
56   end\r
57 \r
58   def bot_action(m, param)\r
59     @bot.action param[:where], param[:what].join(" ")\r
60   end\r
61 \r
62   def bot_mode(m, param)\r
63     @bot.mode param[:where], param[:what], param[:who].join(" ")\r
64   end\r
65 \r
66   def bot_ping(m, param)\r
67     m.reply "pong"\r
68   end\r
69 \r
70   def bot_quiet(m, param)\r
71     if param.has_key?(:where)\r
72       @bot.set_quiet param[:where].sub(/^here$/, m.target.downcase)\r
73     else\r
74       @bot.set_quiet\r
75     end\r
76     # Make sense when the commmand is given in private or in a non-quieted\r
77     # channel\r
78     m.okay\r
79   end\r
80 \r
81   def bot_talk(m, param)\r
82     if param.has_key?(:where)\r
83       @bot.reset_quiet param[:where].sub(/^here$/, m.target.downcase)\r
84     else\r
85       @bot.reset_quiet\r
86     end\r
87     # Make sense when the commmand is given in private or in a non-quieted\r
88     # channel\r
89     m.okay\r
90   end\r
91 \r
92   def bot_help(m, param)\r
93     m.reply @bot.help(param[:topic].join(" "))\r
94   end\r
95 \r
96   #TODO move these to a "chatback" plugin\r
97   # when (/^(botsnack|ciggie)$/i)\r
98   #   @bot.say m.replyto, @lang.get("thanks_X") % m.sourcenick if(m.public?)\r
99   #   @bot.say m.replyto, @lang.get("thanks") if(m.private?)\r
100   # when (/^#{Regexp.escape(@bot.nick)}!*$/)\r
101   #   @bot.say m.replyto, @lang.get("hello_X") % m.sourcenick\r
102 \r
103   # handle help requests for "core" topics\r
104   def help(cmd, topic="")\r
105     case cmd\r
106     when "quit"\r
107       return "quit [<message>] => quit IRC with message <message>"\r
108     when "restart"\r
109       return "restart => completely stop and restart the bot (including reconnect)"\r
110     when "join"\r
111       return "join <channel> [<key>] => join channel <channel> with secret key <key> if specified. #{myself} also responds to invites if you have the required access level"\r
112     when "part"\r
113       return "part <channel> => part channel <channel>"\r
114     when "hide"\r
115       return "hide => part all channels"\r
116     when "nick"\r
117       return "nick <nick> => attempt to change nick to <nick>"\r
118     when "say"\r
119       return "say <channel>|<nick> <message> => say <message> to <channel> or in private message to <nick>"\r
120     when "action"\r
121       return "action <channel>|<nick> <message> => does a /me <message> to <channel> or in private message to <nick>"\r
122     when "quiet"\r
123       return "quiet [in here|<channel>] => with no arguments, stop speaking in all channels, if \"in here\", stop speaking in this channel, or stop speaking in <channel>"\r
124     when "talk"\r
125       return "talk [in here|<channel>] => with no arguments, resume speaking in all channels, if \"in here\", resume speaking in this channel, or resume speaking in <channel>"\r
126     when "version"\r
127       return "version => describes software version"\r
128     when "ping"\r
129       return "ping => replies with a pong"\r
130     when "mode"\r
131       return "mode <channel> <mode> <nicks> => set channel modes for <nicks> on <channel> to <mode>"\r
132     #     when "botsnack"\r
133     #       return "botsnack => reward #{myself} for being good"\r
134     #     when "hello"\r
135     #       return "hello|hi|hey|yo [#{myself}] => greet the bot"\r
136     else\r
137       return "#{name}: quit, restart, join, part, hide, save, nick, say, action, topic, quiet, talk, version, ping, mode"#, botsnack, hello"\r
138     end\r
139   end\r
140 end\r
141 \r
142 basics = BasicsModule.new\r
143 \r
144 basics.map "quit *msg",\r
145   :action => 'bot_quit',\r
146   :defaults => { :msg => nil },\r
147   :auth_path => 'quit'\r
148 basics.map "restart *msg",\r
149   :action => 'bot_restart',\r
150   :defaults => { :msg => nil },\r
151   :auth_path => 'quit'\r
152 \r
153 basics.map "quiet [in] [:where]",\r
154   :action => 'bot_quiet',\r
155   :auth_path => 'talk::set'\r
156 basics.map "talk [in] [:where]",\r
157   :action => 'bot_talk',\r
158   :auth_path => 'talk::set'\r
159 \r
160 basics.map "say :where *what",\r
161   :action => 'bot_say',\r
162   :auth_path => 'talk::do'\r
163 basics.map "action :where *what",\r
164   :action => 'bot_action',\r
165   :auth_path => 'talk::do'\r
166 basics.map "mode :where :what *who",\r
167   :action => 'bot_mode',\r
168   :auth_path => 'talk::do'\r
169 \r
170 basics.map "join :chan :pass", \r
171   :action => 'bot_join',\r
172   :defaults => {:pass => nil},\r
173   :auth_path => 'move'\r
174 basics.map "part :chan",\r
175   :action => 'bot_part',\r
176   :defaults => {:chan => nil},\r
177   :auth_path => 'move'\r
178 basics.map "hide",\r
179   :action => 'bot_hide',\r
180   :auth_path => 'move'\r
181 \r
182 basics.map "ping",\r
183   :action => 'bot_ping',\r
184   :auth_path => '!ping!'\r
185 basics.map "help *topic",\r
186   :action => 'bot_help',\r
187   :defaults => { :topic => [""] },\r
188   :auth_path => '!help!'\r
189 \r
190 basics.default_auth('*', false)\r
191 \r