From: Andy Spencer Date: Sat, 25 Oct 2014 05:23:05 +0000 (+0000) Subject: Update and re-enable email X-Git-Url: http://pileus.org/git/?p=~andy%2Frhawk;a=commitdiff_plain;h=3c3c400eb65785a84b03e21bc01f690078882fc8 Update and re-enable email --- diff --git a/email.awk b/email.awk index 7f007b5..fbcf7db 100644 --- a/email.awk +++ b/email.awk @@ -1,10 +1,6 @@ @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) @@ -23,7 +19,7 @@ BEGIN { 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_from = NICK "<" NICK "@pileus.org>" mail_err = "If you received this message in error,\n" \ "someone in #rhnoise is being a jerk" } @@ -80,46 +76,70 @@ function mail_run( user, chan, ready, time) } } +function mail_save(file) +{ + json_save(file, mail_enable) +} + +# Help +/^\.help$/ { + say(".help mail -- manage email subscriptions") +} + +/^\.help e?mail$/ { + say("Mail -- email users when they are mentioned") + say(".subscribe [addr] -- set your mailing address to [addr]") + say(".unsubscribe [addr] -- remove your subscription") + say(".addresses -- show your subscription address") + next +} + +# Commands AUTH == OWNER && TO == NICK && -/^e?mail .* .*/ { +/^subscribe .* .*/ { reply("notifying " $2 " for " $3) mail_enable[$3] = $2 + mail_save("var/mail.json") } TO == NICK && -/^e?mail *[^ ]*$/ { +/^subscribe *[^ ]*$/ { _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 + mail_save("var/mail.json") } AUTH == OWNER && TO == NICK && -/^stfu .*/ { +/^unsubscribe .*/ { reply("well fine then") delete mail_enable[$2] delete mail_ready[$2] delete mail_seen[$2] + mail_save("var/mail.json") } TO == NICK && -/^stfu$/ { +/^unsubscribe$/ { reply("well fine then") delete mail_enable[FROM] delete mail_ready[FROM] delete mail_seen[FROM] + mail_save("var/mail.json") } TO == NICK && -/^who/ { +/^addresses/ { for (_user in mail_enable) reply("\"" _user "\" <" mail_enable[_user] ">") } +# Message logging and monitoring DST ~ /^#.*/ { for (_user in mail_enable) { _idle = systime() - mail_seen[_user] diff --git a/rhawk b/rhawk index 1f9b013..724ff93 100755 --- a/rhawk +++ b/rhawk @@ -3,7 +3,7 @@ @include "irc.awk" @include "json.awk" @include "spades.awk" -#@include "email.awk" +@include "email.awk" # Initialization BEGIN {