Added minetest modules and am stuck on interactions and module flow
This commit is contained in:
49
modpol_minetest/modules/priv_to_org.lua
Normal file
49
modpol_minetest/modules/priv_to_org.lua
Normal file
@ -0,0 +1,49 @@
|
||||
--- Set privilege to org members
|
||||
-- @module priv_to_org
|
||||
-- Allows initiator to grant a priv they have to all members of an org
|
||||
|
||||
local priv_to_org = {
|
||||
name = "Set privilege to org members",
|
||||
slug = "priv_to_org",
|
||||
desc = "Allows initiator to grant a priv they have to all members of an org"
|
||||
}
|
||||
|
||||
priv_to_org.data = {
|
||||
}
|
||||
|
||||
priv_to_org.config = {
|
||||
}
|
||||
|
||||
--- (Required): initiate function
|
||||
-- Modules have access to the following instance variables:
|
||||
-- <li><code>self.org</code> (the org the module was called in),</li>
|
||||
-- <li><code>self.initiator</code> (the user that callced the module),</li>
|
||||
-- <li><code>self.id</code> (the process id of the module instance)</li>
|
||||
-- @param config (optional) If user wants to override fields in the config table
|
||||
-- @param result (optional) Callback if this module is embedded in other modules
|
||||
-- @function initiate
|
||||
function priv_to_org:initiate(config, result)
|
||||
local player_privs = minetest.get_player_privs(self.initiator)
|
||||
for i,v in ipairs(player_privs) do
|
||||
if not v then table.remove(player_privs,i) end
|
||||
end
|
||||
modpol.interactions.dropdown_query(
|
||||
self.initiator,
|
||||
"Which privilege do you want to share with members of "..self.org.name.."?",
|
||||
player_privs,
|
||||
function(input)
|
||||
for member in self.org.members do
|
||||
local member_privs = minetest.get_player_privs(member.name)
|
||||
member_privs[input] = true
|
||||
minetest.set_player_privs(member.name, member_privs)
|
||||
end
|
||||
local message = self.initiator .. " has set " .. input ..
|
||||
" privilege to all members of " .. self.org.name
|
||||
modpol.interactions.message_org(self.initiator,self.org.id, message)
|
||||
end)
|
||||
-- call result function
|
||||
if result then result() end
|
||||
end
|
||||
|
||||
--- (Required) Add to module table
|
||||
modpol.modules.priv_to_org = priv_to_org
|
@ -176,6 +176,12 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
||||
if formname == "modpol:org_dashboard" then
|
||||
local pname = player:get_player_name()
|
||||
local org = modpol.orgs.get_org(_contexts[pname].current_org)
|
||||
-- just confirm the org still exists:
|
||||
if not org then
|
||||
modpol.interactions.message(pname, "Org no longer exists")
|
||||
modpol.interactions.dashboard(pname)
|
||||
return end
|
||||
-- okay, onward
|
||||
if nil then
|
||||
elseif fields.join then
|
||||
org:add_member(pname)
|
||||
|
Reference in New Issue
Block a user