Merge branch 'request_interactions' into 'master'
Request interactions See merge request medlabboulder/modpol!22
This commit is contained in:
commit
9d81d57a54
@ -12,8 +12,5 @@ dofile (localdir .. "/orgs/requests.lua")
|
|||||||
--interactions
|
--interactions
|
||||||
dofile (localdir .. "/interactions/interactions.lua")
|
dofile (localdir .. "/interactions/interactions.lua")
|
||||||
|
|
||||||
-- messaging functions
|
|
||||||
dofile (localdir .. "/processes/processes.lua")
|
|
||||||
|
|
||||||
--modules
|
--modules
|
||||||
dofile (localdir .. "/modules/consent.lua")
|
dofile (localdir .. "/modules/consent.lua")
|
@ -5,7 +5,10 @@
|
|||||||
|
|
||||||
modpol.interactions = {}
|
modpol.interactions = {}
|
||||||
|
|
||||||
-- ===================================================================
|
|
||||||
|
-- DASHBOARDS
|
||||||
|
-- ==========
|
||||||
|
|
||||||
-- Function: modpol.dashboard(user)
|
-- Function: modpol.dashboard(user)
|
||||||
-- Params: user (string)
|
-- Params: user (string)
|
||||||
-- Q: Should this return a menu of commands relevant to the specific user?
|
-- Q: Should this return a menu of commands relevant to the specific user?
|
||||||
@ -16,8 +19,6 @@ function modpol.dashboard(user)
|
|||||||
-- Org status
|
-- Org status
|
||||||
output = output .. "Orgs:\n" ..
|
output = output .. "Orgs:\n" ..
|
||||||
table.concat(modpol.orgs.list_all(),"\n")
|
table.concat(modpol.orgs.list_all(),"\n")
|
||||||
-- Process status (ongoing processes)
|
|
||||||
output = output .. "\nProcesses:\n" .. table.concat(modpol.processes)
|
|
||||||
-- Command list (should be redone to be org-specific)
|
-- Command list (should be redone to be org-specific)
|
||||||
output = output .. "\nCommand list:\n"
|
output = output .. "\nCommand list:\n"
|
||||||
for key,value in pairs(modpol) do
|
for key,value in pairs(modpol) do
|
||||||
@ -27,6 +28,43 @@ function modpol.dashboard(user)
|
|||||||
end
|
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
|
-- Function: modpol.interactions.message
|
||||||
-- input: user (string), message (string)
|
-- input: user (string), message (string)
|
||||||
|
@ -1,106 +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.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
|
|
@ -64,8 +64,6 @@ function modpol.interactions.dashboard(user)
|
|||||||
"dropdown[2,2.5;5,0.8;user_orgs;"..formspec_list(user_orgs)..";;]",
|
"dropdown[2,2.5;5,0.8;user_orgs;"..formspec_list(user_orgs)..";;]",
|
||||||
"label[0.5,4;All users:]",
|
"label[0.5,4;All users:]",
|
||||||
"dropdown[2,3.5;5,0.8;all_users;"..formspec_list(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;;]",
|
|
||||||
"button[0.5,7;1,0.8;test_poll;Test poll]",
|
"button[0.5,7;1,0.8;test_poll;Test poll]",
|
||||||
"button[2,7;1,0.8;add_org;Add org]",
|
"button[2,7;1,0.8;add_org;Add org]",
|
||||||
"button[3.5,7;1.5,0.8;remove_org;Remove org]",
|
"button[3.5,7;1.5,0.8;remove_org;Remove org]",
|
||||||
@ -160,7 +158,13 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|||||||
local org = modpol.orgs.get_org(_contexts[pname].current_org)
|
local org = modpol.orgs.get_org(_contexts[pname].current_org)
|
||||||
if nil then
|
if nil then
|
||||||
elseif fields.join 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)
|
modpol.interactions.org_dashboard(pname,org.name)
|
||||||
elseif fields.leave then
|
elseif fields.leave then
|
||||||
org:remove_member(pname)
|
org:remove_member(pname)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user