4 # :title: rbot basic management from IRC
6 # Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>
8 class BasicsModule < CoreBotModule
10 Config.register Config::BooleanValue.new('irc.join_after_identify',
11 :default => false, :wizard => true, :requires_restart => true,
12 :desc => "Should the bot wait until its identification is confirmed before joining any channels?")
15 @bot.config['irc.join_channels'].each { |c|
16 debug "autojoining channel #{c}"
17 if(c =~ /^(\S+)\s+(\S+)$/i)
29 # on connect, we join the default channels unless we have to wait for
30 # identification. Observe that this means the bot may not connect any channels
31 # until the 'identified' method gets delegated
33 if @bot.config['irc.join_after_identify']
34 log "waiting for identififcation before JOINing default channels"
41 who = m.private? ? "me" : m.target
44 m.ctcp_reply m.message
46 m.ctcp_reply Time.now.to_s
50 def bot_join(m, param)
52 @bot.join param[:chan], param[:pass]
54 @bot.join param[:chan]
59 if @bot.auth.allow?(:"basics::move::join", m.source, m.source)
64 def bot_part(m, param)
66 @bot.part param[:chan]
68 @bot.part m.target if m.public?
72 def bot_channel_list(m, param)
74 # sort the channels by the base name and then map with prefixes for the
76 ret << @bot.channels.compact.sort { |a,b|
77 a.name.downcase <=> b.name.downcase
79 c.modes_of(@bot.myself).map{ |mo|
80 m.server.prefix_for_mode(mo)
86 def bot_quit(m, param)
87 @bot.quit param[:msg].to_s
90 def bot_restart(m, param)
91 @bot.restart param[:msg].to_s
94 def bot_reconnect(m, param)
95 @bot.reconnect param[:msg].to_s
98 def bot_hide(m, param)
102 def bot_say(m, param)
103 @bot.say param[:where], param[:what].to_s
106 def bot_action(m, param)
107 @bot.action param[:where], param[:what].to_s
110 def bot_mode(m, param)
111 @bot.mode param[:where], param[:what], param[:who].join(" ")
114 def bot_ping(m, param)
118 def bot_quiet(m, param)
119 if param.has_key?(:where)
120 @bot.set_quiet param[:where].sub(/^here$/, m.target.downcase)
124 # Make sense when the commmand is given in private or in a non-quieted
129 def bot_talk(m, param)
130 if param.has_key?(:where)
131 @bot.reset_quiet param[:where].sub(/^here$/, m.target.downcase)
135 # Make sense when the commmand is given in private or in a non-quieted
140 def bot_help(m, param)
141 m.reply @bot.help(param[:topic].join(" "))
144 #TODO move these to a "chatback" plugin
145 # when (/^(botsnack|ciggie)$/i)
146 # @bot.say m.replyto, @lang.get("thanks_X") % m.sourcenick if(m.public?)
147 # @bot.say m.replyto, @lang.get("thanks") if(m.private?)
148 # when (/^#{Regexp.escape(@bot.nick)}!*$/)
149 # @bot.say m.replyto, @lang.get("hello_X") % m.sourcenick
151 # handle help requests for "core" topics
152 def help(cmd, topic="")
155 _("quit [<message>] => quit IRC with message <message>")
157 _("restart => completely stop and restart the bot (including reconnect)")
159 _("reconnect => ask the bot to disconnect and then connect again")
161 _("join <channel> [<key>] => join channel <channel> with secret key <key> if specified. #{@bot.myself} also responds to invites if you have the required access level")
163 _("part <channel> => part channel <channel>")
165 _("hide => part all channels")
167 _("say <channel>|<nick> <message> => say <message> to <channel> or in private message to <nick>")
169 _("action <channel>|<nick> <message> => does a /me <message> to <channel> or in private message to <nick>")
171 _("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>")
173 _("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>")
175 _("ping => replies with a pong")
177 _("mode <channel> <mode> <nicks> => set channel modes for <nicks> on <channel> to <mode>")
179 # return "botsnack => reward #{@bot.myself} for being good"
181 # return "hello|hi|hey|yo [#{@bot.myself}] => greet the bot"
183 _("%{name}: quit, restart, join, part, hide, save, say, action, topic, quiet, talk, ping, mode") % {:name=>name}
189 basics = BasicsModule.new
191 basics.map "quit *msg",
192 :action => 'bot_quit',
193 :defaults => { :msg => nil },
195 basics.map "restart *msg",
196 :action => 'bot_restart',
197 :defaults => { :msg => nil },
199 basics.map "reconnect *msg",
200 :action => 'bot_reconnect',
201 :defaults => { :msg => nil },
204 basics.map "quiet [in] [:where]",
205 :action => 'bot_quiet',
206 :auth_path => 'talk::set'
207 basics.map "talk [in] [:where]",
208 :action => 'bot_talk',
209 :auth_path => 'talk::set'
211 basics.map "say :where *what",
212 :action => 'bot_say',
213 :auth_path => 'talk::do'
214 basics.map "action :where *what",
215 :action => 'bot_action',
216 :auth_path => 'talk::do'
217 basics.map "mode :where :what *who",
218 :action => 'bot_mode',
219 :auth_path => 'talk::do'
221 basics.map "join :chan :pass",
222 :action => 'bot_join',
223 :defaults => {:pass => nil},
225 basics.map "part :chan",
226 :action => 'bot_part',
227 :defaults => {:chan => nil},
229 basics.map "channels",
230 :action => 'bot_channel_list',
233 :action => 'bot_hide',
237 :action => 'bot_ping',
238 :auth_path => '!ping!'
239 basics.map "help *topic",
240 :action => 'bot_help',
241 :defaults => { :topic => [""] },
242 :auth_path => '!help!'
244 basics.default_auth('*', false)