]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
fix http usage, other tweaks
authorTom Gilbert <tom@linuxbrit.co.uk>
Thu, 10 Mar 2005 12:11:17 +0000 (12:11 +0000)
committerTom Gilbert <tom@linuxbrit.co.uk>
Thu, 10 Mar 2005 12:11:17 +0000 (12:11 +0000)
ChangeLog
TODO
rbot/ircbot.rb
rbot/keywords.rb
rbot/message.rb
rbot/plugins/google.rb
rbot/plugins/nickserv.rb
rbot/utils.rb

index ec1c8886acfdd57dc65825ee0e9feadf9c538a6e..d6506ee8d73db65d170010eb2b2c3d101a1c7416 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Wed Oct 13 16:16:31 BST 2004  Tom Gilbert <tom@linuxbrit.co.uk>
+
+  * Fix bug with quotes plugin where it gets confused and sees both a quote
+  and a keyword, both plugins are triggered by, for example "addquote foo is
+  bar"
+  * fixed this by implementing the "has_responded" flag on a message. When a
+  plugin replied to a message (or it manually sets m.replied to true), the
+  keywords plugin will honour that flag and not examine the message for
+  keywords. This flag can also be checked by listen plugins that don't want to
+  interfere with other plugin commands.
+
 Mon Oct 11 00:37:52 BST 2004  Tom Gilbert <tom@linuxbrit.co.uk>
 
   * Fixes to the NickServ plugin
diff --git a/TODO b/TODO
index 1cba66db332f8dd0da0ea886cbd8517845a4e5da..6c9bae1ff07a4b76c2972b42812eeb6c1ac5a817 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,5 +1,4 @@
 o runtime language changing
-o keyword searching
 o maybe runtime language configuration?
 o freeze/thaw factoids (make them readonly) at higher auth
 o respond to insults
index 60ed5e98bd1632dff507fe293c2eeb07fc49be43..45603963ee731b2337ea33ad39faf1bb734db458 100644 (file)
@@ -69,6 +69,9 @@ class IrcBot
   # storage (hash interface tied to a bdb file, plugins use Accessors to store
   # and restore objects in their own namespaces.)
   attr_reader :registry
+
+  # our webrick instance
+  attr_reader :http_server
   
   # create a new IrcBot with botclass +botclass+
   def initialize(botclass)
@@ -392,6 +395,7 @@ class IrcBot
     @socket.flush
     @socket.shutdown
     @registry.close
+    @http_server.shutdown
     puts "rbot quit (#{message})"
     exit 0
   end
index b8ce84fdae1ea92c5cafcbfedcfa486595970f25..7895b3990aa27920fca4dd5f0d483fc4293a6ddf 100644 (file)
@@ -350,6 +350,7 @@ module Irc
 
     # privmsg handler
     def privmsg(m)
+      return if m.replied?
       if(m.address?)
         if(!(m.message =~ /\\\?\s*$/) && m.message =~ /^(.*\S)\s*\?\s*$/)
           keyword m, $1 if(@bot.auth.allow?("keyword", m.source, m.replyto))
index 8604e1a4e3529777d78577cc41f7d31b4fc8d7c1..c217b1da0767f724f8285e8b51937390f965d5e2 100644 (file)
@@ -22,7 +22,10 @@ module Irc
     
     # contents of the message
     attr_accessor :message
-    
+
+    # has the message been replied to/handled by a plugin?
+    attr_accessor :replied
+
     # instantiate a new Message
     # bot::      associated bot class
     # source::   hostmask of the message source
@@ -35,6 +38,7 @@ module Irc
       @address = false
       @target = target
       @message = BasicUserMessage.stripcolour message
+      @replied = false
 
       # split source into consituent parts
       if source =~ /^((\S+)!(\S+))$/
@@ -56,6 +60,11 @@ module Irc
       return @address
     end
 
+    # has this message been replied to by a plugin?
+    def replied?
+      return @replied
+    end
+
     # strip mIRC colour escapes from a string
     def BasicUserMessage.stripcolour(string)
       return "" unless string
@@ -163,6 +172,7 @@ module Irc
     # in a channel, it will reply in the channel.
     def reply(string)
       @bot.say @replyto, string
+      @replied = true
     end
 
   end
index 5fa466e7d5a140cd4203029f53fe8a4a125f0397..2e9aacba683c7f87a324be6e5c4fb33c1eb67f42 100644 (file)
@@ -29,21 +29,21 @@ class GooglePlugin < Plugin
 
     http = Net::HTTP.new("www.google.com", 80, proxy_host, proxy_port)
 
-    http.start {|http|
-      begin
-        resp = http.get(query)
+    begin
+      http.start {|http|
+        resp = http.get(query)
         if resp.code == "302"
           result = resp['location']
         end
-      rescue => e
-        p e
-        if e.response && e.response['location']
-          result = e.response['location']
-        else
-          result = "error!"
-        end
+      }
+    rescue => e
+      p e
+      if e.response && e.response['location']
+        result = e.response['location']
+      else
+        result = "error!"
       end
-    }
+    end
     m.reply "#{m.params}: #{result}"
   end
 end
index 6067ec3e490d57e9730e0fe6088bf4632e7bd456..94c57e6de0e5e39d2446bf9a05cee5a6712e1af1 100644 (file)
@@ -9,7 +9,7 @@ class NickServPlugin < Plugin
     when "password"
       return "nickserv password <nick> <passwd>: remember the password for nick <nick> and use it to identify in future"
     when "register"
-      return "nickserv register [<password>]: register the current nick, choosing a random password unless <password> is supplied - current nick must not already be registered for this to work"
+      return "nickserv register [<password> [<email>]]: register the current nick, choosing a random password unless <password> is supplied - current nick must not already be registered for this to work. Also specify email if required by your services"
     when "identify"
       return "nickserv identify: identify with nickserv - shouldn't be needed - bot should identify with nickserv immediately on request - however this could be useful after splits or service disruptions, or when you just set the password for the current nick"
     when "listnicks"
@@ -44,6 +44,12 @@ class NickServPlugin < Plugin
       @bot.sendmsg "PRIVMSG", "NickServ", "REGISTER " + passwd
       @registry[@bot.nick] = passwd
       @bot.okay m.replyto
+    when (/^register\s*(\S*)\s*(.*)$/)
+      passwd = $1
+      email = $2
+      @bot.sendmsg "PRIVMSG", "NickServ", "REGISTER " + passwd + " " + email
+      @registry[@bot.nick] = passwd
+      @bot.okay m.replyto
     when (/^register\s*(.*)\s*$/)
       passwd = $1
       @bot.sendmsg "PRIVMSG", "NickServ", "REGISTER " + passwd
index 516fb4dcbf514aae07768d8fd5db87f49cf2eb63..36276e8d9813554c42bae1e635d7fb0ec3fad38c 100644 (file)
@@ -166,18 +166,18 @@ module Irc
       http.open_timeout = opentimeout
       http.read_timeout = readtimeout
 
-      http.start {|http|
-        begin
+      begin
+        http.start {|http|
           resp = http.get(query)
           if resp.code == "200"
             return resp.body
           end
-        rescue => e
-          # cheesy for now
-          $stderr.puts "Utils.http_get exception: #{e}, while trying to get #{uristr}"
-          return nil
-        end
-      }
+        }
+      rescue => e
+        # cheesy for now
+        $stderr.puts "Utils.http_get exception: #{e}, while trying to get #{uristr}"
+        return nil
+      end
     end
 
     # This is nasty-ass. I hate writing parsers.