aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2023-01-29 17:53:21 +0100
committerKim Alvefur <zash@zash.se>2023-01-29 17:53:21 +0100
commit08a730746ce2dc52d2bc47d9868d64f601e2ea81 (patch)
tree6468920f438f7fc2343addb550edf832d7c38529 /plugins
parent2b0584d2ee7150db07d7e9b064c3c7aa83cabcda (diff)
downloadprosody-08a730746ce2dc52d2bc47d9868d64f601e2ea81.tar.gz
prosody-08a730746ce2dc52d2bc47d9868d64f601e2ea81.zip
mod_admin_shell: Add muc:affiliations(room) command to list memberships
Easier than going trough muc:room():each_affiliation() since you have to do fiddly things to reach the print() function.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_admin_shell.lua28
1 files changed, 28 insertions, 0 deletions
diff --git a/plugins/mod_admin_shell.lua b/plugins/mod_admin_shell.lua
index c5a3a243..e4ebe4c4 100644
--- a/plugins/mod_admin_shell.lua
+++ b/plugins/mod_admin_shell.lua
@@ -290,6 +290,7 @@ function commands.help(session, data)
print [[muc:list(host) - List rooms on the specified MUC component]]
print [[muc:room(roomjid) - Reference the specified MUC room to access MUC API methods]]
print [[muc:occupants(roomjid, filter) - List room occupants, optionally filtered on substring or role]]
+ print [[muc:affiliations(roomjid, filter) - List affiliated members of the room, optionally filtered on substring or affiliation]]
elseif section == "server" then
print [[server:version() - Show the server's version number]]
print [[server:uptime() - Show how long the server has been running]]
@@ -1413,6 +1414,33 @@ function def_env.muc:occupants(room_jid, filter)
end
end
+function def_env.muc:affiliations(room_jid, filter)
+ local room_name, host = check_muc(room_jid);
+ if not room_name then
+ return room_name, host;
+ end
+ local room_obj = prosody.hosts[host].modules.muc.get_room_from_jid(room_jid);
+ if not room_obj then
+ return nil, "No such room: " .. room_jid;
+ end
+
+ local print = self.session.print;
+ local total, displayed = 0, 0;
+ for affiliated_jid, affiliation, affiliation_data in room_obj:each_affiliation() do
+ if filter == nil or affiliation == filter or affiliated_jid:find(filter, 1, true) then
+ print(affiliation, affiliated_jid, affiliation_data and affiliation_data.reserved_nickname or "")
+ displayed = displayed + 1;
+ end
+ total = total + 1
+ end
+
+ if total == displayed then
+ return true, ("%d affiliation%s listed"):format(total, total ~= 1 and "s" or "")
+ else
+ return true, ("%d out of %d affiliation%s listed"):format(displayed, total, total ~= 1 and "s" or "")
+ end
+end
+
local um = require"core.usermanager";
def_env.user = {};