registrar

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 6831c9091b781d191d569901e08434c6c17c4c3d
parent ace201fb4ff17a4ff4c42d295cb41bb4ee0dd4e9
Author: Juan F. Meleiro <juan@juanmeleiro.mat.br>
Date:   Wed, 13 Sep 2023 10:04:04 -0300

script: Implement birthday announcement routine

Diffstat:
Dbirthdays/template | 15---------------
Alib/birthday.lua | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mregistrar | 19+++++++++++--------
Atemplates/birthday.m4 | 19+++++++++++++++++++
4 files changed, 101 insertions(+), 23 deletions(-)

diff --git a/birthdays/template b/birthdays/template @@ -1,15 +0,0 @@ -=============================================================================== -`Registrar: juan Birthday Announcement 'esyscmd(date +%Y-%m-%d | tr -d '\n') -=============================================================================== - - Let all who read henceforth know: - -DATE - - is - - PLAYER's COUNT Agoran Birthday! - - Congratulations! - -=============================================================================== diff --git a/lib/birthday.lua b/lib/birthday.lua @@ -0,0 +1,71 @@ +require "lib.utils" +pprint = require "pprint" + +local fns = { + tmp = ".tmp" +} + +function ord(num) + if (num == 1) then + return "st" + elseif (num == 2) then + return "nd" + elseif (num == 3) then + return "rd" + else + return "th" + end +end + +function announce(args, date, original) + local time = { + year = tonumber(string.sub(date, 1, 4)), + month = tonumber(string.sub(date, 6, 7)), + day = tonumber(string.sub(date, 9, 10)) + } + local monthname = os.date("%B", os.time(time)) + local dayord = ord(time.day) + local count = tostring(time.year - tonumber(string.sub(original, 1, 4))) + local countord = ord(count) + local day = tostring(time.day) + local datestring = string.format("The %s%s of %s of %d", day, dayord, monthname, time.year) + local datepad = (string.rep(" ", (80 - string.len(datestring))//2)) + + defs = { + MAILDATE = os.date("%a, %d %b %Y %T %z"), + DATE = datepad .. datestring, + PLAYER = args.name, + COUNT = count .. countord + } + + os.execute(string.format("m4 %s templates/birthday.m4 > %s", m4flags(defs), fns.tmp)) + if args.p then + os.execute(string.format("cat %s", fns.tmp)) + else + os.execute(string.format("neomutt -H %s -E", fns.tmp)) + end + os.remove(fns.tmp) +end + +function birthday(args, players, log) + if not (players[args.name]) then + die("No such player.") + end + + local original = "xxxx-xx-xx" + for _,e in ipairs(players[args.name]) do + original = math.min(original, e.registration) + end + + local this_birthday = os.date("%Y") .. "-" .. string.sub(original, 6) + local prev_birthday = tostring(tonumber(os.date("%Y")) - 1) .. "-" .. string.sub(original, 6) + local today = os.date("%Y-%m-%d") + + if (this_birthday < today) then + announce(args, this_birthday, original) + else + announce(args, prev_birthday, original) + end +end + +return birthday diff --git a/registrar b/registrar @@ -6,6 +6,7 @@ local path = require "path" require "lib.utils" registration = require "lib.registration" report = require "lib.report" +birthday = require "lib.birthday" local parser = argparse("registrar", "Manage Agora's registrar duties") parser:flag("-p", "Pretend: only show what would be done") @@ -31,10 +32,13 @@ register_cmd:argument("contact", "URL (or plain email address) to contact player register_cmd:argument("date", "Time stamp of registration (seconds after epoch)") register_cmd:option("-m", "Message ID of registration (without 'message://' prefix)") -parser:command("activate", "Activate player") -parser:command("deactivate", "Deactivate player") -parser:command("rename", "Rename player") -parser:command("readdress", "Change player's address") +local birthday_cmd = parser:command("birthday", "Announce player's birthday") +birthday_cmd:argument("name", "The name of the player") + +-- parser:command("activate", "Activate player") +-- parser:command("deactivate", "Deactivate player") +-- parser:command("rename", "Rename player") +-- parser:command("readdress", "Change player's address") -- Deserialize local fns = { @@ -124,13 +128,12 @@ elseif args.command == "weekly" then end os.remove(fns.history) -elseif args.command == "birthday" then - io.write("Birthdays not implemented. Use registrar.fish\n") - elseif args.command == "register" then registration.register(args, players, log) elseif args.command == "deregister" then - registration.deregister(args, players, log) + registration.deregister(args, players, log) +elseif args.command == "birthday" then + birthday(args, players, log) else io.write("Not implemented.") diff --git a/templates/birthday.m4 b/templates/birthday.m4 @@ -0,0 +1,19 @@ +Date: MAILDATE +From: juan <juan@juanmeleiro.mat.br> +To: <agora-official@agoranomic.org> +Subject: [Registrar] Birthday Announcement +=============================================================================== +`Registrar: juan Birthday Announcement 'esyscmd(date +%Y-%m-%d | tr -d '\n') +=============================================================================== + + Let all who read henceforth know: + +DATE + + is + + PLAYER's COUNT Agoran Birthday! + + Congratulations! + +===============================================================================