diff options
author | Tom Gilbert <tom@linuxbrit.co.uk> | 2005-03-10 12:11:17 +0000 |
---|---|---|
committer | Tom Gilbert <tom@linuxbrit.co.uk> | 2005-03-10 12:11:17 +0000 |
commit | 787c3322e0c1acdccb457c47bea76f31c5747f52 (patch) | |
tree | 6dc7e8e1bb39907208c441994127e4d6e63da03c /rbot | |
parent | bebe7f8392f3f1750bc196cb19bd4bfbda3310b6 (diff) |
fix http usage, other tweaks
Diffstat (limited to 'rbot')
-rw-r--r-- | rbot/ircbot.rb | 4 | ||||
-rw-r--r-- | rbot/keywords.rb | 1 | ||||
-rw-r--r-- | rbot/message.rb | 12 | ||||
-rw-r--r-- | rbot/plugins/google.rb | 22 | ||||
-rw-r--r-- | rbot/plugins/nickserv.rb | 8 | ||||
-rw-r--r-- | rbot/utils.rb | 16 |
6 files changed, 42 insertions, 21 deletions
diff --git a/rbot/ircbot.rb b/rbot/ircbot.rb index 60ed5e98..45603963 100644 --- a/rbot/ircbot.rb +++ b/rbot/ircbot.rb @@ -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 diff --git a/rbot/keywords.rb b/rbot/keywords.rb index b8ce84fd..7895b399 100644 --- a/rbot/keywords.rb +++ b/rbot/keywords.rb @@ -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)) diff --git a/rbot/message.rb b/rbot/message.rb index 8604e1a4..c217b1da 100644 --- a/rbot/message.rb +++ b/rbot/message.rb @@ -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 diff --git a/rbot/plugins/google.rb b/rbot/plugins/google.rb index 5fa466e7..2e9aacba 100644 --- a/rbot/plugins/google.rb +++ b/rbot/plugins/google.rb @@ -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 diff --git a/rbot/plugins/nickserv.rb b/rbot/plugins/nickserv.rb index 6067ec3e..94c57e6d 100644 --- a/rbot/plugins/nickserv.rb +++ b/rbot/plugins/nickserv.rb @@ -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 diff --git a/rbot/utils.rb b/rbot/utils.rb index 516fb4dc..36276e8d 100644 --- a/rbot/utils.rb +++ b/rbot/utils.rb @@ -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. |