registrar

Files related to my duties as Registrar of Agora Nomic
git clone git://juanmeleiro.mat.br/registrar
Log | Files | Refs | README

activity.lua (1044B)


      1 require "lib.utils"
      2 local pprint = require "pprint"
      3 
      4 local _M = {}
      5 
      6 function _M.activate(args, players, log)
      7 	die(not players[args.name], string.format("No player %s", args.name))
      8 	local h = table.query(players[args.name].history, function (h) return h.reason == "s" end)
      9 	die(h.active, "Player is already active.")
     10 	h.active = true
     11 	h.latest = os.date("%Y-%m-%d", args.when)
     12 	die(not h, "Player is not active.")
     13 	table.insert(log, {
     14 					 what = "activation",
     15 					 who = args.name,
     16 					 when = args.when,
     17 					 where = args.m
     18 	})
     19 end
     20 
     21 function _M.deactivate(args, players, log)
     22 	die(not players[args.name], string.format("No player %s", args.name))
     23 	local h = table.query(players[args.name].history, function (h) return h.active end)
     24 	pprint.pprint(h)
     25 	die(not h, "Player is not registered.")
     26 	die(not h.active, "Player is already inactive.")
     27 	h.active = false
     28 	h.latest = os.date("%Y-%m-%d", args.when)
     29 	table.insert(log, {
     30 					 what = "deactivation",
     31 					 who = args.name,
     32 					 when = args.when,
     33 					 where = args.m
     34 	})
     35 end
     36 
     37 return _M