Software /
code /
prosody
Comparison
plugins/mod_pubsub/mod_pubsub.lua @ 13456:e9ab660b9c5f
mod_pubsub: Add shell commands to create and list nodes
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 06 Mar 2024 17:38:21 +0000 |
parent | 13339:c94989c557cd |
child | 13457:3347ed1014b8 |
comparison
equal
deleted
inserted
replaced
13455:2a001cd7f99a | 13456:e9ab660b9c5f |
---|---|
248 | 248 |
249 jid = module.host; | 249 jid = module.host; |
250 normalize_jid = jid_bare; | 250 normalize_jid = jid_bare; |
251 })); | 251 })); |
252 end | 252 end |
253 | |
254 local function get_service(service_jid) | |
255 return assert(assert(prosody.hosts[service_jid], "Unknown pubsub service").modules.pubsub, "Not a pubsub service").service; | |
256 end | |
257 | |
258 module:add_item("shell-command", { | |
259 section = "pubsub"; | |
260 section_desc = "Manage publish/subscribe nodes"; | |
261 name = "create_node"; | |
262 desc = "Create a node with the specified name"; | |
263 args = { | |
264 { name = "service_jid", type = "string" }; | |
265 { name = "node_name", type = "string" }; | |
266 }; | |
267 host_selector = "service_jid"; | |
268 | |
269 handler = function (self, service_jid, node_name) --luacheck: ignore 212/self | |
270 return get_service(service_jid):create(node_name, true); | |
271 end; | |
272 }); | |
273 | |
274 module:add_item("shell-command", { | |
275 section = "pubsub"; | |
276 section_desc = "Manage publish/subscribe nodes"; | |
277 name = "list_nodes"; | |
278 desc = "List nodes on a pubsub service"; | |
279 args = { | |
280 { name = "service_jid", type = "string" }; | |
281 }; | |
282 host_selector = "service_jid"; | |
283 | |
284 handler = function (self, service_jid) --luacheck: ignore 212/self | |
285 local service = get_service(service_jid); | |
286 local nodes = select(2, assert(service:get_nodes(true))); | |
287 local count = 0; | |
288 for node_name in pairs(nodes) do | |
289 count = count + 1; | |
290 self.session.print(node_name); | |
291 end | |
292 return true, ("%d nodes"):format(count); | |
293 end; | |
294 }); |