Renamed modpol/modpol directory to modpol_core for clarity and consistency
This commit is contained in:
52
modpol_core/modules/consent.lua
Normal file
52
modpol_core/modules/consent.lua
Normal 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
|
Reference in New Issue
Block a user