+
+ def self.kapsi(ip)
+ url = "http://lakka.kapsi.fi:40086/lookup.yaml?host="
+ yaml = Irc::Utils.bot.httputil.get(url+ip)
+ return YAML::load(yaml)
+ end
+
+ def self.blogama(ip)
+ url = "http://ipinfodb.com/ip_query.php?ip="
+ debug "Requesting #{url+ip}"
+
+ xml = Irc::Utils.bot.httputil.get(url+ip)
+
+ if xml
+ obj = REXML::Document.new(xml)
+ debug "Found #{obj}"
+ newobj = {
+ :country => obj.elements["Response"].elements["CountryName"].text,
+ :city => obj.elements["Response"].elements["City"].text,
+ :region => obj.elements["Response"].elements["RegionName"].text,
+ }
+ debug "Returning #{newobj}"
+ return newobj
+ else
+ raise InvalidHostError
+ end
+ end
+
+ def self.resolve(hostname, api)
+ raise InvalidHostError unless valid_host?(hostname)
+
+ begin
+ ip = Resolv.getaddress(hostname)
+ rescue Resolv::ResolvError
+ raise InvalidHostError
+ end
+
+ jump_table = {
+ "blogama" => Proc.new { |ip| blogama(ip) },
+ "kapsi" => Proc.new { |ip| kapsi(ip) },
+ "geoiptool" => Proc.new { |ip| geoiptool(ip) },
+ }
+
+ raise BadAPIError unless jump_table.key?(api)
+
+ return jump_table[api].call(ip)
+ 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