commit 5d45185c18b03296730722a49ca46ab4cd452a0f
parent 4930be1b54a4c091527fe0a4c9f9847845261970
Author: Juan F. Meleiro <juan@juanmeleiro.mat.br>
Date: Mon, 18 Sep 2023 15:54:24 -0300
script: Add activation and deactivation commands
Diffstat:
2 files changed, 60 insertions(+), 6 deletions(-)
diff --git a/lib/activity.lua b/lib/activity.lua
@@ -0,0 +1,39 @@
+require "lib.utils"
+local pprint = require "pprint"
+
+local _M = {}
+
+function _M.activate(args, players, log)
+ die(not players[args.name], string.format("No player %s", args.name))
+ local h = table.query(players[args.name], function (h) return h.reason == "s" end)
+ pprint.pprint(h)
+ die(h.active, "Player is already active.")
+ h.active = true
+ h.latest = os.date("%Y-%m-%d", args.when)
+ die(not h, "Player is not active.")
+ table.insert(log, {
+ what = "activation",
+ who = args.name,
+ when = args.when,
+ where = args.where
+ })
+end
+
+function _M.deactivate(args, players, log)
+ die(not players[args.name], string.format("No player %s", args.name))
+ local h = table.query(players[args.name], function (h) return h.active end)
+ pprint.pprint(h)
+ die(not h, "Player is not registered.")
+ die(not h.active, "Player is already inactive.")
+ h.active = false
+ h.latest = os.date("%Y-%m-%d", args.when)
+ pprint.pprint(h)
+ table.insert(log, {
+ what = "deactivation",
+ who = args.name,
+ when = args.when,
+ where = args.where
+ })
+end
+
+return _M
diff --git a/registrar b/registrar
@@ -4,9 +4,10 @@ local json = require "json"
local path = require "path"
require "lib.utils"
-registration = require "lib.registration"
-report = require "lib.report"
-birthday = require "lib.birthday"
+local registration = require "lib.registration"
+local report = require "lib.report"
+local birthday = require "lib.birthday"
+local activity = require "lib.activity"
local parser = argparse("registrar", "Manage Agora's registrar duties")
parser:flag("-p", "Pretend: only show what would be done")
@@ -35,8 +36,18 @@ register_cmd:option("-m", "Message ID of registration (without 'message://' pref
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")
+local activate_cmd = parser:command("activate", "Activate player")
+activate_cmd:argument("name", "The name of the player")
+activate_cmd:argument("when", "When they were activated (seconds after epoch)")
+ :convert(tonumber)
+activate_cmd:option("-m", "Message ID of activation (without 'message://' prefix)")
+
+local deactivate_cmd = parser:command("deactivate", "Deactivate player")
+deactivate_cmd:argument("name", "The name of the player")
+deactivate_cmd:argument("when", "When they were deactivated (seconds after epoch)")
+ :convert(tonumber)
+deactivate_cmd:option("-m", "Message ID of deactivation (without 'message://' prefix)")
+
-- parser:command("rename", "Rename player")
-- parser:command("readdress", "Change player's address")
@@ -134,9 +145,13 @@ elseif args.command == "deregister" then
registration.deregister(args, players, log)
elseif args.command == "birthday" then
birthday(args, players, log)
+elseif args.command == "activate" then
+ activity.activate(args, players, log)
+elseif args.command == "deactivate" then
+ activity.deactivate(args, players, log)
+ pprint.pprint(players["juan"][1])
else
io.write("Not implemented.")
-
end
-- Serialize