+#-- vim:sw=2:et\r
+#++\r
+\r
+\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.notice m.sourcenick, "\001PING #$1\001"\r
+ @bot.irclog "@ #{m.sourcenick} pinged me"\r
+ return\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
+ 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
+ end\r
+ end\r
+\r
+ # handle help requests for "core" topics\r
+ def help(topic="")\r
+ case topic\r
+ when "quit"\r
+ return "quit [<message>] => quit IRC with message <message>"\r
+ when "restart"\r
+ return "restart => completely stop and restart the bot (including reconnect)"\r
+ when "join"\r
+ return "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
+ when "part"\r
+ return "part <channel> => part channel <channel>"\r
+ when "hide"\r
+ return "hide => part all channels"\r
+ when "save"\r
+ return "save => save current dynamic data and configuration"\r
+ when "rescan"\r
+ return "rescan => reload modules and static facts"\r
+ when "nick"\r
+ return "nick <nick> => attempt to change nick to <nick>"\r
+ when "say"\r
+ return "say <channel>|<nick> <message> => say <message> to <channel> or in private message to <nick>"\r
+ when "action"\r
+ return "action <channel>|<nick> <message> => does a /me <message> to <channel> or in private message to <nick>"\r
+ when "quiet"\r
+ return "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
+ when "talk"\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
+ 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
+ end\r
+end\r
+\r
+core = Core.new\r
+\r