X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=email.awk;h=7f007b5e277942c830f171521bda2ca03c99da2d;hb=511a9c15b13339cc6005e1dbb7b4bb0282356efc;hp=5aab62f820acba519360be5dbf695c544a6f6e8f;hpb=baadfbfb57edd0aac28fcf3e77b198cf696e3ce4;p=~andy%2Frhawk diff --git a/email.awk b/email.awk index 5aab62f..7f007b5 100644 --- a/email.awk +++ b/email.awk @@ -1,22 +1,33 @@ @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.json", mail_enable) +} -# Email notifications BEGIN { - mail_hist = 60 # Send 60 seconds of backlog - mail_delay = 60 # Wait 60 seconds after last mention before mailing - - mail_from = NICK "" - mail_err = "If you received this message in error,\n" \ - "someone in #rhnoise is being a jerk" + json_load("var/mail.json", mail_enable) + for (_user in mail_enable) + debug("watching " mail_enable[_user] " for " _user) +} - for (_user in mail_enable) +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 = 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 received this message in error,\n" \ + "someone in #rhnoise is being a jerk" +} + function mail_send(addr, subj, body, sendmail, errmsg) { @@ -42,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) @@ -53,7 +64,7 @@ function mail_prep(user, chan, } } } - privmsg(chan, "notifying " user " at " addr) + say(chan, "notifying " user " at " addr) mail_send(addr, "Message for " user " in " chan, body) delete mail_ready[user][chan] } @@ -64,12 +75,12 @@ 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) @@ -86,12 +97,13 @@ TO == NICK && mail_enable[_user] = _addr } -FROM ~ OWNER && +AUTH == OWNER && TO == NICK && /^stfu .*/ { reply("well fine then") delete mail_enable[$2] delete mail_ready[$2] + delete mail_seen[$2] } TO == NICK && @@ -99,6 +111,7 @@ TO == NICK && reply("well fine then") delete mail_enable[FROM] delete mail_ready[FROM] + delete mail_seen[FROM] } TO == NICK && @@ -108,15 +121,18 @@ TO == NICK && } DST ~ /^#.*/ { - for (_user in mail_enable) - if ($0 ~ "\\<"_user"\\>") { + 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) }