join_org_consent.lua 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. --- Join org (consent).
  2. -- A simple module that calls a consent process on an org to add a member.
  3. -- Depends on the Consent module.
  4. -- @module join_org_consent
  5. local join_org_consent = {
  6. name = "Join this org (consent)",
  7. slug = "join_org_consent",
  8. desc = "Adds member with consent of all members"
  9. }
  10. join_org_consent.data = {
  11. result = nil
  12. }
  13. join_org_consent.config = {
  14. }
  15. --- Initiate join org with consent
  16. -- @function join_org_consent:initiate
  17. -- @param result
  18. function join_org_consent:initiate(result)
  19. if self.org:has_member(self.initiator) then
  20. modpol.interactions.message(
  21. self.initiator,
  22. "You are already a member of this org")
  23. if result then result() end
  24. self.org:delete_process(self.id)
  25. else
  26. self.data.result = result
  27. self.org:call_module(
  28. "consent",
  29. self.initiator,
  30. {
  31. prompt = "Allow " .. self.initiator .. " to join?",
  32. votes_required = #self.org.members
  33. },
  34. function ()
  35. self:complete()
  36. end
  37. )
  38. end
  39. end
  40. --- Adds member to org, notifies org, and deletes process
  41. -- @function join_org_consent:complete
  42. function join_org_consent:complete()
  43. self.org:add_member(self.initiator)
  44. modpol.interactions.message_org(
  45. self.initiator,self.org.name,
  46. "Consent reached: " .. self.initiator ..
  47. " joined org " .. self.org.name)
  48. if self.data.result then self.data.result() end
  49. self.org:delete_process(self.id)
  50. end
  51. modpol.modules.join_org_consent = join_org_consent