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 join_channels unless @bot.config['irc.join_after_identify']
37 who = m.private? ? "me" : m.target
40 m.ctcp_reply m.message
42 m.ctcp_reply Time.now.to_s
46 def bot_join(m, param)
48 @bot.join param[:chan], param[:pass]
50 @bot.join param[:chan]
55 if @bot.auth.allow?(:"basics::move::join", m.source, m.source)
60 def bot_part(m, param)
62 @bot.part param[:chan]
64 @bot.part m.target if m.public?
68 def bot_quit(m, param)
69 @bot.quit param[:msg].to_s
72 def bot_restart(m, param)
73 @bot.restart param[:msg].to_s
76 def bot_hide(m, param)
81 @bot.say param[:where], param[:what].to_s
84 def bot_action(m, param)
85 @bot.action param[:where], param[:what].to_s
88 def bot_mode(m, param)
89 @bot.mode param[:where], param[:what], param[:who].join(" ")
92 def bot_ping(m, param)
96 def bot_quiet(m, param)
97 if param.has_key?(:where)
98 @bot.set_quiet param[:where].sub(/^here$/, m.target.downcase)
102 # Make sense when the commmand is given in private or in a non-quieted
107 def bot_talk(m, param)
108 if param.has_key?(:where)
109 @bot.reset_quiet param[:where].sub(/^here$/, m.target.downcase)
113 # Make sense when the commmand is given in private or in a non-quieted
118 def bot_help(m, param)
119 m.reply @bot.help(param[:topic].join(" "))
122 #TODO move these to a "chatback" plugin
123 # when (/^(botsnack|ciggie)$/i)
124 # @bot.say m.replyto, @lang.get("thanks_X") % m.sourcenick if(m.public?)
125 # @bot.say m.replyto, @lang.get("thanks") if(m.private?)
126 # when (/^#{Regexp.escape(@bot.nick)}!*$/)
127 # @bot.say m.replyto, @lang.get("hello_X") % m.sourcenick
129 # handle help requests for "core" topics
130 def help(cmd, topic="")
133 _("quit [<message>] => quit IRC with message <message>")
135 _("restart => completely stop and restart the bot (including reconnect)")
137 _("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")
139 _("part <channel> => part channel <channel>")
141 _("hide => part all channels")
143 _("say <channel>|<nick> <message> => say <message> to <channel> or in private message to <nick>")
145 _("action <channel>|<nick> <message> => does a /me <message> to <channel> or in private message to <nick>")
147 _("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>")
149 _("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>")
151 _("ping => replies with a pong")
153 _("mode <channel> <mode> <nicks> => set channel modes for <nicks> on <channel> to <mode>")
155 # return "botsnack => reward #{@bot.myself} for being good"
157 # return "hello|hi|hey|yo [#{@bot.myself}] => greet the bot"
159 _("%{name}: quit, restart, join, part, hide, save, say, action, topic, quiet, talk, ping, mode") % {:name=>name}
165 basics = BasicsModule.new
167 basics.map "quit *msg",
168 :action => 'bot_quit',
169 :defaults => { :msg => nil },
171 basics.map "restart *msg",
172 :action => 'bot_restart',
173 :defaults => { :msg => nil },
176 basics.map "quiet [in] [:where]",
177 :action => 'bot_quiet',
178 :auth_path => 'talk::set'
179 basics.map "talk [in] [:where]",
180 :action => 'bot_talk',
181 :auth_path => 'talk::set'
183 basics.map "say :where *what",
184 :action => 'bot_say',
185 :auth_path => 'talk::do'
186 basics.map "action :where *what",
187 :action => 'bot_action',
188 :auth_path => 'talk::do'
189 basics.map "mode :where :what *who",
190 :action => 'bot_mode',
191 :auth_path => 'talk::do'
193 basics.map "join :chan :pass",
194 :action => 'bot_join',
195 :defaults => {:pass => nil},
197 basics.map "part :chan",
198 :action => 'bot_part',
199 :defaults => {:chan => nil},
202 :action => 'bot_hide',
206 :action => 'bot_ping',
207 :auth_path => '!ping!'
208 basics.map "help *topic",
209 :action => 'bot_help',
210 :defaults => { :topic => [""] },
211 :auth_path => '!help!'
213 basics.default_auth('*', false)