4 # :title: rbot basic management from IRC
6 # Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>
8 class BasicsModule < CoreBotModule
11 who = m.private? ? "me" : m.target
14 m.ctcp_reply m.message
16 m.ctcp_reply Time.now.to_s
20 def bot_join(m, param)
22 @bot.join param[:chan], param[:pass]
24 @bot.join param[:chan]
29 if @bot.auth.allow?(:"basics::move::join", m.source, m.source)
34 def bot_part(m, param)
36 @bot.part param[:chan]
38 @bot.part m.target if m.public?
42 def bot_quit(m, param)
43 @bot.quit param[:msg].to_s
46 def bot_restart(m, param)
47 @bot.restart param[:msg].to_s
50 def bot_hide(m, param)
55 @bot.say param[:where], param[:what].to_s
58 def bot_action(m, param)
59 @bot.action param[:where], param[:what].to_s
62 def bot_mode(m, param)
63 @bot.mode param[:where], param[:what], param[:who].join(" ")
66 def bot_ping(m, param)
70 def bot_quiet(m, param)
71 if param.has_key?(:where)
72 @bot.set_quiet param[:where].sub(/^here$/, m.target.downcase)
76 # Make sense when the commmand is given in private or in a non-quieted
81 def bot_talk(m, param)
82 if param.has_key?(:where)
83 @bot.reset_quiet param[:where].sub(/^here$/, m.target.downcase)
87 # Make sense when the commmand is given in private or in a non-quieted
92 def bot_help(m, param)
93 m.reply @bot.help(param[:topic].join(" "))
96 #TODO move these to a "chatback" plugin
97 # when (/^(botsnack|ciggie)$/i)
98 # @bot.say m.replyto, @lang.get("thanks_X") % m.sourcenick if(m.public?)
99 # @bot.say m.replyto, @lang.get("thanks") if(m.private?)
100 # when (/^#{Regexp.escape(@bot.nick)}!*$/)
101 # @bot.say m.replyto, @lang.get("hello_X") % m.sourcenick
103 # handle help requests for "core" topics
104 def help(cmd, topic="")
107 _("quit [<message>] => quit IRC with message <message>")
109 _("restart => completely stop and restart the bot (including reconnect)")
111 _("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")
113 _("part <channel> => part channel <channel>")
115 _("hide => part all channels")
117 _("nick <nick> => attempt to change nick to <nick>")
119 _("say <channel>|<nick> <message> => say <message> to <channel> or in private message to <nick>")
121 _("action <channel>|<nick> <message> => does a /me <message> to <channel> or in private message to <nick>")
123 _("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>")
125 _("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>")
127 _("ping => replies with a pong")
129 _("mode <channel> <mode> <nicks> => set channel modes for <nicks> on <channel> to <mode>")
131 # return "botsnack => reward #{@bot.myself} for being good"
133 # return "hello|hi|hey|yo [#{@bot.myself}] => greet the bot"
135 _("%{name}: quit, restart, join, part, hide, save, nick, say, action, topic, quiet, talk, ping, mode") % {:name=>name}
141 basics = BasicsModule.new
143 basics.map "quit *msg",
144 :action => 'bot_quit',
145 :defaults => { :msg => nil },
147 basics.map "restart *msg",
148 :action => 'bot_restart',
149 :defaults => { :msg => nil },
152 basics.map "quiet [in] [:where]",
153 :action => 'bot_quiet',
154 :auth_path => 'talk::set'
155 basics.map "talk [in] [:where]",
156 :action => 'bot_talk',
157 :auth_path => 'talk::set'
159 basics.map "say :where *what",
160 :action => 'bot_say',
161 :auth_path => 'talk::do'
162 basics.map "action :where *what",
163 :action => 'bot_action',
164 :auth_path => 'talk::do'
165 basics.map "mode :where :what *who",
166 :action => 'bot_mode',
167 :auth_path => 'talk::do'
169 basics.map "join :chan :pass",
170 :action => 'bot_join',
171 :defaults => {:pass => nil},
173 basics.map "part :chan",
174 :action => 'bot_part',
175 :defaults => {:chan => nil},
178 :action => 'bot_hide',
182 :action => 'bot_ping',
183 :auth_path => '!ping!'
184 basics.map "help *topic",
185 :action => 'bot_help',
186 :defaults => { :topic => [""] },
187 :auth_path => '!help!'
189 basics.default_auth('*', false)