]> Pileus Git - ~andy/rhawk/blobdiff - rhawk
Add GeoIP Lookup
[~andy/rhawk] / rhawk
diff --git a/rhawk b/rhawk
index a4535b98095724882fde4e26a38af8dd02e95c1c..f68c93f453e463b44d5aba679fccff19f47a6c4a 100755 (executable)
--- a/rhawk
+++ b/rhawk
@@ -9,7 +9,7 @@
 BEGIN {
        json_load("var/login.json",     login);
        json_load("var/nounicode.json", nounicode);
-       json_load("var/nocolor.json",   nocolors);
+       json_load("var/nocolor.json",   nocolor);
 
        OWNER = login["owner"];
 
@@ -187,6 +187,26 @@ BEGIN {
                say("no auth info for " _who)
 }
 
+# GeoIP Lookup
+function geoip(ip,  dat, cmd, line, parts) {
+       dat = "/usr/share/GeoIP/GeoIPCity.dat"
+
+       cmd = "geoiplookup -f " dat " " ip
+       cmd | getline line
+       close(cmd)
+
+       if (split(line, parts, /[:,] /) >= 9)
+               return parts[8] ","  parts[9] " -- " \
+                      parts[6] ", " parts[4] ", " parts[3] " -- " ip
+       else
+               return "not found -- " ip
+}
+
+/^\.geoip (([0-9a-zA-Z_.-]+) *)*$/ {
+       for (_i=2; _i<=NF; _i++)
+               say(geoip($_i))
+}
+
 # Fortune
 TO == NICK && /^/               { extra = ""   }
 TO == NICK && /^\.?fortune.*-o/ { extra = "-o" }
@@ -318,6 +338,11 @@ TO == NICK && DST ~ /^#/ {
        #say("Hello, " FROM)
 }
 
+/^\.nestroyeti/ {
+       say(sprintf("Temperature: %4.1f F Humidity: %2d%%",
+               rand()*20+65, rand()*20+40))
+}
+
 #DST != "#sfvlug" &&
 !(FROM in bots) &&
 CMD == "PRIVMSG" &&
@@ -400,6 +425,7 @@ FROM == "rhnoise" && load_mod {
 # Decrementer
 BEGIN {
        user_scores[0] = 1;
+       delete user_scores
 }
 
 /^\.(scores|scoreboard)$/ {
@@ -434,6 +460,11 @@ tolower($0) ~ /\<nuclear launch detected\>/ {
        }
 }
 
+# Vote relay
+DST != "#rhnoise" && /\<[a-zA-Z0-9_]{3,16}(\+\+|--)/ {
+       say("#rhnoise", "(" DST ") " FROM ": " MSG);
+}
+
 # Misc
 { fflush("") }