4 # :title: rbot basic management from IRC
\r
6 # Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>
\r
7 # Copyright:: (C) 2006,2007 Giuseppe Bilotta
\r
10 class BasicsModule < CoreBotModule
\r
13 return unless m.kind_of?(PrivMessage)
\r
14 if m.message =~ /^\001PING\s+(.+)\001/
\r
17 @bot.notice m.source, "\001PING #{ping_id}\001"
\r
18 @bot.irclog "@ #{m.source} pinged me"
\r
20 @bot.notice m.source, "\001PING #{ping_id}\001"
\r
21 @bot.irclog "@ #{m.source} pinged #{m.target}"
\r
26 def bot_join(m, param)
\r
28 @bot.join param[:chan], param[:pass]
\r
30 @bot.join param[:chan]
\r
34 def bot_part(m, param)
\r
36 @bot.part param[:chan]
\r
38 @bot.part m.target if m.public?
\r
42 def bot_quit(m, param)
\r
43 @bot.quit(param[:msg] ? param[:msg].join(" ") : nil)
\r
46 def bot_restart(m, param)
\r
47 @bot.restart(param[:msg] ? param[:msg].join(" ") : nil)
\r
50 def bot_hide(m, param)
\r
54 def bot_say(m, param)
\r
55 @bot.say param[:where], param[:what].join(" ")
\r
58 def bot_action(m, param)
\r
59 @bot.action param[:where], param[:what].join(" ")
\r
62 def bot_mode(m, param)
\r
63 @bot.mode param[:where], param[:what], param[:who].join(" ")
\r
66 def bot_ping(m, param)
\r
70 def bot_quiet(m, param)
\r
71 if param.has_key?(:where)
\r
72 @bot.set_quiet param[:where].sub(/^here$/, m.target.downcase)
\r
76 # Make sense when the commmand is given in private or in a non-quieted
\r
81 def bot_talk(m, param)
\r
82 if param.has_key?(:where)
\r
83 @bot.reset_quiet param[:where].sub(/^here$/, m.target.downcase)
\r
87 # Make sense when the commmand is given in private or in a non-quieted
\r
92 def bot_help(m, param)
\r
93 m.reply @bot.help(param[:topic].join(" "))
\r
96 #TODO move these to a "chatback" plugin
\r
97 # when (/^(botsnack|ciggie)$/i)
\r
98 # @bot.say m.replyto, @lang.get("thanks_X") % m.sourcenick if(m.public?)
\r
99 # @bot.say m.replyto, @lang.get("thanks") if(m.private?)
\r
100 # when (/^#{Regexp.escape(@bot.nick)}!*$/)
\r
101 # @bot.say m.replyto, @lang.get("hello_X") % m.sourcenick
\r
103 # handle help requests for "core" topics
\r
104 def help(cmd, topic="")
\r
107 _("quit [<message>] => quit IRC with message <message>")
\r
109 _("restart => completely stop and restart the bot (including reconnect)")
\r
111 _("join <channel> [<key>] => join channel <channel> with secret key <key> if specified. #{myself} also responds to invites if you have the required access level")
\r
113 _("part <channel> => part channel <channel>")
\r
115 _("hide => part all channels")
\r
117 _("nick <nick> => attempt to change nick to <nick>")
\r
119 _("say <channel>|<nick> <message> => say <message> to <channel> or in private message to <nick>")
\r
121 _("action <channel>|<nick> <message> => does a /me <message> to <channel> or in private message to <nick>")
\r
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>")
\r
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>")
\r
127 _("version => describes software version")
\r
129 _("ping => replies with a pong")
\r
131 _("mode <channel> <mode> <nicks> => set channel modes for <nicks> on <channel> to <mode>")
\r
133 # return "botsnack => reward #{myself} for being good"
\r
135 # return "hello|hi|hey|yo [#{myself}] => greet the bot"
\r
137 _("%{name}: quit, restart, join, part, hide, save, nick, say, action, topic, quiet, talk,version, ping, mode") % {:name=>name}
\r
143 basics = BasicsModule.new
\r
145 basics.map "quit *msg",
\r
146 :action => 'bot_quit',
\r
147 :defaults => { :msg => nil },
\r
148 :auth_path => 'quit'
\r
149 basics.map "restart *msg",
\r
150 :action => 'bot_restart',
\r
151 :defaults => { :msg => nil },
\r
152 :auth_path => 'quit'
\r
154 basics.map "quiet [in] [:where]",
\r
155 :action => 'bot_quiet',
\r
156 :auth_path => 'talk::set'
\r
157 basics.map "talk [in] [:where]",
\r
158 :action => 'bot_talk',
\r
159 :auth_path => 'talk::set'
\r
161 basics.map "say :where *what",
\r
162 :action => 'bot_say',
\r
163 :auth_path => 'talk::do'
\r
164 basics.map "action :where *what",
\r
165 :action => 'bot_action',
\r
166 :auth_path => 'talk::do'
\r
167 basics.map "mode :where :what *who",
\r
168 :action => 'bot_mode',
\r
169 :auth_path => 'talk::do'
\r
171 basics.map "join :chan :pass",
\r
172 :action => 'bot_join',
\r
173 :defaults => {:pass => nil},
\r
174 :auth_path => 'move'
\r
175 basics.map "part :chan",
\r
176 :action => 'bot_part',
\r
177 :defaults => {:chan => nil},
\r
178 :auth_path => 'move'
\r
180 :action => 'bot_hide',
\r
181 :auth_path => 'move'
\r
184 :action => 'bot_ping',
\r
185 :auth_path => '!ping!'
\r
186 basics.map "help *topic",
\r
187 :action => 'bot_help',
\r
188 :defaults => { :topic => [""] },
\r
189 :auth_path => '!help!'
\r
191 basics.default_auth('*', false)
\r