]> Pileus Git - ~andy/rhawk/blobdiff - rhawk
Save game after flipping the table
[~andy/rhawk] / rhawk
diff --git a/rhawk b/rhawk
index 48fb2fab0e7ad3368df7bc65e5970edb10bd1e53..0bc31a3ceadaf1512ed2ac9837a26ef77773f8b9 100755 (executable)
--- a/rhawk
+++ b/rhawk
@@ -3,7 +3,9 @@
 @include "irc.awk"
 @include "json.awk"
 @include "spades.awk"
-#@include "email.awk"
+@include "email.awk"
+@include "remind.awk"
+@include "sfvlug.awk"
 
 # Initialization
 BEGIN {
@@ -26,6 +28,8 @@ BEGIN {
                join("#rhspades")
                join("#sfvlug")
        }
+
+       PROCINFO["sorted_in"] = "@ind_str_asc";
 }
 
 # Admin
@@ -97,53 +101,6 @@ CMD == "NICK" && FROM in bots {
        json_save("var/nocolor.json", nocolor);
 }
 
-# SFV Lug
-function email(to, from, subj, body, sendmail)
-{
-       from     = NICK "<andy@pileus.org>"
-       subj     = "Update sfvlug.org!"
-       body     = "The next SFVLUG meeting is TBA!"
-       sendmail = "/usr/sbin/sendmail '" to "'"
-       print "To: " to        | sendmail
-       print "From: " from    | sendmail
-       print "Subject: " subj | sendmail
-       print ""               | sendmail
-       print body             | sendmail
-       say("Topic out of date, emailing " to);
-       close(sendmail)
-}
-
-BEGIN { pollchan = "#sfvlug" }
-(CMD == "PING"    && systime()-lastpoll > 60*60*24) ||
-(CMD == "PRIVMSG" && /^\.poll/) {
-       if (!TOPICS[pollchan]) {
-               debug("Unknown topic for " pollchan);
-               send("TOPIC " pollchan)
-               next
-       }
-       _curl     = "curl -s http://sfvlug.org/"
-       _day      = "(Sun|Mon|Tue|Wed|Thu|Fri|Sat)"
-       _web_tba  = "next meeting is: TBA"
-       _web_ptrn = "next meeting.*" _day "\\w+[, ]+([A-Z]\\w+) +([0-9]+)[, ]+([0-9]+)"
-       _irc_ptrn = _day "\\w*[, ]+([A-Z]\\w+) +([0-9]+)"
-       while (_curl | getline _line) {
-               #if (match(_line, _web_tba))
-               #       email("Brian <brian@zimage.com>");
-               if (match(_line, _web_ptrn, _parts)) {
-                       _date  = _parts[1] " " _parts[2] " " _parts[3]
-                       _topic = TOPICS[pollchan]
-                       sub(_irc_ptrn, _date, _topic)
-                       if (_topic != TOPICS[pollchan])
-                               topic(pollchan, TOPICS[pollchan] = _topic)
-                       else
-                               debug("topic is already correct")
-                       break
-               }
-       }
-       lastpoll = systime()
-       close(_curl)
-}
-
 # Versin/Uptime
 function head(cmd, var) {
        cmd | getline var
@@ -160,13 +117,15 @@ function uptime(time,  fmt) {
                time / (1       ) % 60)
 }
 BEGIN {
-       up_version = head("git describe --always --dirty")
+       up_version = head("git describe --always")
+       up_dirty   = head("git describe --always --dirty")
        up_author  = head("git log -n1 --format=format:%an")
        up_message = head("git log -n1 --format=format:%s")
        up_reload  = systime();
 }
 /^\.(version|rev)/ {
-       say("version: " up_version " - " up_author " - " up_message)
+       say("version: " up_dirty " - " up_author " - " up_message)
+       say("http://pileus.org/git/?p=~andy/rhawk;h=" up_version)
 }
 /^\.uptime/ {
        _now = systime();
@@ -187,6 +146,31 @@ 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]
+       else
+               return "not found"
+}
+
+/^\.geoip (([0-9a-zA-Z_.-]+) *)*$/ {
+       for (_i=2; _i<=NF; _i++) {
+               if ($_i in USERS)
+                       say(geoip(USERS[$_i]["host"]) " -- " \
+                           $_i " -> " USERS[$_i]["host"])
+               else
+                       say(geoip($_i) " -- " $_i)
+       }
+}
+
 # Fortune
 TO == NICK && /^/               { extra = ""   }
 TO == NICK && /^\.?fortune.*-o/ { extra = "-o" }
@@ -318,6 +302,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" &&
@@ -326,12 +315,6 @@ MSG !~ /^\./ &&
        say("Awk, awk, awk! I'm a bird!")
 }
 
-!(FROM in bots) &&
-((TO == NICK && /(help|halp)/) ||
- /^[^.](help|halp)/) {
-       reply("Nothing can help you now..")
-}
-
 /(\<[Hh][Oo]\>.*){3}/ {
        say("\00309Merry \00304Christmas!")
 }
@@ -368,6 +351,14 @@ FROM == "rhnoise" && $2 == "slaps" && $3 == NICK {
        say("Springtime for Hitler and Germany!");
 }
 
+/^.drank mauchter/ {
+       if (!drank) {
+               system("sleep " 2)
+               say("\x02MD 20/20\x0f - \x02Morgen David\x0f - \x02Under an overpass\x0f - ***** (3 minutes ago)");
+       }
+       drank=1
+}
+
 # God damn commands
 FROM == "rhnoise" && load_mod {
        say(".load " load_mod)
@@ -436,10 +427,29 @@ tolower($0) ~ /\<nuclear launch detected\>/ {
 }
 
 # Vote relay
-DST != "#rhnoise" && /\<[a-zA-Z0-9_]{3,16}(\+\+|--)/ {
+DST != "#rhnoise" && DST != NICK &&
+/\<[a-zA-Z0-9_]{3,16}(\+\+|--)/ {
        say("#rhnoise", "(" DST ") " FROM ": " MSG);
 }
 
+# Fun operators
+function bang(a, b) {
+       if (a=="nan") return "nan";
+       if (b=="nan") return "nan";
+       if (a==b)     return "nan";
+       if (a==0)     return "+0";
+       if (b==0)     return "-0";
+       return 1/(1/a - 1/b);
+}
+
+/^ *[+-]?[0-9]*\.?[0-9]+( *\? *[+-]?[0-9]*\.?[0-9]+)+ *$/ {
+       gsub(/?/, " ");
+       _num = $1+0;
+       for (_i=2; _i<=NF; _i++)
+               _num = bang(_num, $_i+0);
+       reply(_num);
+}
+
 # Misc
 { fflush("") }