Added remove_org_consent module, a few other tweaks to modules
This commit is contained in:
parent
b9d2b73611
commit
9e492bb1f8
@ -22,7 +22,7 @@ Modular Politics can also be used independently of Minetest as a command-line to
|
|||||||
The command-line version is in the `modpol` subdirectory. To interact with the interpreter on Unix systems in CLI mode, install lua or luajit and execute the following in this directory:
|
The command-line version is in the `modpol` subdirectory. To interact with the interpreter on Unix systems in CLI mode, install lua or luajit and execute the following in this directory:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ cd modpol/interacctions/
|
$ cd modpol/interactions/
|
||||||
$ lua [or luajit]
|
$ lua [or luajit]
|
||||||
> dofile("login.lua")
|
> dofile("login.lua")
|
||||||
```
|
```
|
||||||
|
@ -13,7 +13,7 @@ dofile (localdir .. "/orgs/process.lua")
|
|||||||
dofile (localdir .. "/interactions/interactions.lua")
|
dofile (localdir .. "/interactions/interactions.lua")
|
||||||
|
|
||||||
--modules
|
--modules
|
||||||
dofile (localdir .. "/modules/join_org.lua")
|
|
||||||
dofile (localdir .. "/modules/consent.lua")
|
dofile (localdir .. "/modules/consent.lua")
|
||||||
--dofile (localdir .. "/modules/remove_org.lua")
|
dofile (localdir .. "/modules/join_org_consent.lua")
|
||||||
|
dofile (localdir .. "/modules/remove_org_consent.lua")
|
||||||
--dofile (localdir .. "/modules/child_org.lua")
|
--dofile (localdir .. "/modules/child_org.lua")
|
||||||
|
@ -97,7 +97,6 @@ end
|
|||||||
-- create instance if not present
|
-- create instance if not present
|
||||||
modpol.instance = modpol.orgs.array[1] or modpol.orgs.init_instance()
|
modpol.instance = modpol.orgs.array[1] or modpol.orgs.init_instance()
|
||||||
|
|
||||||
|
|
||||||
modpol.ocutil.log ("modpol loaded")
|
modpol.ocutil.log ("modpol loaded")
|
||||||
|
|
||||||
-- ===================================================================
|
-- ===================================================================
|
||||||
|
@ -39,4 +39,4 @@ function Consent:callback(member)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
modpol.modules.consent = Consent
|
modpol.modules.consent = Consent
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
|
|
||||||
join_org = {}
|
join_org = {}
|
||||||
|
|
||||||
|
join_org.setup = {
|
||||||
|
name = "Join Org",
|
||||||
|
slug = "join_org",
|
||||||
|
desc = "If consent process is passed, initiator joins this org."
|
||||||
|
}
|
||||||
|
|
||||||
function join_org.initiate(initiator, org, result)
|
function join_org.initiate(initiator, org, result)
|
||||||
modpol.interactions.binary_poll_user(
|
modpol.interactions.binary_poll_user(
|
||||||
initiator,
|
initiator,
|
||||||
|
@ -1,58 +0,0 @@
|
|||||||
-- JOIN ORG
|
|
||||||
-- Module that enables a user to join an org
|
|
||||||
|
|
||||||
JoinOrg = {}
|
|
||||||
|
|
||||||
JoinOrg.setup = {
|
|
||||||
name = "Join an org",
|
|
||||||
desc = "Initiator chooses an org to become a member of. Nothing happens if they are already in an org.",
|
|
||||||
votes_yes = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
function JoinOrg:initiate(result)
|
|
||||||
modpol.interactions.binary_poll_user(
|
|
||||||
self.initiator,
|
|
||||||
"Would you like to join",
|
|
||||||
function (resp)
|
|
||||||
if resp == "Yes" then
|
|
||||||
for id, member in pairs(self.org.members) do
|
|
||||||
self.org:add_pending_action(self.id, member, "callback")
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
)
|
|
||||||
|
|
||||||
if result then result() end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
function JoinOrg:callback(member)
|
|
||||||
modpol.interactions.binary_poll_user(
|
|
||||||
member,
|
|
||||||
"Do you want " .. self.initiator .. " to join?",
|
|
||||||
function (resp)
|
|
||||||
if resp == "Yes" then
|
|
||||||
self.votes_yes = self.votes_yes + 1
|
|
||||||
end
|
|
||||||
|
|
||||||
self:evaluate_vote()
|
|
||||||
|
|
||||||
end
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function JoinOrg:evaluate_vote()
|
|
||||||
if self.votes_yes >= 1 then
|
|
||||||
print('added user')
|
|
||||||
self.org:add_member(self.initiator)
|
|
||||||
self.org:wipe_pending_actions(self.id)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- ===================================
|
|
||||||
-- When calling a module internally
|
|
||||||
|
|
||||||
modpol.modules.join_org_class = JoinOrg
|
|
@ -1,20 +1,22 @@
|
|||||||
|
--- Join org (consent)
|
||||||
|
-- A simple module that calls a consent process on an org to add a member.
|
||||||
|
-- Depends on the Consent module.
|
||||||
|
|
||||||
|
join_org_consent = {}
|
||||||
|
|
||||||
JoinOrg = {}
|
join_org_consent.setup = {
|
||||||
|
name = "Join this org",
|
||||||
JoinOrg.setup = {
|
|
||||||
name = "Join an org",
|
|
||||||
slug = "join_org_consent",
|
slug = "join_org_consent",
|
||||||
desc = "Consent based join org module"
|
desc = "Adds member with consent of all members."
|
||||||
}
|
}
|
||||||
|
|
||||||
function JoinOrg:initiate()
|
function join_org_consent:initiate()
|
||||||
self.org:call_module(
|
self.org:call_module(
|
||||||
"consent",
|
"consent",
|
||||||
self.initiator,
|
self.initiator,
|
||||||
{
|
{
|
||||||
prompt = "Allow " .. self.initiator .. " to join?",
|
prompt = "Allow " .. self.initiator .. " to join?",
|
||||||
votes_required = 1
|
votes_required = #self.org.members
|
||||||
},
|
},
|
||||||
function ()
|
function ()
|
||||||
self:complete()
|
self:complete()
|
||||||
@ -22,9 +24,9 @@ function JoinOrg:initiate()
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
function JoinOrg:complete()
|
function join_org_consent:complete()
|
||||||
self.org:add_member(self.initiator)
|
self.org:add_member(self.initiator)
|
||||||
print("Added " .. self.initiator .. " to the org!")
|
print("Added " .. self.initiator .. " to the org.")
|
||||||
end
|
end
|
||||||
|
|
||||||
modpol.modules.join_org_consent = JoinOrg
|
modpol.modules.join_org_consent = join_org_consent
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
--- Remove Org
|
||||||
|
-- A simple module that calls a consent process on an org to remove it.
|
||||||
|
-- Depends on the Consent module.
|
||||||
|
remove_org = {}
|
||||||
|
|
||||||
|
--- (Required): setup table containing name and description of the module
|
||||||
|
remove_org.setup = {
|
||||||
|
name = "Remove this org",
|
||||||
|
slug = "remove_org",
|
||||||
|
desc = "Removes an org if all members consent."
|
||||||
|
}
|
||||||
|
|
||||||
|
--- Initiate function
|
||||||
|
-- <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>
|
||||||
|
-- @function initiate
|
||||||
|
function remove_org:initiate(config, result)
|
||||||
|
|
||||||
|
-- call result function
|
||||||
|
if result then result() end
|
||||||
|
end
|
31
modpol/modules/remove_org_consent.lua
Normal file
31
modpol/modules/remove_org_consent.lua
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
--- Remove org (consent)
|
||||||
|
-- A simple module that calls a consent process on an org to remove it.
|
||||||
|
-- Depends on the Consent module.
|
||||||
|
remove_org_consent = {}
|
||||||
|
|
||||||
|
remove_org_consent.setup = {
|
||||||
|
name = "Remove this org",
|
||||||
|
slug = "remove_org",
|
||||||
|
desc = "Removes an org if all members consent."
|
||||||
|
}
|
||||||
|
|
||||||
|
function remove_org_consent:initiate()
|
||||||
|
self.org:call_module(
|
||||||
|
"consent",
|
||||||
|
self.initiator,
|
||||||
|
{
|
||||||
|
prompt = "Remove org " .. self.org.name .. "?",
|
||||||
|
votes_required = #self.org.members
|
||||||
|
},
|
||||||
|
function ()
|
||||||
|
self:complete()
|
||||||
|
end
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
function join_org_consent:complete()
|
||||||
|
self.org:delete()
|
||||||
|
print("Removed org " .. self.org.name .. ".")
|
||||||
|
end
|
||||||
|
|
||||||
|
modpol.modules.remove_org_consent = remove_org_consent
|
@ -30,6 +30,8 @@ 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
|
||||||
-- @function initiate
|
-- @function initiate
|
||||||
function Template:initiate(config, result)
|
function Template:initiate(config, result)
|
||||||
-- call interaction functions here!
|
-- call interaction functions here!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user