Software /
code /
prosody-modules
Annotate
mod_adhoc/adhoc/mod_adhoc.lua @ 40:4c4daa1f8ae7
mod_adhoc_cmd_admin: Add Get List of Online Users command
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Wed, 14 Oct 2009 00:52:58 +0200 |
parent | 36:58d326d86a9a |
child | 43:adc9eff8adb2 |
rev | line source |
---|---|
6 | 1 -- Copyright (C) 2009 Thilo Cestonaro |
2 -- | |
3 -- This file is MIT/X11 licensed. Please see the | |
4 -- COPYING file in the source package for more information. | |
5 -- | |
6 | |
7 local st = require "util.stanza"; | |
8 local commands = {}; | |
9 | |
10 module:add_feature("http://jabber.org/protocol/commands"); | |
11 | |
12 module:hook("iq/host/http://jabber.org/protocol/disco#items:query", function (event) | |
13 local origin, stanza = event.origin, event.stanza; | |
14 if stanza.attr.type == "get" and stanza.tags[1].attr.node and stanza.tags[1].attr.node == "http://jabber.org/protocol/commands" then | |
15 reply = st.reply(stanza); | |
16 reply:tag("query", {xmlns="http://jabber.org/protocol/disco#items", node="http://jabber.org/protocol/commands"}) | |
17 for i = 1, #commands do | |
18 -- module:log("info", "adding command %s", commands[i].name); | |
28
b9d063dd16d5
mod_adhoc, mod_adhoc_cmd_ping: Code cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
9
diff
changeset
|
19 reply:tag("item", {name=commands[i].name, node=commands[i].node, jid=module:get_host()}); |
6 | 20 reply:up(); |
21 end | |
22 origin.send(reply); | |
23 return true; | |
24 end | |
25 end, 500); | |
26 | |
27 module:hook("iq/host", function (event) | |
28 local origin, stanza = event.origin, event.stanza; | |
29 if stanza.attr.type == "set" and stanza.tags[1] and stanza.tags[1].name == "command" then | |
30 local node = stanza.tags[1].attr.node | |
31 for i = 1, #commands do | |
32 if commands[i].node == node then | |
33 return commands[i].handler(commands[i], origin, stanza); | |
34 end | |
35 end | |
36 end | |
37 end, 500); | |
38 | |
39 module:hook("item-added/adhoc", function (event) | |
40 commands[ # commands + 1] = event.item; | |
41 end, 500); | |
9 | 42 |
43 local _G = _G; | |
44 local t_remove = _G.table.remove; | |
45 module:hook("item-removed/adhoc", function (event) | |
46 for i = 1, #commands do | |
47 if commands[i].node == event.item.node then | |
48 t_remove(commands, i); | |
28
b9d063dd16d5
mod_adhoc, mod_adhoc_cmd_ping: Code cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
9
diff
changeset
|
49 break; |
9 | 50 end |
51 end | |
52 end, 500); |