From 7b9042eb3c5ca20ed067219da1ee6ba307cb5750 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Mon, 21 Jan 2013 02:01:26 +0000 Subject: [PATCH] Misc updates --- email.awk | 20 +++++++++--- irc.awk | 14 ++++++--- rhawk | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 111 insertions(+), 17 deletions(-) diff --git a/email.awk b/email.awk index e3080aa..f3a3b61 100644 --- 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 "" 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 880f76b..7feb953 100644 --- 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 62c1bc9..952212c 100755 --- 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) ~ /\/ { + _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 -- 2.43.2