104 lines
3.1 KiB
Lua
104 lines
3.1 KiB
Lua
-- ===================================================================
|
|
-- /orgs.lua
|
|
-- User interaction functions for Modular Politics
|
|
-- Called by modpol.lua
|
|
|
|
modpol.interactions = {}
|
|
|
|
|
|
-- DASHBOARDS
|
|
-- ==========
|
|
|
|
-- Function: modpol.dashboard(user)
|
|
-- Params: user (string)
|
|
-- Q: Should this return a menu of commands relevant to the specific user?
|
|
-- Output: Displays a menu of commands to the user
|
|
-- TKTK currently just prints all of modpol---needs major improvement
|
|
function modpol.dashboard(user)
|
|
local output = ""
|
|
-- Org status
|
|
output = output .. "Orgs:\n" ..
|
|
table.concat(modpol.orgs.list_all(),"\n")
|
|
-- Command list (should be redone to be org-specific)
|
|
output = output .. "\nCommand list:\n"
|
|
for key,value in pairs(modpol) do
|
|
output = output .. "modpol." .. key .. " "
|
|
end
|
|
print(output)
|
|
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)
|
|
-- output: prints message to CLI
|
|
function modpol.interactions.message(user, message)
|
|
print(user .. ": " .. message)
|
|
end
|
|
|
|
-- ===================================================================
|
|
-- Function: modpol.interactions.text_query
|
|
-- input: Query (string)
|
|
-- output: User response (string)
|
|
function modpol.interactions.text_query(query)
|
|
-- TODO
|
|
end
|
|
|
|
-- ===================================================================
|
|
-- Function: modpol.binary_poll_user(user, question)
|
|
-- Params: user (string), question (string)
|
|
-- Output:
|
|
-- presents a yes/no/abstain poll to a user, returns answer
|
|
function modpol.interactions.binary_poll_user(user, question)
|
|
local query = "Poll for " .. user .. " (y/n): ".. question
|
|
local answer
|
|
repeat
|
|
print(query)
|
|
answer = io.read()
|
|
until answer == "y" or answer == "n" or answer == "a"
|
|
if answer == "y" then
|
|
return "Yes"
|
|
elseif answer == "n" then
|
|
return "No"
|
|
else
|
|
return "Abstain"
|
|
end
|
|
end
|