+
+ 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
+
+ IPINFODB_URL = "http://api.ipinfodb.com/v2/ip_query.php?key=%{key}&ip=%{ip}"
+
+ def self.ipinfodb(ip)
+ url = IPINFODB_URL % {
+ :ip => ip,
+ :key => Irc::Utils.bot.config['geoip.ipinfodb_key']
+ }
+ debug "Requesting #{url}"
+
+ xml = Irc::Utils.bot.httputil.get(url)
+
+ 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
+
+ JUMP_TABLE = {
+ "ipinfodb" => Proc.new { |ip| ipinfodb(ip) },
+ "kapsi" => Proc.new { |ip| kapsi(ip) },
+ "geoiptool" => Proc.new { |ip| geoiptool(ip) },
+ }
+
+ def self.resolve(hostname, api)
+ raise InvalidHostError unless valid_host?(hostname)
+
+ begin
+ ip = Resolv.getaddress(hostname)
+ rescue Resolv::ResolvError
+ raise InvalidHostError
+ end
+
+ 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