Added minetest modules and am stuck on interactions and module flow
This commit is contained in:
@ -14,5 +14,6 @@ dofile (localdir .. "/interactions/interactions.lua")
|
||||
dofile (localdir .. "/modules/add_child_org.lua")
|
||||
dofile (localdir .. "/modules/consent.lua")
|
||||
dofile (localdir .. "/modules/join_org_consent.lua")
|
||||
dofile (localdir .. "/modules/leave_org.lua")
|
||||
dofile (localdir .. "/modules/remove_org_consent.lua")
|
||||
dofile (localdir .. "/modules/remove_org.lua")
|
||||
|
@ -1,29 +1,62 @@
|
||||
--- @module add_child_org
|
||||
-- Adds a child org
|
||||
-- Depends on `consent`
|
||||
|
||||
local add_child_org = {
|
||||
name = "Add child org",
|
||||
slug = "add_child_org",
|
||||
desc = "Create a child org within the current one"
|
||||
desc = "Create a child org within the current one with consent"
|
||||
}
|
||||
add_child_org.data = {
|
||||
child_name = ""
|
||||
}
|
||||
add_child_org.config = {
|
||||
}
|
||||
|
||||
-- @function initiate
|
||||
function add_child_org:initiate(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(
|
||||
self.initiator,"Child org name: ",
|
||||
function(input)
|
||||
self.org:add_org(input, self.initiator)
|
||||
modpol.interactions.message_org(
|
||||
self.initiator,
|
||||
self.org.id,
|
||||
"Child org created: "..input)
|
||||
modpol.interactions.dashboard(self.initiator)
|
||||
end)
|
||||
if input == "" then
|
||||
modpol.interactions.message(
|
||||
self.initiator,
|
||||
"No name entered for child org")
|
||||
self.org:wipe_pending_actions(self.id)
|
||||
return end
|
||||
self.data.child_name = input
|
||||
modpol.interactions.message(
|
||||
self.initiator,
|
||||
"Proposed child org: " .. input)
|
||||
self.org:wipe_pending_actions(self.id)
|
||||
self:propose_child_org()
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
function add_child_org: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.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
|
||||
|
||||
--- (Required) Add to module table
|
||||
modpol.modules.add_child_org = add_child_org
|
||||
|
@ -16,7 +16,7 @@ consent.config = {
|
||||
votes_required = 1
|
||||
}
|
||||
|
||||
function consent:initiate(result)
|
||||
function consent:initiate(config, result)
|
||||
self.result = result
|
||||
-- if org is empty, consent is given automatically
|
||||
if self.org:get_member_count() == 0 then
|
||||
@ -39,10 +39,10 @@ function consent:callback(member)
|
||||
if resp == "Yes" then
|
||||
self.data.votes = self.data.votes + 1
|
||||
end
|
||||
|
||||
|
||||
if self.data.votes >= self.config.votes_required then
|
||||
if self.result then self.result() end
|
||||
self.org:wipe_pending_actions(self.id)
|
||||
if self.result then self.result() end
|
||||
end
|
||||
end
|
||||
)
|
||||
|
@ -0,0 +1,43 @@
|
||||
--- leave_org
|
||||
-- @module leave_org
|
||||
|
||||
local leave_org = {
|
||||
name = "Leave org",
|
||||
slug = "leave_org",
|
||||
desc = "Leave this org"
|
||||
}
|
||||
|
||||
leave_org.data = {
|
||||
}
|
||||
|
||||
leave_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 leave_org:initiate(config, result)
|
||||
if self.org == modpol.instance then
|
||||
modpol.interactions.message(
|
||||
self.initiator,
|
||||
"You cannot leave the root org")
|
||||
else
|
||||
self.org:remove_member(self.initiator)
|
||||
modpol.interactions.message_org(
|
||||
self.initiator,self.org.id,
|
||||
self.initiator .. " has left org " .. self.org.name)
|
||||
modpol.interactions.message(
|
||||
self.initiator,
|
||||
"You have left org " .. self.org.name)
|
||||
-- call result function
|
||||
end
|
||||
if result then result() end
|
||||
end
|
||||
|
||||
--- (Required) Add to module table
|
||||
modpol.modules.leave_org = leave_org
|
||||
|
@ -15,12 +15,18 @@ remove_org.data = {}
|
||||
--- Initiate function
|
||||
-- @function initiate
|
||||
function remove_org:initiate(config, result)
|
||||
modpol.interactions.message_org(
|
||||
self.initiator,self.org.id,
|
||||
"Removing org: "..self.org.name)
|
||||
self.org:delete()
|
||||
modpol.interactions.dashboard(self.initiator)
|
||||
-- call result function
|
||||
if self.org == modpol.instance then
|
||||
modpol.interactions.message(
|
||||
self.initiator,
|
||||
"You cannot remove the root org")
|
||||
else
|
||||
modpol.interactions.message_org(
|
||||
self.initiator,self.org.id,
|
||||
"Removing org: "..self.org.name)
|
||||
self.org:delete()
|
||||
modpol.interactions.dashboard(self.initiator)
|
||||
-- call result function
|
||||
end
|
||||
if result then result() end
|
||||
end
|
||||
|
||||
|
@ -33,7 +33,6 @@ function remove_org_consent:complete()
|
||||
self.initiator, self.org.id,
|
||||
"Removing org: " .. self.org.name)
|
||||
self.org:delete()
|
||||
modpol.interactions.dashboard(self.initiator)
|
||||
end
|
||||
|
||||
modpol.modules.remove_org_consent = remove_org_consent
|
||||
|
@ -90,12 +90,9 @@ end
|
||||
|
||||
function modpol.orgs:interact(process_id, user)
|
||||
local process = self.processes[process_id]
|
||||
modpol.interactions.message(user,"hi!")
|
||||
if self.pending[user] then
|
||||
modpol.interactions.message(user,"id: "..process_id)
|
||||
local callback = self.pending[user][process_id]
|
||||
if callback then
|
||||
modpol.interactions.message(user,"la!")
|
||||
process[callback](process, user)
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user