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_quit(m, param)
73 @bot.quit param[:msg].to_s
76 def bot_restart(m, param)
77 @bot.restart param[:msg].to_s
80 def bot_reconnect(m, param)
81 @bot.reconnect param[:msg].to_s
84 def bot_hide(m, param)
89 @bot.say param[:where], param[:what].to_s
92 def bot_action(m, param)
93 @bot.action param[:where], param[:what].to_s
96 def bot_mode(m, param)
97 @bot.mode param[:where], param[:what], param[:who].join(" ")
100 def bot_ping(m, param)
104 def bot_quiet(m, param)
105 if param.has_key?(:where)
106 @bot.set_quiet param[:where].sub(/^here$/, m.target.downcase)
110 # Make sense when the commmand is given in private or in a non-quieted
115 def bot_talk(m, param)
116 if param.has_key?(:where)
117 @bot.reset_quiet param[:where].sub(/^here$/, m.target.downcase)
121 # Make sense when the commmand is given in private or in a non-quieted
126 def bot_help(m, param)
127 m.reply @bot.help(param[:topic].join(" "))
130 #TODO move these to a "chatback" plugin
131 # when (/^(botsnack|ciggie)$/i)
132 # @bot.say m.replyto, @lang.get("thanks_X") % m.sourcenick if(m.public?)
133 # @bot.say m.replyto, @lang.get("thanks") if(m.private?)
134 # when (/^#{Regexp.escape(@bot.nick)}!*$/)
135 # @bot.say m.replyto, @lang.get("hello_X") % m.sourcenick
137 # handle help requests for "core" topics
138 def help(cmd, topic="")
141 _("quit [<message>] => quit IRC with message <message>")
143 _("restart => completely stop and restart the bot (including reconnect)")
145 _("reconnect => ask the bot to disconnect and then connect again")
147 _("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")
149 _("part <channel> => part channel <channel>")
151 _("hide => part all channels")
153 _("say <channel>|<nick> <message> => say <message> to <channel> or in private message to <nick>")
155 _("action <channel>|<nick> <message> => does a /me <message> to <channel> or in private message to <nick>")
157 _("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>")
159 _("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>")
161 _("ping => replies with a pong")
163 _("mode <channel> <mode> <nicks> => set channel modes for <nicks> on <channel> to <mode>")
165 # return "botsnack => reward #{@bot.myself} for being good"
167 # return "hello|hi|hey|yo [#{@bot.myself}] => greet the bot"
169 _("%{name}: quit, restart, join, part, hide, save, say, action, topic, quiet, talk, ping, mode") % {:name=>name}
175 basics = BasicsModule.new
177 basics.map "quit *msg",
178 :action => 'bot_quit',
179 :defaults => { :msg => nil },
181 basics.map "restart *msg",
182 :action => 'bot_restart',
183 :defaults => { :msg => nil },
185 basics.map "reconnect *msg",
186 :action => 'bot_reconnect',
187 :defaults => { :msg => nil },
190 basics.map "quiet [in] [:where]",
191 :action => 'bot_quiet',
192 :auth_path => 'talk::set'
193 basics.map "talk [in] [:where]",
194 :action => 'bot_talk',
195 :auth_path => 'talk::set'
197 basics.map "say :where *what",
198 :action => 'bot_say',
199 :auth_path => 'talk::do'
200 basics.map "action :where *what",
201 :action => 'bot_action',
202 :auth_path => 'talk::do'
203 basics.map "mode :where :what *who",
204 :action => 'bot_mode',
205 :auth_path => 'talk::do'
207 basics.map "join :chan :pass",
208 :action => 'bot_join',
209 :defaults => {:pass => nil},
211 basics.map "part :chan",
212 :action => 'bot_part',
213 :defaults => {:chan => nil},
216 :action => 'bot_hide',
220 :action => 'bot_ping',
221 :auth_path => '!ping!'
222 basics.map "help *topic",
223 :action => 'bot_help',
224 :defaults => { :topic => [""] },
225 :auth_path => '!help!'
227 basics.default_auth('*', false)