]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/core/basics.rb
Plugin header boilerplating.
[user/henk/code/ruby/rbot.git] / lib / rbot / core / basics.rb
index 8217895ef6eb061acc6be3b57d3bb5639c14d245..866f506af49e82ca569192886cd5bdb39321ca97 100644 (file)
@@ -1,15 +1,25 @@
 #-- vim:sw=2:et\r
 #++\r
-\r
+#\r
+# :title: rbot basic management from IRC\r
+#\r
+# Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>\r
+# Copyright:: (C) 2006,2007 Giuseppe Bilotta\r
+# License:: GPL v2\r
 \r
 class BasicsModule < CoreBotModule\r
 \r
   def listen(m)\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
+    if m.message =~ /^\001PING\s+(.+)\001/\r
+      ping_id = $1\r
+      if m.private?\r
+        @bot.notice m.source, "\001PING #{ping_id}\001"\r
+        @bot.irclog "@ #{m.source} pinged me"\r
+      else\r
+        @bot.notice m.source, "\001PING #{ping_id}\001"\r
+        @bot.irclog "@ #{m.source} pinged #{m.target}"\r
+      end\r
     end\r
   end\r
 \r
@@ -59,18 +69,24 @@ class BasicsModule < CoreBotModule
 \r
   def bot_quiet(m, param)\r
     if param.has_key?(:where)\r
-      @bot.set_quiet param[:where].sub(/^here$/, m.target)\r
+      @bot.set_quiet param[:where].sub(/^here$/, m.target.downcase)\r
     else\r
       @bot.set_quiet\r
     end\r
+    # Make sense when the commmand is given in private or in a non-quieted\r
+    # channel\r
+    m.okay\r
   end\r
 \r
   def bot_talk(m, param)\r
     if param.has_key?(:where)\r
-      @bot.reset_quiet param[:where].sub(/^here$/, m.target)\r
+      @bot.reset_quiet param[:where].sub(/^here$/, m.target.downcase)\r
     else\r
       @bot.reset_quiet\r
     end\r
+    # Make sense when the commmand is given in private or in a non-quieted\r
+    # channel\r
+    m.okay\r
   end\r
 \r
   def bot_help(m, param)\r
@@ -81,17 +97,12 @@ class BasicsModule < CoreBotModule
   # 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(plugin, topic="")\r
-    case topic\r
+  def help(cmd, topic="")\r
+    case cmd\r
     when "quit"\r
       return "quit [<message>] => quit IRC with message <message>"\r
     when "restart"\r
@@ -118,12 +129,14 @@ class BasicsModule < 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 "ping"\r
+      return "ping => replies with a pong"\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 "#{name}: quit, restart, 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, ping"#, botsnack, hello"\r
     end\r
   end\r
 end\r
@@ -139,18 +152,12 @@ basics.map "restart *msg",
   :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
+basics.map "quiet [in] [:where]",\r
   :action => 'bot_quiet',\r
   :auth_path => 'talk::set'\r
-basics.map "talk",\r
+basics.map "talk [in] [:where]",\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
@@ -179,7 +186,7 @@ basics.map "ping",
   :auth_path => '!ping!'\r
 basics.map "help *topic",\r
   :action => 'bot_help',\r
-  :default => { :topic => [""] },\r
+  :defaults => { :topic => [""] },\r
   :auth_path => '!help!'\r
 \r
 basics.default_auth('*', false)\r