remove_member_consent.lua 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. --- remove_member_consent
  2. -- @module remove_member_consent
  3. local remove_member_consent = {
  4. name = "Remove a member (consent)",
  5. slug = "remove_member_consent",
  6. desc = "Removes org member with consent of other members"
  7. }
  8. remove_member_consent.data = {
  9. member_to_remove = "",
  10. result = nil
  11. }
  12. remove_member_consent.config = {
  13. }
  14. function remove_member_consent:initiate(result)
  15. -- Abort if in root org
  16. if self.org == modpol.instance then
  17. modpol.interactions.message(
  18. self.initiator,
  19. "Members cannot be removed from the root org")
  20. if result then result() end
  21. self.org:delete_process(self.id)
  22. else -- proceed if not root
  23. self.data.result = result
  24. modpol.interactions.dropdown_query(
  25. self.initiator,
  26. "Which member of org "..self.org.name..
  27. " do you want to remove?",
  28. self.org.members,
  29. function(input)
  30. self.data.member_to_remove = input
  31. self.org:call_module(
  32. "consent",
  33. self.initiator,
  34. {
  35. prompt = "Remove "..input..
  36. " from org "..self.org.name.."?",
  37. votes_required = #self.org.members - 1
  38. },
  39. function()
  40. self:complete()
  41. end)
  42. modpol.interactions.org_dashboard(
  43. self.initiator, self.org.name)
  44. end)
  45. end
  46. end
  47. function remove_member_consent:complete()
  48. modpol.interactions.message_org(
  49. self.initiator, self.org.id,
  50. "Consent reached: removing "..
  51. self.data.member_to_remove..
  52. " from org "..self.org.name)
  53. self.org:remove_member(self.data.member_to_remove)
  54. self.org:delete_process(self.id)
  55. if self.data.result then self.data.result() end
  56. end
  57. --- (Required) Add to module table
  58. modpol.modules.remove_member_consent = remove_member_consent