]> Pileus Git - ~andy/rhawk/commitdiff
Misc updates
authorAndy Spencer <andy753421@gmail.com>
Mon, 21 Jan 2013 02:01:26 +0000 (02:01 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 21 Jan 2013 02:01:26 +0000 (02:01 +0000)
email.awk
irc.awk
rhawk

index e3080aaa3c92e4bc34396b134c42623b7d287dd6..f3a3b617029c9858e427813dddf59ffe25923742 100644 (file)
--- a/email.awk
+++ b/email.awk
@@ -1,8 +1,21 @@
 @include "json.awk"
 
 # Save email addresses
-BEGIN { json_load("var/mail.txt", mail_enable) }
-END   { json_save("var/mail.txt", mail_enable) }
+END {
+       json_save("var/mail.txt", mail_enable)
+}
+
+BEGIN {
+       json_load("var/mail.txt", mail_enable)
+       for (_user in mail_enable)
+               debug("watching " mail_enable[_user] " for " _user)
+}
+
+TO == NICK && /^sync/ {
+       json_load("var/mail.txt", mail_enable)
+       for (_user in mail_enable)
+               debug("watching " mail_enable[_user] " for " _user)
+}
 
 # Email notifications
 BEGIN {
@@ -13,9 +26,6 @@ BEGIN {
        mail_from   = NICK "<andy753421@gmail.com>"
        mail_err    = "If you received this message in error,\n" \
                      "someone in #rhnoise is being a jerk"
-
-       for (_user in mail_enable)
-               debug("watching " mail_enable[_user] " for " _user)
 }
 
 function mail_send(addr, subj, body,
diff --git a/irc.awk b/irc.awk
index 880f76b2e0c0070718a677696e9d31874bc59375..7feb95319a2d8b62be40fdfe9229783e7deb0e50 100644 (file)
--- a/irc.awk
+++ b/irc.awk
@@ -101,12 +101,16 @@ function topic(chan, msg) {
 BEGIN {
        if (CHILD == "") {
                debug("Starting server");
-               status = system("awk -f rhawk -v CHILD=1 -v FIRST=1");
+               cmd = "awk -f rhawk -v CHILD=1 -v START=" systime();
+               status = system(cmd " -v FIRST=1");
                while (status)
-                       status = system("awk -f rhawk -v CHILD=1");
+                       status = system(cmd);
                exit(0);
        } else {
-               debug("Starting child: CHILD=" CHILD " FIRST=" FIRST);
+               debug("Starting child:" \
+                     " CHILD=" CHILD   \
+                     " START=" START   \
+                     " FIRST=" FIRST);
        }
 }
 
@@ -135,9 +139,9 @@ function reload() {
 
        match(MSG, /(([^ :,]*)[:,] *)?(.*)/, arr);
        TO  = arr[2]
-       $0  = TO == NICK ? arr[3] : MSG
+       $0  = TO ? arr[3] : MSG
 
-       if (CMD == "PRIVMSG" && DST == NICK && FROM)
+       if (CMD == "PRIVMSG" && DST == NICK && FROM && !TO)
                TO = DST
 
        #set()
diff --git a/rhawk b/rhawk
index 62c1bc983f2d1b9582df1d74b6cbeb6d7e28375e..952212c0c90fa8b07acb2fc3869beb3cca1bda9c 100755 (executable)
--- a/rhawk
+++ b/rhawk
@@ -2,7 +2,7 @@
 
 @include "irc.awk"
 @include "spades.awk"
-@include "email.awk"
+#@include "email.awk"
 
 # Initialization
 BEGIN {
@@ -75,9 +75,10 @@ CMD == "NICK" && FROM in bots {
 # SFV Lug
 BEGIN { pollchan = "#sfvlug" }
 (CMD == "PING"    && systime()-lastpoll > 60*60*24) ||
-(CMD == "PRIVMSG" && DST == pollchan && /^\.poll/) {
+(CMD == "PRIVMSG" && /^\.poll/) {
        if (!topics[pollchan]) {
                debug("Unknown topic for " pollchan);
+               send("TOPIC " pollchan)
                next
        }
        _curl     = "curl -s http://sfvlug.org/"
@@ -85,6 +86,7 @@ BEGIN { pollchan = "#sfvlug" }
        _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) {
+               #debug("match(" _line ", " _web_ptrn ", ..)")
                if (match(_line, _web_ptrn, _parts)) {
                        _date  = _parts[1] " " _parts[2] " " _parts[3]
                        _topic = topics[pollchan]
@@ -100,6 +102,25 @@ BEGIN { pollchan = "#sfvlug" }
        close(cmd)
 }
 
+# Uptime
+function uptime(time,  fmt) {
+       fmt = "%d:%02d:%02d:%02d"
+       fmt = "%d days %02d:%02d:%02d"
+       return sprintf(fmt,
+               time / (60*60*24),
+               time / (60*60   ) % 24,
+               time / (60      ) % 60,
+               time / (1       ) % 60)
+}
+BEGIN {
+       up_reload = systime();
+}
+/^\.uptime/ {
+       _now = systime();
+       say("uptime: " uptime(_now - START) ", " \
+           "reload: " uptime(_now - up_reload))
+}
+
 # Fortune
 TO == NICK && /^/               { extra = ""   }
 TO == NICK && /^\.?fortune.*-o/ { extra = "-o" }
@@ -121,17 +142,31 @@ FROM ~ OWNER && /^go go gadget woop/ {
                say(".delay " i " seconds; .woop " i)
 }
 
-TO == NICK && /^[Ww][Oo]+[Pp]/ {
+function woop(msg) {
        gsub(/[^Oo]/, "", $1)
        _len = length($1)
        if (_len == 2)
                _len = 10
-       _woop = "WOOP"
+       if ($2)
+               _len = $2
+       _woop = msg
        for (i=1; i<_len; i++)
-               _woop = _woop " WOOP"
+               _woop = _woop " " msg
        say(_woop)
 }
 
+TO == NICK && /^[Ww][Oo]+[Pp] *([0-9]*)/ {
+       woop("WOOP")
+}
+
+/^~WOOP *([0-9]*)/ {
+       woop("(00/")
+}
+
+/^~woop *([0-9]*)/ {
+       woop("^H^P^P^O")
+}
+
 TO == NICK && DST ~ /^#/ {
        #say("Hello, " FROM)
 }
@@ -143,14 +178,59 @@ MSG !~ /^\./ &&
 }
 
 !(FROM in bots) &&
-/^[^.](help|halp)/ {
+((TO == NICK && /(help|halp)/) ||
+ /^[^.](help|halp)/) {
        reply("Nothing can help you now..")
 }
 
-/Ho.*Ho.*Ho/ {
+/(\<[Hh][Oo]\>.*){3}/ {
        say("\00309Merry \00304Christmas!")
 }
 
+!(FROM in bots) &&
+tolower($0) ~ /\<cloud\>/ {
+       _cmd = "shuf clouds.txt"
+       _cmd | getline _cloud
+       close(_cmd)
+       say(_cloud)
+}
+
+/^headshot [Cc]hristmas/ {
+       say(".load Christmas")
+       say(".jingle")
+       say(".unload Christmas")
+}
+
+FROM == "rhnoise" && $2 == "slaps" && $3 == NICK {
+       say(".spin")
+}
+
+/^[Aa]nd now[.,]/ {
+       say("And now...");
+       say("THE LARCH");
+}
+
+# God damn commands
+FROM == "rhnoise" && load_mod {
+       say(".load " load_mod)
+       say("rhnoise: You slag!")
+}
+// {
+       load_mod = ""
+}
+(TO  ==  "rhnoise" && /^load \w+/) ||
+(DST == "#rhniose" && /^\.load [a-z]\w+/) {
+       gsub(/[^a-zA-Z0-9_]/, " ")
+       load_mod = toupper(substr($2,1,1)) substr($2,2);
+}
+
+(DST == "#rhnoise" && /^\.line /) {
+       sub(/\./, "!");
+       say($0);
+       say("scalawag: You slag!")
+}
+
+# Misc
 { fflush("") }
 
 # vim: ft=awk