A bunch of module bugfixes
This commit is contained in:
parent
af6e639e27
commit
e994061f38
@ -228,11 +228,11 @@ end
|
|||||||
-- ====================
|
-- ====================
|
||||||
|
|
||||||
-- Function: modpol.interactions.message_org
|
-- Function: modpol.interactions.message_org
|
||||||
-- input: initiator (string), org_id (number), message (string)
|
-- input: initiator (string), org (number or string), message (string)
|
||||||
-- output: broadcasts message to all org members
|
-- output: broadcasts message to all org members
|
||||||
function modpol.interactions.message_org(initiator, org_id, message)
|
function modpol.interactions.message_org(initiator, org, message)
|
||||||
local org = modpol.orgs.get_org(org_id)
|
local this_org = modpol.orgs.get_org(org)
|
||||||
local users = org:list_members()
|
local users = this_org:list_members()
|
||||||
for k,v in ipairs(users) do
|
for k,v in ipairs(users) do
|
||||||
modpol.interactions.message(v, message)
|
modpol.interactions.message(v, message)
|
||||||
end
|
end
|
||||||
|
@ -15,12 +15,6 @@ add_child_org.config = {
|
|||||||
|
|
||||||
-- @function initiate
|
-- @function initiate
|
||||||
function add_child_org:initiate(config, result)
|
function add_child_org:initiate(config, result)
|
||||||
self.org:add_pending_action(
|
|
||||||
self.id, self.initiator,
|
|
||||||
"name_child_org")
|
|
||||||
end
|
|
||||||
|
|
||||||
function add_child_org:name_child_org()
|
|
||||||
modpol.interactions.text_query(
|
modpol.interactions.text_query(
|
||||||
self.initiator,"Child org name: ",
|
self.initiator,"Child org name: ",
|
||||||
function(input)
|
function(input)
|
||||||
@ -28,34 +22,38 @@ function add_child_org:name_child_org()
|
|||||||
modpol.interactions.message(
|
modpol.interactions.message(
|
||||||
self.initiator,
|
self.initiator,
|
||||||
"No name entered for child org")
|
"No name entered for child org")
|
||||||
self.org:wipe_pending_actions(self.id)
|
self.org:delete_process(self.id)
|
||||||
return end
|
return end
|
||||||
self.data.child_name = input
|
self.data.child_name = input
|
||||||
modpol.interactions.message(
|
modpol.interactions.message(
|
||||||
self.initiator,
|
self.initiator,
|
||||||
"Proposed child org: " .. input)
|
"Proposed child org: " .. input)
|
||||||
self.org:wipe_pending_actions(self.id)
|
-- initiate consent process
|
||||||
self:propose_child_org()
|
self.org:call_module(
|
||||||
|
"consent",
|
||||||
|
self.initiator,
|
||||||
|
{
|
||||||
|
prompt = "Create child org " ..
|
||||||
|
self.data.child_name .. "?",
|
||||||
|
votes_required = #self.org.members
|
||||||
|
},
|
||||||
|
function()
|
||||||
|
self:create_child_org()
|
||||||
|
end
|
||||||
|
)
|
||||||
|
modpol.interactions.org_dashboard(
|
||||||
|
self.initiator, self.org.name)
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
function add_child_org:propose_child_org()
|
function add_child_org:create_child_org()
|
||||||
self.org:call_module(
|
self.org:add_org(self.data.child_name, self.initiator)
|
||||||
"consent",
|
modpol.interactions.message_org(
|
||||||
self.initiator,
|
self.initiator,
|
||||||
{
|
self.org.name,
|
||||||
prompt = "Create child org " .. self.data.child_name .. "?",
|
"Child org created: "..self.data.child_name)
|
||||||
votes_required = #self.org.members
|
self.org:delete_process(self.id)
|
||||||
},
|
|
||||||
function()
|
|
||||||
self.org:add_org(self.data.child_name, self.initiator)
|
|
||||||
modpol.interactions.message_org(
|
|
||||||
self.initiator,
|
|
||||||
self.org.id,
|
|
||||||
"Child org created: "..self.data.child_name)
|
|
||||||
end
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- (Required) Add to module table
|
--- (Required) Add to module table
|
||||||
|
@ -8,7 +8,7 @@ local consent = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
consent.data = {
|
consent.data = {
|
||||||
votes = 0
|
votes = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
consent.config = {
|
consent.config = {
|
||||||
@ -16,11 +16,12 @@ consent.config = {
|
|||||||
votes_required = 1
|
votes_required = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
function consent:initiate(config, result)
|
function consent:initiate(result)
|
||||||
self.result = result
|
self.data.result = result
|
||||||
-- if org is empty, consent is given automatically
|
-- if org is empty, consent is given automatically
|
||||||
if self.org:get_member_count() == 0 then
|
if self.org:get_member_count() == 0 then
|
||||||
self.result()
|
if self.data.result then
|
||||||
|
self.data.result() end
|
||||||
self.org:wipe_pending_actions(self.id)
|
self.org:wipe_pending_actions(self.id)
|
||||||
else
|
else
|
||||||
-- otherwise, create poll
|
-- otherwise, create poll
|
||||||
@ -39,14 +40,14 @@ function consent:callback(member)
|
|||||||
if resp == "Yes" then
|
if resp == "Yes" then
|
||||||
self.data.votes = self.data.votes + 1
|
self.data.votes = self.data.votes + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.data.votes >= self.config.votes_required then
|
if self.data.votes >= self.config.votes_required then
|
||||||
|
if self.data.result then
|
||||||
|
self.data.result() end
|
||||||
self.org:wipe_pending_actions(self.id)
|
self.org:wipe_pending_actions(self.id)
|
||||||
if self.result then self.result() end
|
self.org:delete_process(self.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
modpol.modules.consent = consent
|
modpol.modules.consent = consent
|
||||||
|
@ -7,19 +7,19 @@ join_org.setup = {
|
|||||||
desc = "If consent process is passed, initiator joins this org."
|
desc = "If consent process is passed, initiator joins this org."
|
||||||
}
|
}
|
||||||
|
|
||||||
function join_org.initiate(initiator, org, result)
|
function join_org.initiate(result)
|
||||||
modpol.interactions.binary_poll_user(
|
modpol.interactions.binary_poll_user(
|
||||||
initiator,
|
initiator,
|
||||||
"Would you like to join " .. org.name,
|
"Would you like to join " .. org.name,
|
||||||
function (resp)
|
function (resp)
|
||||||
if resp == "Yes" then
|
if resp == "Yes" then
|
||||||
org:add_member(initiator)
|
self.org:add_member(self.initiator)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
for i, member in ipairs(org.members) do
|
for i, member in ipairs(self.org.members) do
|
||||||
org:add_pending_action(
|
self.org:add_pending_action(
|
||||||
member,
|
member,
|
||||||
function ()
|
function ()
|
||||||
modpol.interactions.binary_poll_user(
|
modpol.interactions.binary_poll_user(
|
||||||
|
@ -14,7 +14,7 @@ join_org_consent.data = {
|
|||||||
join_org_consent.config = {
|
join_org_consent.config = {
|
||||||
}
|
}
|
||||||
|
|
||||||
function join_org_consent:initiate()
|
function join_org_consent:initiate(result)
|
||||||
self.org:call_module(
|
self.org:call_module(
|
||||||
"consent",
|
"consent",
|
||||||
self.initiator,
|
self.initiator,
|
||||||
@ -26,6 +26,7 @@ function join_org_consent:initiate()
|
|||||||
self:complete()
|
self:complete()
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
if result then result() end
|
||||||
end
|
end
|
||||||
|
|
||||||
function join_org_consent:complete()
|
function join_org_consent:complete()
|
||||||
|
@ -15,13 +15,9 @@ leave_org.config = {
|
|||||||
|
|
||||||
--- (Required): initiate function
|
--- (Required): initiate function
|
||||||
-- Modules have access to the following instance variables:
|
-- 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
|
-- @param result (optional) Callback if this module is embedded in other modules
|
||||||
-- @function initiate
|
-- @function initiate
|
||||||
function leave_org:initiate(config, result)
|
function leave_org:initiate(result)
|
||||||
if self.org == modpol.instance then
|
if self.org == modpol.instance then
|
||||||
modpol.interactions.message(
|
modpol.interactions.message(
|
||||||
self.initiator,
|
self.initiator,
|
||||||
@ -34,7 +30,6 @@ function leave_org:initiate(config, result)
|
|||||||
modpol.interactions.message(
|
modpol.interactions.message(
|
||||||
self.initiator,
|
self.initiator,
|
||||||
"You have left org " .. self.org.name)
|
"You have left org " .. self.org.name)
|
||||||
-- call result function
|
|
||||||
end
|
end
|
||||||
if result then result() end
|
if result then result() end
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
--- @module Remove Org
|
--- @module Remove Org
|
||||||
-- A simple module that calls a consent process on an org to remove it.
|
-- A simple module that removes an org.
|
||||||
|
|
||||||
|
|
||||||
--- Main module table
|
--- Main module table
|
||||||
@ -14,7 +14,7 @@ remove_org.data = {}
|
|||||||
|
|
||||||
--- Initiate function
|
--- Initiate function
|
||||||
-- @function initiate
|
-- @function initiate
|
||||||
function remove_org:initiate(config, result)
|
function remove_org:initiate(result)
|
||||||
if self.org == modpol.instance then
|
if self.org == modpol.instance then
|
||||||
modpol.interactions.message(
|
modpol.interactions.message(
|
||||||
self.initiator,
|
self.initiator,
|
||||||
|
@ -14,7 +14,7 @@ remove_org_consent.data = {
|
|||||||
remove_org_consent.config = {
|
remove_org_consent.config = {
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove_org_consent:initiate()
|
function remove_org_consent:initiate(result)
|
||||||
self.org:call_module(
|
self.org:call_module(
|
||||||
"consent",
|
"consent",
|
||||||
self.initiator,
|
self.initiator,
|
||||||
@ -26,6 +26,9 @@ function remove_org_consent:initiate()
|
|||||||
self:complete()
|
self:complete()
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
modpol.interactions.org_dashboard(
|
||||||
|
self.initiator, self.org.name)
|
||||||
|
if result then result() end
|
||||||
end
|
end
|
||||||
|
|
||||||
function remove_org_consent:complete()
|
function remove_org_consent:complete()
|
||||||
|
@ -35,10 +35,9 @@ module_template.config = {
|
|||||||
-- <li><code>self.org</code> (the org the module was called in),</li>
|
-- <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.initiator</code> (the user that callced the module),</li>
|
||||||
-- <li><code>self.id</code> (the process id of the module instance)</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
|
-- @param result (optional) Callback if this module is embedded in other modules
|
||||||
-- @function initiate
|
-- @function initiate
|
||||||
function module_template:initiate(config, result)
|
function module_template:initiate(result)
|
||||||
-- call interaction functions here!
|
-- call interaction functions here!
|
||||||
|
|
||||||
-- call result function
|
-- call result function
|
||||||
|
@ -60,6 +60,8 @@ end
|
|||||||
function modpol.orgs:add_pending_action(process_id, user, callback)
|
function modpol.orgs:add_pending_action(process_id, user, callback)
|
||||||
self.pending[user] = self.pending[user] or {}
|
self.pending[user] = self.pending[user] or {}
|
||||||
self.pending[user][process_id] = callback
|
self.pending[user][process_id] = callback
|
||||||
|
modpol.interactions.message(
|
||||||
|
user, "New pending action in org "..self.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
function modpol.orgs:remove_pending_action(process_id, user)
|
function modpol.orgs:remove_pending_action(process_id, user)
|
||||||
|
@ -97,7 +97,7 @@ modpol.ocutil.log = function (s)
|
|||||||
|
|
||||||
if modpol.ocutil.logdir ~= nil and
|
if modpol.ocutil.logdir ~= nil and
|
||||||
modpol.ocutil.logname ~= nil then
|
modpol.ocutil.logname ~= nil then
|
||||||
s = s .. "\n" -- Add trailing newline
|
s = s .. "\n" -- Add trailing newline
|
||||||
|
|
||||||
local logpath = modpol.ocutil.logdir .. "/" .. modpol.ocutil.logname
|
local logpath = modpol.ocutil.logdir .. "/" .. modpol.ocutil.logname
|
||||||
modpol.ocutil.file_append (logpath, s)
|
modpol.ocutil.file_append (logpath, s)
|
||||||
|
@ -15,31 +15,30 @@ priv_to_org.config = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
--- (Required): initiate function
|
--- (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
|
-- @param result (optional) Callback if this module is embedded in other modules
|
||||||
-- @function initiate
|
-- @function initiate
|
||||||
function priv_to_org:initiate(config, result)
|
function priv_to_org:initiate(result)
|
||||||
local player_privs = minetest.get_player_privs(self.initiator)
|
local player_privs = minetest.get_player_privs(self.initiator)
|
||||||
for i,v in ipairs(player_privs) do
|
-- construct table for display
|
||||||
if not v then table.remove(player_privs,i) end
|
local player_privs_table = {"View..."}
|
||||||
|
for k,v in pairs(player_privs) do
|
||||||
|
if player_privs[k] then
|
||||||
|
table.insert(player_privs_table,k)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
modpol.interactions.dropdown_query(
|
modpol.interactions.dropdown_query(
|
||||||
self.initiator,
|
self.initiator,
|
||||||
"Which privilege do you want to share with members of "..self.org.name.."?",
|
"Which privilege do you want to share with members of "..self.org.name.."?",
|
||||||
player_privs,
|
player_privs_table,
|
||||||
function(input)
|
function(input)
|
||||||
for member in self.org.members do
|
for i,member in ipairs(self.org.members) do
|
||||||
local member_privs = minetest.get_player_privs(member.name)
|
local member_privs = minetest.get_player_privs(member)
|
||||||
member_privs[input] = true
|
member_privs[input] = true
|
||||||
minetest.set_player_privs(member.name, member_privs)
|
minetest.set_player_privs(member, member_privs)
|
||||||
end
|
end
|
||||||
local message = self.initiator .. " has set " .. input ..
|
local message = self.initiator .. " added " .. input ..
|
||||||
" privilege to all members of " .. self.org.name
|
" privilege to all members of " .. self.org.name
|
||||||
modpol.interactions.message_org(self.initiator,self.org.id, message)
|
modpol.interactions.message_org(self.initiator, self.org.id, message)
|
||||||
end)
|
end)
|
||||||
-- call result function
|
-- call result function
|
||||||
if result then result() end
|
if result then result() end
|
||||||
|
@ -223,8 +223,16 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|||||||
elseif fields.modules
|
elseif fields.modules
|
||||||
and fields.modules ~= "View..." then
|
and fields.modules ~= "View..." then
|
||||||
local module = fields.modules
|
local module = fields.modules
|
||||||
org:call_module(module, pname)
|
modpol.interactions.binary_poll_user(
|
||||||
modpol.interactions.org_dashboard(pname,org.name)
|
pname,
|
||||||
|
modpol.modules[module].name.."\n"..
|
||||||
|
modpol.modules[module].desc.."\n"..
|
||||||
|
"Proceed?",
|
||||||
|
function(input)
|
||||||
|
if input == "Yes" then
|
||||||
|
org:call_module(module, pname)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
-- Receiving actions
|
-- Receiving actions
|
||||||
elseif fields.actions
|
elseif fields.actions
|
||||||
@ -258,14 +266,16 @@ function modpol.interactions.policy_dashboard(
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- BASIC INTERACTION FUNCTIONS
|
-- INTERACTION FUNCTIONS
|
||||||
-- ===========================
|
-- =====================
|
||||||
|
|
||||||
-- Function: modpol.interactions.message
|
-- Function: modpol.interactions.message
|
||||||
-- input: user (string), message (string)
|
-- input: user (string), message (string)
|
||||||
-- output: displays message to specified user
|
-- output: displays message to specified user
|
||||||
function modpol.interactions.message(user, message)
|
function modpol.interactions.message(user, message)
|
||||||
minetest.chat_send_player(user, message)
|
if message then
|
||||||
|
minetest.chat_send_player(user, message)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Function: modpol.interactions.text_query
|
-- Function: modpol.interactions.text_query
|
||||||
@ -331,11 +341,13 @@ end
|
|||||||
minetest.register_on_player_receive_fields(function (player, formname, fields)
|
minetest.register_on_player_receive_fields(function (player, formname, fields)
|
||||||
if formname == "modpol:dropdown_query" then
|
if formname == "modpol:dropdown_query" then
|
||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
if fields.cancel ~= "cancel" then
|
if fields.cancel == "cancel" then
|
||||||
|
-- cancel, do nothing
|
||||||
|
else
|
||||||
local choice = fields.input
|
local choice = fields.input
|
||||||
local func = _contexts[pname]["dropdown_query_func"]
|
local func = _contexts[pname]["dropdown_query_func"]
|
||||||
if not choice then
|
if not choice then
|
||||||
-- no choice, do nothing
|
-- empty, do nothing
|
||||||
elseif func then
|
elseif func then
|
||||||
func(choice)
|
func(choice)
|
||||||
else
|
else
|
||||||
@ -355,10 +367,10 @@ function modpol.interactions.binary_poll_user(user, question, func)
|
|||||||
-- set up formspec
|
-- set up formspec
|
||||||
local formspec = {
|
local formspec = {
|
||||||
"formspec_version[4]",
|
"formspec_version[4]",
|
||||||
"size[5,3]",
|
"size[8,4]",
|
||||||
"label[0.375,0.5;",minetest.formspec_escape(question), "]",
|
"label[0.375,0.5;",minetest.formspec_escape(question), "]",
|
||||||
"button[1,1.5;1,0.8;yes;Yes]",
|
"button[1,2.5;1,0.8;yes;Yes]",
|
||||||
"button[2,1.5;1,0.8;no;No]",
|
"button[2,2.5;1,0.8;no;No]",
|
||||||
--TODO can we enable text wrapping?
|
--TODO can we enable text wrapping?
|
||||||
--TODO we could use scroll boxes to contain the text
|
--TODO we could use scroll boxes to contain the text
|
||||||
}
|
}
|
||||||
@ -377,7 +389,6 @@ minetest.register_on_player_receive_fields(function (player, formname, fields)
|
|||||||
elseif fields.no then vote = fields.no
|
elseif fields.no then vote = fields.no
|
||||||
end
|
end
|
||||||
if vote then
|
if vote then
|
||||||
modpol.interactions.message(pname, "Responded " .. vote)
|
|
||||||
local func = _contexts[pname]["binary_poll_func"]
|
local func = _contexts[pname]["binary_poll_func"]
|
||||||
if func then func(vote) end
|
if func then func(vote) end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user