\r
class Core < CoreBotModule\r
\r
- # TODO cleanup\r
- # handle incoming IRC PRIVMSG +m+\r
def listen(m)\r
return unless m.class <= PrivMessage\r
if(m.private? && m.message =~ /^\001PING\s+(.+)\001/)\r
@bot.irclog "@ #{m.sourcenick} pinged me"\r
return\r
end\r
+ end\r
+\r
+ def bot_join(m, param)\r
+ if param[:pass]\r
+ @bot.join param[:chan], param[:pass]\r
+ else\r
+ @bot.join param[:chan]\r
+ end\r
+ end\r
+\r
+ def bot_part(m, param)\r
+ if param[:chan]\r
+ @bot.part param[:chan]\r
+ else\r
+ @bot.part m.target if m.public?\r
+ end\r
+ end\r
+\r
+ def bot_quit(m, param)\r
+ @bot.quit(param[:msg] ? param[:msg].join(" ") : nil)\r
+ end\r
+\r
+ def bot_restart(m, param)\r
+ @bot.restart(param[:msg] ? param[:msg].join(" ") : nil)\r
+ end\r
+\r
+ def bot_hide(m, param)\r
+ @bot.join 0\r
+ end\r
+\r
+ def bot_save(m, param)\r
+ @bot.save\r
+ m.okay\r
+ end\r
+\r
+ def bot_nick(m, param)\r
+ @bot.nickchg(param[:nick])\r
+ end\r
+\r
+ def bot_say(m, param)\r
+ @bot.say param[:where], param[:what].join(" ")\r
+ end\r
+\r
+ def bot_action(m, param)\r
+ @bot.action param[:where], param[:what].join(" ")\r
+ end\r
+\r
+ def bot_mode(m, param)\r
+ @bot.mode param[:where], param[:what], param[:who].join(" ")\r
+ end\r
+\r
+ def bot_ping(m, param)\r
+ m.reply "pong"\r
+ end\r
+\r
+ def bot_rescan(m, param)\r
+ m.reply "saving ..."\r
+ @bot.save\r
+ m.reply "rescanning ..."\r
+ @bot.rescan\r
+ m.reply "done. #{@plugins.status(true)}"\r
+ end\r
+\r
+ def bot_quiet(m, param)\r
+ if param.has_key?(:where)\r
+ @bot.set_quiet param[:where].sub(/^here$/, m.target)\r
+ else\r
+ @bot.set_quiet\r
+ end\r
+ end\r
\r
- if(m.address?)\r
- case m.message\r
- when (/^join\s+(\S+)\s+(\S+)$/i)\r
- @bot.join $1, $2 if(@bot.auth.allow?("join", m.source, m.replyto))\r
- when (/^join\s+(\S+)$/i)\r
- @bot.join $1 if(@bot.auth.allow?("join", m.source, m.replyto))\r
- when (/^part$/i)\r
- @bot.part m.target if(m.public? && @bot.auth.allow?("join", m.source, m.replyto))\r
- when (/^part\s+(\S+)$/i)\r
- @bot.part $1 if(@bot.auth.allow?("join", m.source, m.replyto))\r
- when (/^quit(?:\s+(.*))?$/i)\r
- @bot.quit $1 if(@bot.auth.allow?("quit", m.source, m.replyto))\r
- when (/^restart(?:\s+(.*))?$/i)\r
- @bot.restart $1 if(@bot.auth.allow?("quit", m.source, m.replyto))\r
- when (/^hide$/i)\r
- @bot.join 0 if(@bot.auth.allow?("join", m.source, m.replyto))\r
- when (/^save$/i)\r
- if(@bot.auth.allow?("config", m.source, m.replyto))\r
- @bot.save\r
- m.okay\r
- end\r
- when (/^nick\s+(\S+)$/i)\r
- @bot.nickchg($1) if(@bot.auth.allow?("nick", m.source, m.replyto))\r
- when (/^say\s+(\S+)\s+(.*)$/i)\r
- @bot.say $1, $2 if(@bot.auth.allow?("say", m.source, m.replyto))\r
- when (/^action\s+(\S+)\s+(.*)$/i)\r
- @bot.action $1, $2 if(@bot.auth.allow?("say", m.source, m.replyto))\r
- # when (/^topic\s+(\S+)\s+(.*)$/i)\r
- # topic $1, $2 if(@bot.auth.allow?("topic", m.source, m.replyto))\r
- when (/^mode\s+(\S+)\s+(\S+)\s+(.*)$/i)\r
- @bot.mode $1, $2, $3 if(@bot.auth.allow?("mode", m.source, m.replyto))\r
- when (/^ping$/i)\r
- @bot.say m.replyto, "pong"\r
- when (/^rescan$/i)\r
- if(@bot.auth.allow?("config", m.source, m.replyto))\r
- m.reply "saving ..."\r
- @bot.save\r
- m.reply "rescanning ..."\r
- @bot.rescan\r
- m.reply "done. #{@plugins.status(true)}"\r
- end\r
- when (/^quiet$/i)\r
- if(@bot.auth.allow?("talk", m.source, m.replyto))\r
- m.okay\r
- @bot.set_quiet\r
- end\r
- when (/^quiet in (\S+)$/i)\r
- where = $1\r
- if(@bot.auth.allow?("talk", m.source, m.replyto))\r
- m.okay\r
- where.gsub!(/^here$/, m.target) if m.public?\r
- @bot.set_quiet(where)\r
- end\r
- when (/^talk$/i)\r
- if(@bot.auth.allow?("talk", m.source, m.replyto))\r
- @bot.reset_quiet\r
- m.okay\r
- end\r
- when (/^talk in (\S+)$/i)\r
- where = $1\r
- if(@bot.auth.allow?("talk", m.source, m.replyto))\r
- where.gsub!(/^here$/, m.target) if m.public?\r
- @bot.reset_quiet(where)\r
- m.okay\r
- end\r
- when (/^status\??$/i)\r
- m.reply status if @bot.auth.allow?("status", m.source, m.replyto)\r
- when (/^registry stats$/i)\r
- if @bot.auth.allow?("config", m.source, m.replyto)\r
- m.reply @registry.stat.inspect\r
- end\r
- when (/^(help\s+)?config(\s+|$)/)\r
- @config.privmsg(m)\r
- when (/^(version)|(introduce yourself)$/i)\r
- @bot.say m.replyto, "I'm a v. #{$version} rubybot, (c) Tom Gilbert - http://linuxbrit.co.uk/rbot/"\r
- when (/^help(?:\s+(.*))?$/i)\r
- @bot.say m.replyto, help($1)\r
- #TODO move these to a "chatback" plugin\r
- when (/^(botsnack|ciggie)$/i)\r
- @bot.say m.replyto, @lang.get("thanks_X") % m.sourcenick if(m.public?)\r
- @bot.say m.replyto, @lang.get("thanks") if(m.private?)\r
- when (/^(hello|howdy|hola|salut|bonjour|sup|niihau|hey|hi(\W|$)|yo(\W|$)).*/i)\r
- @bot.say m.replyto, @lang.get("hello_X") % m.sourcenick if(m.public?)\r
- @bot.say m.replyto, @lang.get("hello") if(m.private?)\r
- end\r
+ def bot_talk(m, param)\r
+ if param.has_key?(:where)\r
+ @bot.reset_quiet param[:where].sub(/^here$/, m.target)\r
else\r
- # stuff to handle when not addressed\r
- case m.message\r
- when (/^\s*(hello|howdy|hola|salut|bonjour|sup|niihau|hey|hi|yo(\W|$))[\s,-.]+#{Regexp.escape(@bot.nick)}$/i)\r
- @bot.say m.replyto, @lang.get("hello_X") % m.sourcenick\r
- when (/^#{Regexp.escape(@bot.nick)}!*$/)\r
- @bot.say m.replyto, @lang.get("hello_X") % m.sourcenick\r
- else\r
- # @keywords.privmsg(m)\r
- end\r
+ @bot.reset_quiet\r
end\r
end\r
\r
+ def bot_status(m, param)\r
+ m.reply @bot.status\r
+ end\r
+\r
+ # TODO is this one of the methods that disappeared when the bot was moved\r
+ # from the single-file to the multi-file registry?\r
+ #\r
+ # def bot_reg_stat(m, param)\r
+ # m.reply @registry.stat.inspect\r
+ # end\r
+\r
+ def bot_version(m, param)\r
+ m.reply "I'm a v. #{$version} rubybot, (c) Tom Gilbert - http://linuxbrit.co.uk/rbot/"\r
+ end\r
+\r
+ def bot_help(m, param)\r
+ m.reply @bot.help(param[:topic].join(" "))\r
+ end\r
+\r
+ #TODO move these to a "chatback" plugin\r
+ # when (/^(botsnack|ciggie)$/i)\r
+ # @bot.say m.replyto, @lang.get("thanks_X") % m.sourcenick if(m.public?)\r
+ # @bot.say m.replyto, @lang.get("thanks") if(m.private?)\r
+ # when (/^(hello|howdy|hola|salut|bonjour|sup|niihau|hey|hi(\W|$)|yo(\W|$)).*/i)\r
+ # @bot.say m.replyto, @lang.get("hello_X") % m.sourcenick if(m.public?)\r
+ # @bot.say m.replyto, @lang.get("hello") if(m.private?)\r
+ # when (/^\s*(hello|howdy|hola|salut|bonjour|sup|niihau|hey|hi|yo(\W|$))[\s,-.]+#{Regexp.escape(@bot.nick)}$/i)\r
+ # @bot.say m.replyto, @lang.get("hello_X") % m.sourcenick\r
+ # when (/^#{Regexp.escape(@bot.nick)}!*$/)\r
+ # @bot.say m.replyto, @lang.get("hello_X") % m.sourcenick\r
+\r
# handle help requests for "core" topics\r
def help(topic="")\r
case topic\r
return "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
when "version"\r
return "version => describes software version"\r
- when "botsnack"\r
- return "botsnack => reward #{myself} for being good"\r
- when "hello"\r
- return "hello|hi|hey|yo [#{myself}] => greet the bot"\r
+ # when "botsnack"\r
+ # return "botsnack => reward #{myself} for being good"\r
+ # when "hello"\r
+ # return "hello|hi|hey|yo [#{myself}] => greet the bot"\r
else\r
return "Core help topics: quit, restart, config, join, part, hide, save, rescan, nick, say, action, topic, quiet, talk, version, botsnack, hello"\r
end\r
\r
core = Core.new\r
\r
+core.map "quit *msg",\r
+ :action => 'bot_quit',\r
+ :defaults => { :msg => nil },\r
+ :auth => 'core::quit::quit'\r
+core.map "restart *msg",\r
+ :action => 'bot_restart',\r
+ :defaults => { :msg => nil },\r
+ :auth => 'core::quit::restart'\r
+\r
+core.map "save",\r
+ :action => 'bot_save',\r
+ :auth => 'core::config::save'\r
+core.map "rescan",\r
+ :action => 'bot_rescan',\r
+ :auth => 'core::config::rescan'\r
+core.map "nick :nick",\r
+ :action => 'bot_nick',\r
+ :auth => 'core::config::nick'\r
+core.map "status",\r
+ :action => 'bot_status',\r
+ :auth => 'core::config::show::status'\r
+ # TODO see above\r
+ #\r
+ # core.map "registry stats",\r
+ # :action => 'bot_reg_stat',\r
+ # :auth => 'core::config::show::registry'\r
+core.map "version",\r
+ :action => 'bot_version',\r
+ :auth => 'core::config::show::version'\r
+\r
+core.map "quiet",\r
+ :action => 'bot_quiet',\r
+ :auth => 'core::talk::quiet'\r
+core.map "quiet in :chan",\r
+ :action => 'bot_quiet',\r
+ :auth => 'core::talk::quiet'\r
+core.map "talk",\r
+ :action => 'bot_talk',\r
+ :auth => 'core::talk::talk'\r
+core.map "quiet in :chan",\r
+ :action => 'bot_quiet',\r
+ :auth => 'core::talk::talk'\r
+\r
+core.map "join :chan :pass", \r
+ :action => 'bot_join',\r
+ :defaults => {:pass => nil},\r
+ :auth => 'core::movearound::join'\r
+core.map "part :chan",\r
+ :action => 'bot_part',\r
+ :defaults => {:chan => nil},\r
+ :auth => 'core::movearound::part'\r
+core.map "hide",\r
+ :action => 'bot_hide',\r
+ :auth => 'core::movearound::hide'\r
+\r
+core.map "say :where *what",\r
+ :action => 'bot_say',\r
+ :auth => 'core::talk::say'\r
+core.map "action :where *what",\r
+ :action => 'bot_action',\r
+ :auth => 'core::talk::act'\r
+core.map "mode :where :what *who",\r
+ :action => 'bot_mode',\r
+ :auth => 'core::talk::mode'\r
+\r
+core.map "ping",\r
+ :action => 'bot_ping'\r
+core.map "help *topic",\r
+ :action => 'bot_help',\r
+ :default => { :topic => [""] }\r
+\r
+# TODO the first line should probably go to the auth module?\r
+#\r
+core.default_auth('*', true)\r
+core.default_auth('core', false)\r
+core.default_auth('core::config::show', true)\r
+\r