X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=email.awk;h=7f007b5e277942c830f171521bda2ca03c99da2d;hb=4c134e54897a8a945d74b2f94ba1afdbf327a249;hp=2e0fd4daefe7667a09b830e7ea563b2e47a73022;hpb=1345cbb548dd7706957b85ef7367afdce1db62aa;p=~andy%2Frhawk diff --git a/email.awk b/email.awk index 2e0fd4d..7f007b5 100644 --- a/email.awk +++ b/email.awk @@ -1,11 +1,31 @@ +@include "json.awk" + +# Save email addresses +END { + json_save("var/mail.json", mail_enable) +} + +BEGIN { + json_load("var/mail.json", mail_enable) + for (_user in mail_enable) + debug("watching " mail_enable[_user] " for " _user) +} + +TO == NICK && /^sync/ { + json_load("var/mail.json", mail_enable) + for (_user in mail_enable) + debug("watching " mail_enable[_user] " for " _user) +} + # Email notifications BEGIN { - mail_hist = 60 # Send 60 seconds of backlog - mail_delay = 60 # Wait 60 seconds after last mention before mailing + mail_hist = 5*60 # If the users has not spoken withn mail_before before + mail_before = 5*60 # someone mentions their name and does not reply within + mail_after = 5*60 # mail_after seconds, email them hist seconds of the backlog - mail_from = NICK "" - mail_err = "If you recieved this message in error,\n" \ - "someone in #rhnoise is begin a jerk" + mail_from = NICK "" + mail_err = "If you received this message in error,\n" \ + "someone in #rhnoise is being a jerk" } function mail_send(addr, subj, body, @@ -33,7 +53,7 @@ function mail_prep(user, chan, for (si = 1; si <= sn; si++) { sec = ss[si] mn = length(mail_log[chan][sec]) - for (mi = 0; mi < mn; mi++) { + for (mi = 0; mi < mn; mi++) { msg = mail_log[chan][sec][mi] if (sec > mail_ready[user][chan] - mail_hist) { if (msg ~ user) @@ -44,7 +64,7 @@ function mail_prep(user, chan, } } } - say("notifying " user " at " addr) + say(chan, "notifying " user " at " addr) mail_send(addr, "Message for " user " in " chan, body) delete mail_ready[user][chan] } @@ -55,34 +75,64 @@ function mail_run( user, chan, ready, time) for (chan in mail_ready[user]) { ready = mail_ready[user][chan] delay = systime() - ready - if (ready && delay > mail_delay) + if (ready && delay > mail_after) mail_prep(user, chan) } } -FROM ~ OWNER && +AUTH == OWNER && +TO == NICK && /^e?mail .* .*/ { reply("notifying " $2 " for " $3) mail_enable[$3] = $2 } +TO == NICK && /^e?mail *[^ ]*$/ { - reply("notifying " $2) - mail_enable[FROM] = $2 + _user = FROM + _addr = $2 + gsub(/[^a-zA-Z0-9_+@.-]/, "", _user) + gsub(/[^a-zA-Z0-9_+@.-]/, "", _addr) + reply("notifying " _addr " for " _user) + mail_enable[_user] = _addr } +AUTH == OWNER && +TO == NICK && +/^stfu .*/ { + reply("well fine then") + delete mail_enable[$2] + delete mail_ready[$2] + delete mail_seen[$2] +} + +TO == NICK && /^stfu$/ { reply("well fine then") delete mail_enable[FROM] + delete mail_ready[FROM] + delete mail_seen[FROM] +} + +TO == NICK && +/^who/ { + for (_user in mail_enable) + reply("\"" _user "\" <" mail_enable[_user] ">") } -TO in mail_enable { - mail_ready[TO][DST] = systime() - debug("queing messages to " DST " for " TO) +DST ~ /^#.*/ { + for (_user in mail_enable) { + _idle = systime() - mail_seen[_user] + if ($0 ~ "\\<"_user"\\>" && _idle > mail_before) { + mail_ready[_user][DST] = systime() + debug("queueing messages to " DST " for " _user) + } + } } FROM in mail_enable { delete mail_ready[FROM] + mail_seen[FROM] = systime() debug("clearing message for " FROM) } @@ -91,7 +141,7 @@ DST ~ /^#.*/ { _i = length(mail_log[DST][_t]) if (_i==0) delete mail_log[DST][_t] mail_log[DST][_t][_i] = DST " " strftime("(%H:%M:%S) ") FROM ": " $0 - debug("log["DST"]["_t"]["_i"] = "mail_log[DST][_t][_i]) + #debug("log["DST"]["_t"]["_i"] = "mail_log[DST][_t][_i]) } // {