Advertisement
Guest User

Untitled

a guest
Aug 17th, 2022
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.27 KB | Source Code | 0 0
  1. local LOGLEVEL = "info"
  2.  
  3. local is_admin = require "core.usermanager".is_admin
  4. local is_healthcheck_room = module:require "util".is_healthcheck_room
  5. module:log(LOGLEVEL, "loaded")
  6.  
  7. local function _is_admin(jid)
  8.     return is_admin(jid, module.host)
  9. end
  10.  
  11. module:hook("muc-occupant-joined", function (event)
  12.     local room, occupant = event.room, event.occupant
  13.  
  14.     if is_healthcheck_room(room.jid) or _is_admin(occupant.jid) then
  15.         module:log(LOGLEVEL, "skip affiliation, %s", occupant.jid)
  16.         return
  17.     end
  18.  
  19.     if not event.origin.auth_token then
  20.         module:log(LOGLEVEL, "skip affiliation, no token")
  21.         return
  22.     end
  23.  
  24.     local affiliation = "member"
  25.     local context_user = event.origin.jitsi_meet_context_user
  26.  
  27.     if context_user then
  28.         local jid_split = import("util.jid", "prepped_split");
  29.         local room_name = jid_split(room.jid);
  30.         module:log("info", "Room name: %s", room_name)
  31.  
  32.         local email_without_at = string.gsub(context_user["email"], "@", "");
  33.         if string.find(room_name, "^" .. email_without_at) ~= nil then
  34.             affiliation = "owner"
  35.         end
  36.     end
  37.  
  38.     module:log(LOGLEVEL, "affiliation: %s", affiliation)
  39.     room:set_affiliation(true, occupant.bare_jid, affiliation)
  40. end)
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement