]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/core/core.rb
Internally rename the core botmodule to basics
[user/henk/code/ruby/rbot.git] / lib / rbot / core / core.rb
index c9210d5944c4855308b4d4e3e56ecdb2e7a70d6d..8217895ef6eb061acc6be3b57d3bb5639c14d245 100644 (file)
 #++\r
 \r
 \r
-class Core < CoreBotModule\r
+class BasicsModule < CoreBotModule\r
 \r
-  # TODO cleanup\r
-  # handle incoming IRC PRIVMSG +m+\r
   def listen(m)\r
-    return unless m.class <= PrivMessage\r
+    return unless m.kind_of?(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
+  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_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_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_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
+  def help(plugin, topic="")\r
     case topic\r
     when "quit"\r
       return "quit [<message>] => quit IRC with message <message>"\r
@@ -141,15 +118,69 @@ class Core < CoreBotModule
       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
+      return "#{name}: quit, restart, 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
+basics = BasicsModule.new\r
+\r
+basics.map "quit *msg",\r
+  :action => 'bot_quit',\r
+  :defaults => { :msg => nil },\r
+  :auth_path => 'quit'\r
+basics.map "restart *msg",\r
+  :action => 'bot_restart',\r
+  :defaults => { :msg => nil },\r
+  :auth_path => 'quit'\r
+\r
+basics.map "quiet",\r
+  :action => 'bot_quiet',\r
+  :auth_path => 'talk::set'\r
+basics.map "quiet in :chan",\r
+  :action => 'bot_quiet',\r
+  :auth_path => 'talk::set'\r
+basics.map "talk",\r
+  :action => 'bot_talk',\r
+  :auth_path => 'talk::set'\r
+basics.map "quiet in :chan",\r
+  :action => 'bot_quiet',\r
+  :auth_path => 'talk::set'\r
+\r
+basics.map "say :where *what",\r
+  :action => 'bot_say',\r
+  :auth_path => 'talk::do'\r
+basics.map "action :where *what",\r
+  :action => 'bot_action',\r
+  :auth_path => 'talk::do'\r
+basics.map "mode :where :what *who",\r
+  :action => 'bot_mode',\r
+  :auth_path => 'talk::do'\r
+\r
+basics.map "join :chan :pass", \r
+  :action => 'bot_join',\r
+  :defaults => {:pass => nil},\r
+  :auth_path => 'move'\r
+basics.map "part :chan",\r
+  :action => 'bot_part',\r
+  :defaults => {:chan => nil},\r
+  :auth_path => 'move'\r
+basics.map "hide",\r
+  :action => 'bot_hide',\r
+  :auth_path => 'move'\r
+\r
+basics.map "ping",\r
+  :action => 'bot_ping',\r
+  :auth_path => '!ping!'\r
+basics.map "help *topic",\r
+  :action => 'bot_help',\r
+  :default => { :topic => [""] },\r
+  :auth_path => '!help!'\r
+\r
+basics.default_auth('*', false)\r
 \r