2
0

priv_to_org.lua 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. --- Set privilege to org members
  2. -- @module priv_to_org
  3. -- Allows initiator to grant a priv they have to all members of an 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. --- (Required): initiate function
  14. -- @param result (optional) Callback if this module is embedded in other modules
  15. -- @function initiate
  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 = {"View..."}
  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. for i,member in ipairs(self.org.members) do
  31. local member_privs = minetest.get_player_privs(member)
  32. member_privs[input] = true
  33. minetest.set_player_privs(member, member_privs)
  34. end
  35. local message = self.initiator .. " added " .. input ..
  36. " privilege to all members of " .. self.org.name
  37. modpol.interactions.message_org(self.initiator, self.org.id, message)
  38. end)
  39. -- call result function
  40. if result then result() end
  41. end
  42. --- (Required) Add to module table
  43. modpol.modules.priv_to_org = priv_to_org