Comparison

plugins/mod_admin_shell.lua @ 12866:54aea2622459

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.
author Kim Alvefur <zash@zash.se>
date Sun, 29 Jan 2023 17:53:21 +0100
parent 12865:e6324117f124
child 12867:2defb0fc2be9
comparison
equal deleted inserted replaced
12865:e6324117f124 12866:54aea2622459
288 -- TODO `muc:room():foo()` commands 288 -- TODO `muc:room():foo()` commands
289 print [[muc:create(roomjid, { config }) - Create the specified MUC room with the given config]] 289 print [[muc:create(roomjid, { config }) - Create the specified MUC room with the given config]]
290 print [[muc:list(host) - List rooms on the specified MUC component]] 290 print [[muc:list(host) - List rooms on the specified MUC component]]
291 print [[muc:room(roomjid) - Reference the specified MUC room to access MUC API methods]] 291 print [[muc:room(roomjid) - Reference the specified MUC room to access MUC API methods]]
292 print [[muc:occupants(roomjid, filter) - List room occupants, optionally filtered on substring or role]] 292 print [[muc:occupants(roomjid, filter) - List room occupants, optionally filtered on substring or role]]
293 print [[muc:affiliations(roomjid, filter) - List affiliated members of the room, optionally filtered on substring or affiliation]]
293 elseif section == "server" then 294 elseif section == "server" then
294 print [[server:version() - Show the server's version number]] 295 print [[server:version() - Show the server's version number]]
295 print [[server:uptime() - Show how long the server has been running]] 296 print [[server:uptime() - Show how long the server has been running]]
296 print [[server:memory() - Show details about the server's memory usage]] 297 print [[server:memory() - Show details about the server's memory usage]]
297 print [[server:shutdown(reason) - Shut down the server, with an optional reason to be broadcast to all connections]] 298 print [[server:shutdown(reason) - Shut down the server, with an optional reason to be broadcast to all connections]]
1411 else 1412 else
1412 return true, ("%d out of %d occupant%s listed"):format(displayed, total, total ~= 1 and "s" or "") 1413 return true, ("%d out of %d occupant%s listed"):format(displayed, total, total ~= 1 and "s" or "")
1413 end 1414 end
1414 end 1415 end
1415 1416
1417 function def_env.muc:affiliations(room_jid, filter)
1418 local room_name, host = check_muc(room_jid);
1419 if not room_name then
1420 return room_name, host;
1421 end
1422 local room_obj = prosody.hosts[host].modules.muc.get_room_from_jid(room_jid);
1423 if not room_obj then
1424 return nil, "No such room: " .. room_jid;
1425 end
1426
1427 local print = self.session.print;
1428 local total, displayed = 0, 0;
1429 for affiliated_jid, affiliation, affiliation_data in room_obj:each_affiliation() do
1430 if filter == nil or affiliation == filter or affiliated_jid:find(filter, 1, true) then
1431 print(affiliation, affiliated_jid, affiliation_data and affiliation_data.reserved_nickname or "")
1432 displayed = displayed + 1;
1433 end
1434 total = total + 1
1435 end
1436
1437 if total == displayed then
1438 return true, ("%d affiliation%s listed"):format(total, total ~= 1 and "s" or "")
1439 else
1440 return true, ("%d out of %d affiliation%s listed"):format(displayed, total, total ~= 1 and "s" or "")
1441 end
1442 end
1443
1416 local um = require"core.usermanager"; 1444 local um = require"core.usermanager";
1417 1445
1418 def_env.user = {}; 1446 def_env.user = {};
1419 function def_env.user:create(jid, password, role) 1447 function def_env.user:create(jid, password, role)
1420 local username, host = jid_split(jid); 1448 local username, host = jid_split(jid);