2
0

consent.lua 929 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. Consent = {}
  2. Consent.setup = {
  3. name = "Consent",
  4. slug = "consent",
  5. desc = "Other modules can use to implement consent based decision making",
  6. votes = 0
  7. }
  8. Consent.config = {
  9. prompt = "Would you like to approve this action?",
  10. votes_required = 1
  11. }
  12. function Consent:initiate(result)
  13. self.result = result
  14. for id, member in pairs(self.org.members) do
  15. self.org:add_pending_action(self.id, member, "callback")
  16. end
  17. end
  18. function Consent:callback(member)
  19. modpol.interactions.binary_poll_user(
  20. member,
  21. self.config.prompt,
  22. function (resp)
  23. if resp == "Yes" then
  24. self.votes = self.votes + 1
  25. end
  26. if self.votes >= self.config.votes_required then
  27. self.result()
  28. self.org:wipe_pending_actions(self.id)
  29. end
  30. end
  31. )
  32. end
  33. modpol.modules.consent = Consent