Adding and fixing basic modules for renaming, removing, and adding orgs
This commit is contained in:
@ -15,10 +15,10 @@ regchat = function(name, command_table)
|
||||
end
|
||||
|
||||
-- ===================================================================
|
||||
-- /modpol
|
||||
-- /mp
|
||||
-- Presents a menu of options to users
|
||||
regchat(
|
||||
"modpol", {
|
||||
"mp", {
|
||||
privs = {},
|
||||
func = function(user)
|
||||
modpol.interactions.dashboard(user)
|
||||
@ -26,14 +26,17 @@ regchat(
|
||||
})
|
||||
|
||||
-- ===================================================================
|
||||
-- /reset
|
||||
-- For testing only
|
||||
-- /mptest
|
||||
-- For testing only, accessible to admin users
|
||||
-- Clears the system and recreates instance with all players
|
||||
-- opens dashboard too for fun.
|
||||
regchat(
|
||||
"reset", {
|
||||
privs = {},
|
||||
"mptest", {
|
||||
privs = {privs=true},
|
||||
func = function(user)
|
||||
modpol.orgs.reset();
|
||||
modpol.orgs.reset()
|
||||
modpol.instance:add_member(user)
|
||||
modpol.interactions.dashboard(user)
|
||||
return true, "Reset orgs"
|
||||
end,
|
||||
})
|
||||
@ -71,38 +74,3 @@ regchat(
|
||||
end
|
||||
})
|
||||
|
||||
-- ===================================================================
|
||||
-- /listplayers
|
||||
regchat(
|
||||
"listplayers", {
|
||||
privs = {},
|
||||
func = function(user)
|
||||
local result = table.concat(modpol.list_users(),", ")
|
||||
return true, "All players: " .. result
|
||||
end,
|
||||
})
|
||||
|
||||
-- ===================================================================
|
||||
-- /joinorg
|
||||
regchat(
|
||||
"joinorg", {
|
||||
privs = {},
|
||||
func = function(user, param)
|
||||
local org = modpol.orgs.get_org(param)
|
||||
local success, result = org:add_member(user)
|
||||
return true, result
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
-- ===================================================================
|
||||
-- /pollself [question]
|
||||
-- asks the user a question specified in param
|
||||
regchat(
|
||||
"pollself", {
|
||||
privs = {},
|
||||
func = function(user, param)
|
||||
modpol.interactions.binary_poll_user(user, param)
|
||||
return true, result
|
||||
end,
|
||||
})
|
||||
|
@ -51,15 +51,15 @@ function modpol.interactions.dashboard(user)
|
||||
-- set up formspec
|
||||
local formspec = {
|
||||
"formspec_version[4]",
|
||||
"size[10,8]",
|
||||
"label[0.5,0.5;MODPOL DASHBOARD]",
|
||||
"size[10,6]",
|
||||
"label[0.5,0.5;M O D U L A R P O L I T I C S]",
|
||||
"label[0.5,2;All orgs:]",
|
||||
"dropdown[2,1.5;5,0.8;all_orgs;"..formspec_list(all_orgs)..";;]",
|
||||
"label[0.5,3;Your orgs:]",
|
||||
"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)..";;]",
|
||||
"button_exit[8.5,7;1,0.8;close;Close]",
|
||||
"button_exit[8.5,5;1,0.8;close;Close]",
|
||||
}
|
||||
local formspec_string = table.concat(formspec, "")
|
||||
-- present to player
|
||||
@ -85,11 +85,11 @@ end)
|
||||
|
||||
|
||||
-- Function: modpol.interactions.org_dashboard
|
||||
-- Params: user (string), org_name (string)
|
||||
-- Params: user (string), org_string (string or num)
|
||||
-- Output: Displays a menu of org-specific commands to the user
|
||||
function modpol.interactions.org_dashboard(user, org_name)
|
||||
function modpol.interactions.org_dashboard(user, org_string)
|
||||
-- prepare data
|
||||
local org = modpol.orgs.get_org(org_name)
|
||||
local org = modpol.orgs.get_org(org_string)
|
||||
if not org then return nil end
|
||||
|
||||
local function membership_toggle(org_display)
|
||||
@ -98,9 +98,8 @@ function modpol.interactions.org_dashboard(user, org_name)
|
||||
if current_org:has_member(user) then
|
||||
return " (member)"
|
||||
end
|
||||
else
|
||||
return ""
|
||||
end
|
||||
return ""
|
||||
end
|
||||
|
||||
-- identify parent
|
||||
@ -119,32 +118,36 @@ function modpol.interactions.org_dashboard(user, org_name)
|
||||
local modules = {"View..."}
|
||||
if org.modules then
|
||||
for k,v in pairs(org.modules) do
|
||||
table.insert(modules, v.slug)
|
||||
if not v.hide then -- hide utility modules
|
||||
local module_entry = v.name..
|
||||
" ["..v.slug.."]"
|
||||
table.insert(modules, module_entry)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- prepare actions menu
|
||||
local actions = {"View..."}
|
||||
local num_actions = 0
|
||||
-- prepare pending menu
|
||||
local pending = {"View..."}
|
||||
local num_pending = 0
|
||||
if org.pending[user] then
|
||||
for k,v in pairs(org.pending[user]) do
|
||||
local action_string = "[" .. k .. "] " ..
|
||||
org.processes[k].name
|
||||
table.insert(actions, action_string)
|
||||
num_actions = num_actions + 1
|
||||
local pending_string = org.processes[k].name
|
||||
.." ["..k.."]"
|
||||
table.insert(pending, pending_string)
|
||||
num_pending = num_pending + 1
|
||||
end
|
||||
end
|
||||
|
||||
-- set player context
|
||||
local user_context = {}
|
||||
user_context["current_org"] = org_name
|
||||
user_context["current_org"] = org.name
|
||||
_contexts[user] = user_context
|
||||
-- set up formspec
|
||||
local formspec = {
|
||||
"formspec_version[4]",
|
||||
"size[10,8]",
|
||||
"label[0.5,0.5;Org: "..
|
||||
minetest.formspec_escape(org_name)..membership_toggle(org_name).."]",
|
||||
minetest.formspec_escape(org.name)..membership_toggle(org.name).."]",
|
||||
"label[0.5,1;Parent: "..parent..membership_toggle(parent).."]",
|
||||
"label[0.5,2;Members:]",
|
||||
"dropdown[2,1.5;5,0.8;user_orgs;"..formspec_list(org.members)..";;]",
|
||||
@ -152,8 +155,8 @@ function modpol.interactions.org_dashboard(user, org_name)
|
||||
"dropdown[2,2.5;5,0.8;children;"..formspec_list(children)..";;]",
|
||||
"label[0.5,4;Modules:]",
|
||||
"dropdown[2,3.5;5,0.8;modules;"..formspec_list(modules)..";;]",
|
||||
"label[0.5,5;Actions ("..num_actions.."):]",
|
||||
"dropdown[2,4.5;5,0.8;actions;"..formspec_list(actions)..";;]",
|
||||
"label[0.5,5;Pending ("..num_pending.."):]",
|
||||
"dropdown[2,4.5;5,0.8;pending;"..formspec_list(pending)..";;]",
|
||||
"button[8.5,7;1,0.8;back;Back]",
|
||||
}
|
||||
local formspec_string = table.concat(formspec, "")
|
||||
@ -179,7 +182,8 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
||||
-- Receiving modules
|
||||
elseif fields.modules
|
||||
and fields.modules ~= "View..." then
|
||||
local module = fields.modules
|
||||
local module = string.match(
|
||||
fields.modules,"%[(.*)%]")
|
||||
modpol.interactions.binary_poll_user(
|
||||
pname,
|
||||
modpol.modules[module].name.."\n"..
|
||||
@ -191,12 +195,12 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
||||
end
|
||||
end)
|
||||
|
||||
-- Receiving actions
|
||||
elseif fields.actions
|
||||
and fields.actions ~= "View..." then
|
||||
local action = string.match(
|
||||
fields.actions,"%[(%d)%]")
|
||||
local process = org.processes[tonumber(action)]
|
||||
-- Receiving pending
|
||||
elseif fields.pending
|
||||
and fields.pending ~= "View..." then
|
||||
local pending = string.match(
|
||||
fields.pending,"%[(%d)%]")
|
||||
local process = org.processes[tonumber(pending)]
|
||||
if process then
|
||||
org:interact(process.id, pname)
|
||||
end
|
||||
|
Reference in New Issue
Block a user