leave_org.lua 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. --- leave_org
  2. -- @module leave_org
  3. local leave_org = {
  4. name = "Leave org",
  5. slug = "leave_org",
  6. desc = "Leave this org"
  7. }
  8. leave_org.data = {
  9. }
  10. leave_org.config = {
  11. }
  12. --- (Required): initiate function
  13. -- Modules have access to the following instance variables:
  14. -- <li><code>self.org</code> (the org the module was called in),</li>
  15. -- <li><code>self.initiator</code> (the user that callced the module),</li>
  16. -- <li><code>self.id</code> (the process id of the module instance)</li>
  17. -- @param config (optional) If user wants to override fields in the config table
  18. -- @param result (optional) Callback if this module is embedded in other modules
  19. -- @function initiate
  20. function leave_org:initiate(config, result)
  21. if self.org == modpol.instance then
  22. modpol.interactions.message(
  23. self.initiator,
  24. "You cannot leave the root org")
  25. else
  26. self.org:remove_member(self.initiator)
  27. modpol.interactions.message_org(
  28. self.initiator,self.org.id,
  29. self.initiator .. " has left org " .. self.org.name)
  30. modpol.interactions.message(
  31. self.initiator,
  32. "You have left org " .. self.org.name)
  33. -- call result function
  34. end
  35. if result then result() end
  36. end
  37. --- (Required) Add to module table
  38. modpol.modules.leave_org = leave_org