priv_to_org.lua 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. --- Set privilege to org members
  2. -- Allows initiator to grant a priv they have to all members of an org
  3. -- @module priv_to_org
  4. local priv_to_org = {
  5. name = "Set privilege to org members",
  6. slug = "priv_to_org",
  7. desc = "Allows initiator to grant a priv they have to all members of an org"
  8. }
  9. priv_to_org.data = {
  10. }
  11. priv_to_org.config = {
  12. }
  13. --- Initiate function
  14. -- @function priv_to_org:initiate
  15. -- @param result
  16. function priv_to_org:initiate(result)
  17. local player_privs = minetest.get_player_privs(self.initiator)
  18. -- construct table for display
  19. local player_privs_table = {}
  20. for k,v in pairs(player_privs) do
  21. if player_privs[k] then
  22. table.insert(player_privs_table,k)
  23. end
  24. end
  25. modpol.interactions.dropdown_query(
  26. self.initiator,
  27. "Which privilege do you want to share with members of "..self.org.name.."?",
  28. player_privs_table,
  29. function(input)
  30. modpol.interactions.org_dashboard(self.initiator,self.org.id)
  31. for i,member in ipairs(self.org.members) do
  32. local member_privs = minetest.get_player_privs(member)
  33. member_privs[input] = true
  34. minetest.set_player_privs(member, member_privs)
  35. end
  36. local message = self.initiator .. " added " .. input ..
  37. " privilege to all members of " .. self.org.name
  38. modpol.interactions.message_org(self.initiator, self.org.id, message)
  39. end)
  40. -- call result function
  41. if result then result() end
  42. end
  43. modpol.modules.priv_to_org = priv_to_org