join_org.lua 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. --- Join org
  2. -- Adds initiator to an org
  3. -- @module join_org
  4. local join_org = {
  5. name = "Join this org",
  6. slug = "join_org",
  7. desc = "Allows initiator to join this org"
  8. }
  9. join_org.data = {
  10. result = nil
  11. }
  12. join_org.config = {
  13. approval_module = false
  14. }
  15. --- Initiate join org with consent
  16. -- @function join_org:initiate
  17. -- @param result Callback if this module is embedded in other modules
  18. function join_org: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:call_module(
  28. self.config.approval_module,
  29. self.initiator,
  30. {
  31. prompt = "Allow " .. self.initiator .. " to join?"
  32. },
  33. function ()
  34. self:complete()
  35. end
  36. )
  37. end
  38. end
  39. --- Adds member to org, notifies org, and deletes process
  40. -- @function join_org:complete
  41. function join_org:complete()
  42. self.org:add_member(self.initiator)
  43. modpol.interactions.message_org(
  44. self.initiator,self.org.name,
  45. self.initiator .. " joined org " .. self.org.name)
  46. if self.data.result then self.data.result() end
  47. self.org:delete_process(self.id)
  48. end
  49. modpol.modules.join_org = join_org