Created processes.lua with consent, initiate functions

This commit is contained in:
Nathan Schneider 2021-01-31 22:47:28 -07:00
parent c927b4d9fc
commit a3fb83fbfa
4 changed files with 59 additions and 5 deletions

View File

@ -13,7 +13,7 @@ modpol.binary_poll_user = function(user, question)
local answer
repeat
print(query)
answer= io.read()
answer = io.read()
until answer == "y" or answer == "n" or answer == "a"
if answer == "y" then
return "Yes"

View File

@ -9,7 +9,7 @@
modpol = {
}
-- Table for all active governance data
-- Table for modpol data
modpol.orgs = {
}
@ -62,6 +62,7 @@ dofile (topdir .. "/users.lua")
dofile (topdir .. "/orgs.lua")
dofile (topdir .. "/interactions.lua")
-- messaging functions
dofile (topdir .. "/processes.lua")
-- ===================================================================
-- Final checks

View File

@ -7,10 +7,8 @@
-- Function: modpol.record
-- Params: strings msg, org
-- Outputs:
--
-- "msg" specifies an event and/or status message.
-- "org" specifies an "org" name.
--
-- This function adds the message to a global ledger and, if "org"
-- specifies a valid "org", to an "org"-specific ledger. Both the mem-
-- ory-resident and on-disk copies of the data structures used are up-
@ -103,7 +101,7 @@ end
-- returns confirmation message
modpol.reset_orgs = function()
local users = list_users()
local users = modpol.list_users()
modpol.orgs = {}
local message = "Orgs purged"
modpol.record(nil, message)

55
processes.lua Normal file
View File

@ -0,0 +1,55 @@
-- ===================================================================
-- /prcesses.lua
-- Process-related functions for Modular Politics
-- Called by modpol.lua
-- TKTK may need to create high-level modpol.processes table to hold ongoing processes
-- TKTK in order to enable async processes. Rewrite all this as listeners
-- ===================================================================
-- Function: modpol.consent
-- Params: org (string), proposal (string)
-- Outputs: boolean - true if consent achieved or false; nil on error
-- Also includes a table of responses
-- This is the default decision-making routine for Modular Politics
-- Stops at the first "No" vote
modpol.consent = function(org, query)
-- Check that org exists
if modpol.orgs[org] == nil then
return nil, "Error: Org does not exist"
end
-- Poll all members
local responses = {}
for index, value in ipairs(modpol.orgs[org]["members"]) do
local response = modpol.binary_poll_user(value, query)
responses[value] = response
if response == "No" then
return false, responses
end
end
return true, responses
end
-- TKTK exploring modpol.initiate functions, which have no args
-- Need to properly document these
modpol.initiate = {}
modpol.initiate.consent = function(org)
print("What is your query?")
local query = io.read()
return modpol.consent(org, query)
end
-- Function: modpol.switchboard
-- Params: org (string), routine (string)
-- Outputs: Checks the org for any policies related to a given function;
-- Calls the modpol.initiate.* function(org) based on policy
-- Defaults to modpol.initiate.consent()
modpol.switchboard = function(org, routine)
if modpol.orgs[org]["policies"]
and modpol.orgs[org]["policies"][routine] then
-- TKTK if there exists a policy
else
modpol.initiate.consent(org)
end
end