From 48b5b3070ba48bc3cd3c967e954cc4e7c0b40885 Mon Sep 17 00:00:00 2001 From: Nathan Schneider Date: Mon, 10 May 2021 23:24:52 -0600 Subject: [PATCH 1/5] Added list_processes and began adding process logic to Join button in interactions --- modpol/processes/processes.lua | 15 +++++++++++++++ .../overrides/interactions/interactions.lua | 11 +++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/modpol/processes/processes.lua b/modpol/processes/processes.lua index 8a6c699..77303de 100644 --- a/modpol/processes/processes.lua +++ b/modpol/processes/processes.lua @@ -13,6 +13,21 @@ modpol.processes = {} + +-- Function: modpol.list_processes +-- output: a table of the names of processes +function modpol.list_processes() + local output = {} + if modpol.processes then + for k,v in ipairs(modpol.processes) do + if v.name then + table.insert(output,v.name) + end + end + end + return output +end + -- =================================================================== -- Function: modpol.register_process -- Adds a process to modpol.processes diff --git a/modpol_minetest/overrides/interactions/interactions.lua b/modpol_minetest/overrides/interactions/interactions.lua index 30ec7f0..19ecc5f 100644 --- a/modpol_minetest/overrides/interactions/interactions.lua +++ b/modpol_minetest/overrides/interactions/interactions.lua @@ -53,6 +53,7 @@ function modpol.interactions.dashboard(user) local all_orgs = modpol.orgs.list_all() local user_orgs = modpol.orgs.user_orgs(user) local all_users = modpol.list_users() + local all_processes = modpol.list_processes() -- set up formspec local formspec = { "formspec_version[4]", @@ -65,7 +66,7 @@ function modpol.interactions.dashboard(user) "label[0.5,4;All users:]", "dropdown[2,3.5;5,0.8;all_users;"..formspec_list(all_users)..";;]", "label[0.5,5;Processes:]", - "dropdown[2,4.5;5,0.8;processes;TBA;;]", + "dropdown[2,4.5;5,0.8;processes;"..formspec_list(all_processess)..";;]", "button[0.5,7;1,0.8;test_poll;Test poll]", "button[2,7;1,0.8;add_org;Add org]", "button[3.5,7;1.5,0.8;remove_org;Remove org]", @@ -160,7 +161,13 @@ minetest.register_on_player_receive_fields(function (player, formname, fields) local org = modpol.orgs.get_org(_contexts[pname].current_org) if nil then elseif fields.join then - org:add_member(pname) + local new_request = { + user = player, + type = "add_member", + params = {player} + } + org:make_request(new_request) + --org:add_member(pname) modpol.interactions.org_dashboard(pname,org.name) elseif fields.leave then org:remove_member(pname) From 2432633d556e0fbc98687164bee3a3800b9a6c85 Mon Sep 17 00:00:00 2001 From: Nathan Schneider Date: Tue, 11 May 2021 16:30:55 -0600 Subject: [PATCH 2/5] Added org_dashboard to CLI interactions --- modpol/interactions/interactions.lua | 44 ++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/modpol/interactions/interactions.lua b/modpol/interactions/interactions.lua index 4eb9c26..18d474f 100644 --- a/modpol/interactions/interactions.lua +++ b/modpol/interactions/interactions.lua @@ -5,7 +5,10 @@ modpol.interactions = {} --- =================================================================== + +-- DASHBOARDS +-- ========== + -- Function: modpol.dashboard(user) -- Params: user (string) -- Q: Should this return a menu of commands relevant to the specific user? @@ -17,7 +20,7 @@ function modpol.dashboard(user) output = output .. "Orgs:\n" .. table.concat(modpol.orgs.list_all(),"\n") -- Process status (ongoing processes) - output = output .. "\nProcesses:\n" .. table.concat(modpol.processes) + output = output .. "\nProcesses:\n" .. table.concat(modpol.list_processes(),"\n") -- Command list (should be redone to be org-specific) output = output .. "\nCommand list:\n" for key,value in pairs(modpol) do @@ -27,6 +30,43 @@ function modpol.dashboard(user) end +-- Function: modpol.interactions.org_dashboard +-- Params: user (string), org_name (string) +-- Output: Displays a menu of org-specific commands to the user +function modpol.interactions.org_dashboard(user, org_name) + local org = modpol.orgs.get_org(org_name) + if not org then return nil end + local is_member = org:has_member(user) + local membership_toggle = function() + local toggle_code = "" + if is_member then + toggle_code = "[Leave]" + else + toggle_code = "[Join]" + end + return toggle_code + end + local children = {} + for k,v in ipairs(org.children) do + local this_child = modpol.orgs.get_org(v) + table.insert(children, this_child.name) + end + -- set up output + local dashboard_table = { + "Org: " .. org_name, + membership_toggle(), + "Members: " .. table.concat(org.members, ", "), + "Children: " .. table.concat(children, ", "), + "Policies: " .. table.concat(org.policies, ", "), + "Processes: " .. table.concat(org.processes, ", "), + "[Add child]", + "[Remove org]", + "[Dashboard: modpol.dashboard()]" + } + -- present to player + print(table.concat(dashboard_table, "\n")) +end + -- =================================================================== -- Function: modpol.interactions.message -- input: user (string), message (string) From fe26d5322dec292122e32e9877ad4994305baa62 Mon Sep 17 00:00:00 2001 From: Nathan Schneider Date: Thu, 13 May 2021 00:41:31 -0600 Subject: [PATCH 3/5] Removed old modpol/processes/ directory; processes now in modpol/orgs --- modpol/processes/processes.lua | 121 --------------------------------- 1 file changed, 121 deletions(-) delete mode 100644 modpol/processes/processes.lua diff --git a/modpol/processes/processes.lua b/modpol/processes/processes.lua deleted file mode 100644 index 77303de..0000000 --- a/modpol/processes/processes.lua +++ /dev/null @@ -1,121 +0,0 @@ --- =================================================================== --- /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.list_processes --- output: a table of the names of processes -function modpol.list_processes() - local output = {} - if modpol.processes then - for k,v in ipairs(modpol.processes) do - if v.name then - table.insert(output,v.name) - end - end - end - return output -end - --- =================================================================== --- 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 From c1475e903589f432b685e97b98f81c2422fe9a50 Mon Sep 17 00:00:00 2001 From: Nathan Schneider Date: Thu, 13 May 2021 00:46:37 -0600 Subject: [PATCH 4/5] Removed processes from main dashboards; processes are now org-based --- modpol/interactions/interactions.lua | 2 -- modpol_minetest/overrides/interactions/interactions.lua | 3 --- 2 files changed, 5 deletions(-) diff --git a/modpol/interactions/interactions.lua b/modpol/interactions/interactions.lua index 18d474f..e6ba855 100644 --- a/modpol/interactions/interactions.lua +++ b/modpol/interactions/interactions.lua @@ -19,8 +19,6 @@ function modpol.dashboard(user) -- Org status output = output .. "Orgs:\n" .. table.concat(modpol.orgs.list_all(),"\n") - -- Process status (ongoing processes) - output = output .. "\nProcesses:\n" .. table.concat(modpol.list_processes(),"\n") -- Command list (should be redone to be org-specific) output = output .. "\nCommand list:\n" for key,value in pairs(modpol) do diff --git a/modpol_minetest/overrides/interactions/interactions.lua b/modpol_minetest/overrides/interactions/interactions.lua index 19ecc5f..58316b2 100644 --- a/modpol_minetest/overrides/interactions/interactions.lua +++ b/modpol_minetest/overrides/interactions/interactions.lua @@ -53,7 +53,6 @@ function modpol.interactions.dashboard(user) local all_orgs = modpol.orgs.list_all() local user_orgs = modpol.orgs.user_orgs(user) local all_users = modpol.list_users() - local all_processes = modpol.list_processes() -- set up formspec local formspec = { "formspec_version[4]", @@ -65,8 +64,6 @@ function modpol.interactions.dashboard(user) "dropdown[2,2.5;5,0.8;user_orgs;"..formspec_list(user_orgs)..";;]", "label[0.5,4;All users:]", "dropdown[2,3.5;5,0.8;all_users;"..formspec_list(all_users)..";;]", - "label[0.5,5;Processes:]", - "dropdown[2,4.5;5,0.8;processes;"..formspec_list(all_processess)..";;]", "button[0.5,7;1,0.8;test_poll;Test poll]", "button[2,7;1,0.8;add_org;Add org]", "button[3.5,7;1.5,0.8;remove_org;Remove org]", From 85f8ec14f886c66ae488af6f242b72f44caba1de Mon Sep 17 00:00:00 2001 From: Nathan Schneider Date: Mon, 17 May 2021 22:27:19 -0600 Subject: [PATCH 5/5] Removed old processes.lua file from modpol/api.lua --- modpol/api.lua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/modpol/api.lua b/modpol/api.lua index cae289f..9565302 100644 --- a/modpol/api.lua +++ b/modpol/api.lua @@ -12,8 +12,5 @@ dofile (localdir .. "/orgs/requests.lua") --interactions dofile (localdir .. "/interactions/interactions.lua") --- messaging functions -dofile (localdir .. "/processes/processes.lua") - --modules -dofile (localdir .. "/modules/consent.lua") \ No newline at end of file +dofile (localdir .. "/modules/consent.lua")