join_org_class.lua 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. -- JOIN ORG
  2. -- Module that enables a user to join an org
  3. JoinOrg = {}
  4. JoinOrg.setup = {
  5. name = "Join an org",
  6. desc = "Initiator chooses an org to become a member of. Nothing happens if they are already in an org.",
  7. votes_yes = 0
  8. }
  9. function JoinOrg:initiate(result)
  10. modpol.interactions.binary_poll_user(
  11. self.initiator,
  12. "Would you like to join",
  13. function (resp)
  14. if resp == "Yes" then
  15. for id, member in pairs(self.org.members) do
  16. self.org:add_pending_action(self.id, member, "callback")
  17. end
  18. end
  19. end
  20. )
  21. if result then result() end
  22. end
  23. function JoinOrg:callback(member)
  24. modpol.interactions.binary_poll_user(
  25. member,
  26. "Do you want " .. self.initiator .. " to join?",
  27. function (resp)
  28. if resp == "Yes" then
  29. self.votes_yes = self.votes_yes + 1
  30. end
  31. self:evaluate_vote()
  32. end
  33. )
  34. end
  35. function JoinOrg:evaluate_vote()
  36. if self.votes_yes >= 1 then
  37. print('added user')
  38. self.org:add_member(self.initiator)
  39. self.org:wipe_pending_actions(self.id)
  40. end
  41. end
  42. -- ===================================
  43. -- When calling a module internally
  44. modpol.modules.join_org_class = JoinOrg