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
17 @bot.irclog "@ #{m.source} pinged #{who}"
19 m.ctcp_reply Time.now.to_s
20 @bot.irclog "@ #{m.source} asked #{who} what time it is"
24 def bot_join(m, param)
26 @bot.join param[:chan], param[:pass]
28 @bot.join param[:chan]
33 if @bot.auth.allow?(:"basics::move::join", m.source, m.source)
38 def bot_part(m, param)
40 @bot.part param[:chan]
42 @bot.part m.target if m.public?
46 def bot_quit(m, param)
47 @bot.quit param[:msg].to_s
50 def bot_restart(m, param)
51 @bot.restart param[:msg].to_s
54 def bot_hide(m, param)
59 @bot.say param[:where], param[:what].to_s
62 def bot_action(m, param)
63 @bot.action param[:where], param[:what].to_s
66 def bot_mode(m, param)
67 @bot.mode param[:where], param[:what], param[:who].join(" ")
70 def bot_ping(m, param)
74 def bot_quiet(m, param)
75 if param.has_key?(:where)
76 @bot.set_quiet param[:where].sub(/^here$/, m.target.downcase)
80 # Make sense when the commmand is given in private or in a non-quieted
85 def bot_talk(m, param)
86 if param.has_key?(:where)
87 @bot.reset_quiet param[:where].sub(/^here$/, m.target.downcase)
91 # Make sense when the commmand is given in private or in a non-quieted
96 def bot_help(m, param)
97 m.reply @bot.help(param[:topic].join(" "))
100 #TODO move these to a "chatback" plugin
101 # when (/^(botsnack|ciggie)$/i)
102 # @bot.say m.replyto, @lang.get("thanks_X") % m.sourcenick if(m.public?)
103 # @bot.say m.replyto, @lang.get("thanks") if(m.private?)
104 # when (/^#{Regexp.escape(@bot.nick)}!*$/)
105 # @bot.say m.replyto, @lang.get("hello_X") % m.sourcenick
107 # handle help requests for "core" topics
108 def help(cmd, topic="")
111 _("quit [<message>] => quit IRC with message <message>")
113 _("restart => completely stop and restart the bot (including reconnect)")
115 _("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")
117 _("part <channel> => part channel <channel>")
119 _("hide => part all channels")
121 _("nick <nick> => attempt to change nick to <nick>")
123 _("say <channel>|<nick> <message> => say <message> to <channel> or in private message to <nick>")
125 _("action <channel>|<nick> <message> => does a /me <message> to <channel> or in private message to <nick>")
127 _("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>")
129 _("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>")
131 _("ping => replies with a pong")
133 _("mode <channel> <mode> <nicks> => set channel modes for <nicks> on <channel> to <mode>")
135 # return "botsnack => reward #{@bot.myself} for being good"
137 # return "hello|hi|hey|yo [#{@bot.myself}] => greet the bot"
139 _("%{name}: quit, restart, join, part, hide, save, nick, say, action, topic, quiet, talk, ping, mode") % {:name=>name}
145 basics = BasicsModule.new
147 basics.map "quit *msg",
148 :action => 'bot_quit',
149 :defaults => { :msg => nil },
151 basics.map "restart *msg",
152 :action => 'bot_restart',
153 :defaults => { :msg => nil },
156 basics.map "quiet [in] [:where]",
157 :action => 'bot_quiet',
158 :auth_path => 'talk::set'
159 basics.map "talk [in] [:where]",
160 :action => 'bot_talk',
161 :auth_path => 'talk::set'
163 basics.map "say :where *what",
164 :action => 'bot_say',
165 :auth_path => 'talk::do'
166 basics.map "action :where *what",
167 :action => 'bot_action',
168 :auth_path => 'talk::do'
169 basics.map "mode :where :what *who",
170 :action => 'bot_mode',
171 :auth_path => 'talk::do'
173 basics.map "join :chan :pass",
174 :action => 'bot_join',
175 :defaults => {:pass => nil},
177 basics.map "part :chan",
178 :action => 'bot_part',
179 :defaults => {:chan => nil},
182 :action => 'bot_hide',
186 :action => 'bot_ping',
187 :auth_path => '!ping!'
188 basics.map "help *topic",
189 :action => 'bot_help',
190 :defaults => { :topic => [""] },
191 :auth_path => '!help!'
193 basics.default_auth('*', false)