join_org_consent.lua 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. local join_org_consent = {
  5. name = "Join this org (consent)",
  6. slug = "join_org_consent",
  7. desc = "Adds member with consent of all members"
  8. }
  9. join_org_consent.data = {
  10. result = nil
  11. }
  12. join_org_consent.config = {
  13. }
  14. function join_org_consent:initiate(result)
  15. if self.org:has_member(self.initiator) then
  16. modpol.interactions.message(
  17. self.initiator,
  18. "You are already a member of this org")
  19. if result then result() end
  20. self.org:delete_process(self.id)
  21. else
  22. self.data.result = result
  23. self.org:call_module(
  24. "consent",
  25. self.initiator,
  26. {
  27. prompt = "Allow " .. self.initiator .. " to join?",
  28. votes_required = #self.org.members
  29. },
  30. function ()
  31. self:complete()
  32. end
  33. )
  34. end
  35. end
  36. function join_org_consent:complete()
  37. self.org:add_member(self.initiator)
  38. modpol.interactions.message_org(
  39. self.initiator,self.org.name,
  40. "Consent reached: " .. self.initiator ..
  41. " joined org " .. self.org.name)
  42. if self.data.result then self.data.result() end
  43. self.org:delete_process(self.id)
  44. end
  45. modpol.modules.join_org_consent = join_org_consent