Mercurial > prosody-modules
comparison mod_adhoc/mod_adhoc.lua @ 6:d497d5df360d
adds mod_adhoc
| author | Thilo Cestonaro <thilo@cestona.ro> |
|---|---|
| date | Fri, 25 Sep 2009 16:31:33 +0200 |
| parents | |
| children | 2be8bcce5b18 |
comparison
equal
deleted
inserted
replaced
| 5:9c1c6c5344dc | 6:d497d5df360d |
|---|---|
| 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); | |
| 19 reply:tag("item", {name=commands[i].name, node=commands[i].node, jid=module:get_host()}); | |
| 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); |
