4 # :title: rbot basic management from IRC
6 # Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>
7 # Copyright:: (C) 2006,2007 Giuseppe Bilotta
10 class BasicsModule < CoreBotModule
13 who = m.private? ? "me" : m.target
16 m.ctcp_reply m.message
18 m.ctcp_reply Time.now.to_s
22 def bot_join(m, param)
24 @bot.join param[:chan], param[:pass]
26 @bot.join param[:chan]
31 if @bot.auth.allow?(:"basics::move::join", m.source, m.source)
36 def bot_part(m, param)
38 @bot.part param[:chan]
40 @bot.part m.target if m.public?
44 def bot_quit(m, param)
45 @bot.quit param[:msg].to_s
48 def bot_restart(m, param)
49 @bot.restart param[:msg].to_s
52 def bot_hide(m, param)
57 @bot.say param[:where], param[:what].to_s
60 def bot_action(m, param)
61 @bot.action param[:where], param[:what].to_s
64 def bot_mode(m, param)
65 @bot.mode param[:where], param[:what], param[:who].join(" ")
68 def bot_ping(m, param)
72 def bot_quiet(m, param)
73 if param.has_key?(:where)
74 @bot.set_quiet param[:where].sub(/^here$/, m.target.downcase)
78 # Make sense when the commmand is given in private or in a non-quieted
83 def bot_talk(m, param)
84 if param.has_key?(:where)
85 @bot.reset_quiet param[:where].sub(/^here$/, m.target.downcase)
89 # Make sense when the commmand is given in private or in a non-quieted
94 def bot_help(m, param)
95 m.reply @bot.help(param[:topic].join(" "))
98 #TODO move these to a "chatback" plugin
99 # when (/^(botsnack|ciggie)$/i)
100 # @bot.say m.replyto, @lang.get("thanks_X") % m.sourcenick if(m.public?)
101 # @bot.say m.replyto, @lang.get("thanks") if(m.private?)
102 # when (/^#{Regexp.escape(@bot.nick)}!*$/)
103 # @bot.say m.replyto, @lang.get("hello_X") % m.sourcenick
105 # handle help requests for "core" topics
106 def help(cmd, topic="")
109 _("quit [<message>] => quit IRC with message <message>")
111 _("restart => completely stop and restart the bot (including reconnect)")
113 _("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")
115 _("part <channel> => part channel <channel>")
117 _("hide => part all channels")
119 _("nick <nick> => attempt to change nick to <nick>")
121 _("say <channel>|<nick> <message> => say <message> to <channel> or in private message to <nick>")
123 _("action <channel>|<nick> <message> => does a /me <message> to <channel> or in private message to <nick>")
125 _("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>")
127 _("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>")
129 _("ping => replies with a pong")
131 _("mode <channel> <mode> <nicks> => set channel modes for <nicks> on <channel> to <mode>")
133 # return "botsnack => reward #{@bot.myself} for being good"
135 # return "hello|hi|hey|yo [#{@bot.myself}] => greet the bot"
137 _("%{name}: quit, restart, join, part, hide, save, nick, say, action, topic, quiet, talk, ping, mode") % {:name=>name}
143 basics = BasicsModule.new
145 basics.map "quit *msg",
146 :action => 'bot_quit',
147 :defaults => { :msg => nil },
149 basics.map "restart *msg",
150 :action => 'bot_restart',
151 :defaults => { :msg => nil },
154 basics.map "quiet [in] [:where]",
155 :action => 'bot_quiet',
156 :auth_path => 'talk::set'
157 basics.map "talk [in] [:where]",
158 :action => 'bot_talk',
159 :auth_path => 'talk::set'
161 basics.map "say :where *what",
162 :action => 'bot_say',
163 :auth_path => 'talk::do'
164 basics.map "action :where *what",
165 :action => 'bot_action',
166 :auth_path => 'talk::do'
167 basics.map "mode :where :what *who",
168 :action => 'bot_mode',
169 :auth_path => 'talk::do'
171 basics.map "join :chan :pass",
172 :action => 'bot_join',
173 :defaults => {:pass => nil},
175 basics.map "part :chan",
176 :action => 'bot_part',
177 :defaults => {:chan => nil},
180 :action => 'bot_hide',
184 :action => 'bot_ping',
185 :auth_path => '!ping!'
186 basics.map "help *topic",
187 :action => 'bot_help',
188 :defaults => { :topic => [""] },
189 :auth_path => '!help!'
191 basics.default_auth('*', false)