Renamed modpol/modpol directory to modpol_core for clarity and consistency

This commit is contained in:
Nathan Schneider
2021-12-18 14:50:41 -07:00
parent bd95fcf811
commit c2852b1bce
32 changed files with 6 additions and 8 deletions

View File

@ -0,0 +1,29 @@
--- @module add_child_org
-- Adds a child org
local add_child_org = {
name = "Add child org",
slug = "add_child_org",
desc = "Create a child org within the current one"
}
add_child_org.data = {
}
add_child_org.config = {
}
-- @function initiate
function add_child_org:initiate(result)
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)
end
--- (Required) Add to module table
modpol.modules.add_child_org = add_child_org

View File

@ -0,0 +1,52 @@
--- @module consent
-- A utility module for checking consent
local consent = {
name = "Consent",
slug = "consent",
desc = "Other modules can use to implement consent based decision making",
}
consent.data = {
votes = 0
}
consent.config = {
prompt = "Do you consent?",
votes_required = 1
}
function consent:initiate(result)
self.result = result
-- if org is empty, consent is given automatically
if self.org:get_member_count() == 0 then
self.result()
self.org:wipe_pending_actions(self.id)
else
-- otherwise, create poll
for id, member in pairs(self.org.members) do
self.org:add_pending_action(self.id, member, "callback")
end
end
end
function consent:callback(member)
modpol.interactions.binary_poll_user(
member,
self.config.prompt,
function (resp)
self.org:remove_pending_action(self.id,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)
end
end
)
end
modpol.modules.consent = consent

View File

@ -0,0 +1,39 @@
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,
"Would you like to join " .. org.name,
function (resp)
if resp == "Yes" then
org:add_member(initiator)
end
end
)
for i, member in ipairs(org.members) do
org:add_pending_action(
member,
function ()
modpol.interactions.binary_poll_user(
member,
"Let " .. initiator .. " join " .. org.name .. "?",
function (resp)
end
)
end
)
end
if result then result() end
end
modpol.modules.join_org = join_org

View File

@ -0,0 +1,36 @@
--- Join org (consent)
-- A simple module that calls a consent process on an org to add a member.
-- Depends on the Consent module.
local join_org_consent = {
name = "Join this org",
slug = "join_org_consent",
desc = "Adds member with consent of all members."
}
join_org_consent.data = {
}
join_org_consent.config = {
}
function join_org_consent:initiate()
self.org:call_module(
"consent",
self.initiator,
{
prompt = "Allow " .. self.initiator .. " to join?",
votes_required = #self.org.members
},
function ()
self:complete()
end
)
end
function join_org_consent:complete()
self.org:add_member(self.initiator)
print("Added " .. self.initiator .. " to the org.")
end
modpol.modules.join_org_consent = join_org_consent

View File

View File

@ -0,0 +1,27 @@
--- @module Remove Org
-- A simple module that calls a consent process on an org to remove it.
--- Main module table
remove_org = {
name = "Remove this org",
slug = "remove_org",
desc = "Removes an org if all members consent."
}
remove_org.config = {}
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 result then result() end
end
modpol.modules.remove_org = remove_org

View File

@ -0,0 +1,39 @@
--- Remove org (consent)
-- A simple module that calls a consent process on an org to remove it.
-- Depends on the Consent module.
local remove_org_consent = {
name = "Remove this org",
slug = "remove_org_consent",
desc = "Removes an org if all members consent."
}
remove_org_consent.data = {
}
remove_org_consent.config = {
}
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 remove_org_consent:complete()
modpol.interactions.message_org(
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

View File

@ -0,0 +1,49 @@
--- module_template
-- @module module_template
--- (Required): data table containing name and description of the module
-- @field name "Human-readable name"
-- @field slug "Same as module class name"
-- @field desc "Description of the module"
local module_template = {
name = "Module Human-Readable Name",
slug = "template",
desc = "Description of the module"
}
--- (Required) Data for module
-- Variables that module uses during the course of a process
-- Can be blank
module_template.data = {
}
--- (Required): config for module
-- Defines the input parameters to the module initiate function.
-- Can be blank
-- When calling a module from within another module,
-- variables not defined in config will be ignored.
-- Default values set in config can be overridden
-- @field field_1 ex: votes_required, default = 5
-- @field field_2 ex: voting_type, default = "majority"
module_template.config = {
field_1 = 5
field_2 = "majority"
}
--- (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 module_template:initiate(config, result)
-- call interaction functions here!
-- call result function
if result then result() end
end
--- (Required) Add to module table
modpol.modules.module_template = module_template