]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/geoip.rb
geoip: make the GeoIP module a standalone
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / geoip.rb
index 55fddcc9992ea59a7e80f65be9ea4eeb0e3c5f8d..615511728df524469571276977a16965ac1579f7 100755 (executable)
@@ -9,7 +9,7 @@
 #
 # Resolves the geographic locations of users (network-wide) and IP addresses
 
-module GeoIP
+module ::GeoIP
   class InvalidHostError < RuntimeError; end
 
   GEO_IP_PRIMARY   = "http://lakka.kapsi.fi:40086/lookup.yaml?host="
@@ -19,7 +19,9 @@ module GeoIP
   REGEX  = {
     :country => %r{Country:.*?<a href=".*?" target="_blank"> (.*?)</a>}m,
     :region  => %r{Region:.*?<a href=".*?" target="_blank">(.*?)</a>}m,
-    :city    => %r{City:.*?<td align="left" class="arial_bold">(.*?)</td>}m
+    :city    => %r{City:.*?<td align="left" class="arial_bold">(.*?)</td>}m,
+    :lat     => %r{Latitude:.*?<td align="left" class="arial_bold">(.*?)</td>}m,
+    :lon     => %r{Longitude:.*?<td align="left" class="arial_bold">(.*?)</td>}m
   }
 
   def self.valid_host?(hostname)
@@ -82,12 +84,13 @@ class GeoIpPlugin < Plugin
     # need to see if the whois reply was invoked by this plugin
     return unless @stack.has_nick?(nick)
 
+    if m.target
+      msg = host2output(m.target.host, m.target.nick)
+    else
+      msg = "no such user on "+@bot.server.hostname.split(".")[-2]
+    end
     @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
+      @bot.say source, msg
     end
 
     @stack.clear(nick)