diff options
author | Kim Alvefur <zash@zash.se> | 2023-01-29 17:41:08 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2023-01-29 17:41:08 +0100 |
commit | 2b0584d2ee7150db07d7e9b064c3c7aa83cabcda (patch) | |
tree | edbc9f528fc72c09a6c44d493b7f001724fd02e7 /plugins/mod_admin_shell.lua | |
parent | 9228a851bc4b93bf442a62b8b7392ee087374bea (diff) | |
download | prosody-2b0584d2ee7150db07d7e9b064c3c7aa83cabcda.tar.gz prosody-2b0584d2ee7150db07d7e9b064c3c7aa83cabcda.zip |
mod_admin_shell: Add muc:occupants(room) command to list occupants
Easier than going trough muc:room():each_occupant() since you have to do
fiddly things to reach the print() function.
Diffstat (limited to 'plugins/mod_admin_shell.lua')
-rw-r--r-- | plugins/mod_admin_shell.lua | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/plugins/mod_admin_shell.lua b/plugins/mod_admin_shell.lua index 3eaa871a..c5a3a243 100644 --- a/plugins/mod_admin_shell.lua +++ b/plugins/mod_admin_shell.lua @@ -25,7 +25,7 @@ local prosody = _G.prosody; local unpack = table.unpack; local iterators = require "util.iterators"; local keys, values = iterators.keys, iterators.values; -local jid_bare, jid_split, jid_join = import("util.jid", "bare", "prepped_split", "join"); +local jid_bare, jid_split, jid_join, jid_resource = import("util.jid", "bare", "prepped_split", "join", "resource"); local set, array = require "util.set", require "util.array"; local cert_verify_identity = require "util.x509".verify_identity; local envload = require "util.envload".envload; @@ -289,6 +289,7 @@ function commands.help(session, data) print [[muc:create(roomjid, { config }) - Create the specified MUC room with the given config]] 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]] elseif section == "server" then print [[server:version() - Show the server's version number]] print [[server:uptime() - Show how long the server has been running]] @@ -1384,6 +1385,34 @@ function def_env.muc:list(host) return true, c.." rooms"; end +function def_env.muc:occupants(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 nick_jid, occupant in room_obj:each_occupant() do + local nick = jid_resource(nick_jid); + if filter == nil or occupant.role == filter or nick:find(filter, 1, true) then + print(occupant.role, nick); + displayed = displayed + 1; + end + total = total + 1 + end + + if total == displayed then + return true, ("%d occupant%s listed"):format(total, total ~= 1 and "s" or "") + else + return true, ("%d out of %d occupant%s listed"):format(displayed, total, total ~= 1 and "s" or "") + end +end + local um = require"core.usermanager"; def_env.user = {}; |