-- =================================================================== -- /processes.lua -- Process-related functions for Modular Politics -- Called by modpol.lua -- =================================================================== -- modpol.processes, a high-level table of active processes -- Process table structure: -- [name]: unique name -- [org]: org -- [update_functions]: table of available update functions -- [state]: table of relevant data on the state of the function modpol.processes = {} -- =================================================================== -- Function: modpol.register_process -- Adds a process to modpol.processes -- =================================================================== -- Function: modpol.delegate_process -- Delegates a process from one org to another -- =================================================================== -- Function: modpol.begin_process -- Params: user (string), org (string), action (string) -- Outputs: Checks the org for any policies related to a given action; -- Calls the modpol.initiate.* function(org) based on policy -- Defaults to modpol.initiate.consent() modpol.begin_process = function(user, org, action) if modpol.orgs[org]["policies"] and modpol.orgs[org]["policies"][routine] then -- check user org membership is satisfied -- register process -- start the appropriate process else -- register process (or does .initiate.* do that?) modpol.initiate.consent(org) end end -- =================================================================== -- Function: modpol.update_process -- =================================================================== -- Function: modpol.end_process -- =================================================================== -- Basic decision functions -- =================================================================== -- =================================================================== -- 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 -- =================================================================== -- Function: modpol.approved -- A simple function for automatically approved processes -- Params: none -- Outputs: boolean - true modpol.approved = function() -- Check that org exists if modpol.orgs[org] == nil then return nil, "Error: Org does not exist" end return true end -- =================================================================== -- Experimental -- =================================================================== -- =================================================================== -- 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