Added remove_org_consent module, a few other tweaks to modules

This commit is contained in:
Nathan Schneider 2021-12-16 23:33:02 -07:00
parent b9d2b73611
commit 9e492bb1f8
10 changed files with 77 additions and 73 deletions

View File

@ -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:
```
$ cd modpol/interacctions/
$ cd modpol/interactions/
$ lua [or luajit]
> dofile("login.lua")
```

View File

@ -13,7 +13,7 @@ dofile (localdir .. "/orgs/process.lua")
dofile (localdir .. "/interactions/interactions.lua")
--modules
dofile (localdir .. "/modules/join_org.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")

View File

@ -97,7 +97,6 @@ end
-- create instance if not present
modpol.instance = modpol.orgs.array[1] or modpol.orgs.init_instance()
modpol.ocutil.log ("modpol loaded")
-- ===================================================================

View File

@ -39,4 +39,4 @@ function Consent:callback(member)
end
modpol.modules.consent = Consent
modpol.modules.consent = Consent

View File

@ -1,6 +1,12 @@
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)
modpol.interactions.binary_poll_user(
initiator,

View File

@ -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

View File

@ -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 = {}
JoinOrg.setup = {
name = "Join an org",
join_org_consent.setup = {
name = "Join this org",
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(
"consent",
self.initiator,
{
prompt = "Allow " .. self.initiator .. " to join?",
votes_required = 1
votes_required = #self.org.members
},
function ()
self:complete()
@ -22,9 +24,9 @@ function JoinOrg:initiate()
)
end
function JoinOrg:complete()
function join_org_consent:complete()
self.org:add_member(self.initiator)
print("Added " .. self.initiator .. " to the org!")
print("Added " .. self.initiator .. " to the org.")
end
modpol.modules.join_org_consent = JoinOrg
modpol.modules.join_org_consent = join_org_consent

View File

@ -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

View 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

View File

@ -30,6 +30,8 @@ Template.config = {
-- <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 Template:initiate(config, result)
-- call interaction functions here!