summaryrefslogtreecommitdiff
path: root/data/rbot
diff options
context:
space:
mode:
authorRaine Virta <rane@kapsi.fi>2008-08-11 20:19:51 +0300
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-08-11 19:29:18 +0200
commit5604d4bfb78ff357997bcce0ee3fd010cf7d9c8d (patch)
tree204df32491760ccf93b2371e55ea03a4d859451f /data/rbot
parent9125a2e6d1ef8af8d380da3766c704f9028dec69 (diff)
geoip plugin: now stacking whois requests to prevent overlaps
Diffstat (limited to 'data/rbot')
-rwxr-xr-xdata/rbot/plugins/geoip.rb52
1 files changed, 40 insertions, 12 deletions
diff --git a/data/rbot/plugins/geoip.rb b/data/rbot/plugins/geoip.rb
index 15372a8b..0eb4eed4 100755
--- a/data/rbot/plugins/geoip.rb
+++ b/data/rbot/plugins/geoip.rb
@@ -17,7 +17,6 @@ module GeoIP
:city => %r{City:.*?<td align="left" class="arial_bold">(.*?)</td>}m
}
-
def self.resolve(hostname)
res = {}
raw = Irc::Utils.bot.httputil.get_response(GEO_IP+hostname)
@@ -29,22 +28,51 @@ module GeoIP
end
end
+class Stack
+ def initialize
+ @hash = {}
+ end
+
+ def [](nick)
+ @hash[nick] = [] unless @hash[nick]
+ @hash[nick]
+ end
+
+ def has_nick?(nick)
+ @hash.has_key?(nick)
+ end
+
+ def clear(nick)
+ @hash.delete(nick)
+ end
+end
+
class GeoIpPlugin < Plugin
def help(plugin, topic="")
"geoip [<user|hostname|ip>] => returns the geographic location of whichever has been given -- note: user can be anyone on the network"
end
+ def initialize
+ super
+
+ @stack = Stack.new
+ end
+
def whois(m)
+ nick = m.whois[:nick].downcase
+
# need to see if the whois reply was invoked by this plugin
- return unless m.whois[:nick] == @nick
+ return unless @stack.has_nick?(nick)
- if m.target
- @bot.say @source, host2output(m.target.host, m.target.nick)
- else
- @bot.say @source, "no such user on "+@bot.server.hostname.split(".")[-2]
+ @stack[nick].each do |source|
+ if m.target
+ @bot.say source, host2output(m.target.host, m.target.nick)
+ else
+ @bot.say source, "no such user on "+@bot.server.hostname.split(".")[-2]
+ end
end
- @nick, @source = nil
+ @stack.clear(m.whois[:nick])
end
def geoip(m, params)
@@ -63,16 +91,16 @@ class GeoIpPlugin < Plugin
end
# input is a host name or an IP
- if params[:input] =~ /[a-z0-9\-]+(?:\.[a-z0-9\-]+)*\.[a-z]{2,3}/i ||
+ if params[:input] =~ /[a-z0-9\-]+(?:\.[a-z0-9\-]+)*\.[a-z]{2,4}/i ||
params[:input] =~ Resolv::IPv4::Regex
m.reply host2output(params[:input])
# assume input is a nick
else
- @source = m.replyto
- @nick = params[:input]
+ nick = params[:input].downcase
- @bot.whois(@nick)
+ @stack[nick] << m.replyto
+ @bot.whois(nick)
end
end
end
@@ -106,4 +134,4 @@ class GeoIpPlugin < Plugin
end
plugin = GeoIpPlugin.new
-plugin.map "geoip [:input]", :action => 'geoip'
+plugin.map "geoip [:input]", :action => 'geoip' \ No newline at end of file