# HG changeset patch # User ephraim@errorm.fritz.box # Date 1253903594 -7200 # Node ID 2be8bcce5b1832d257722ee635439d6052e7f3b1 # Parent 10502594a49ba6e2752c75b6262b1f81f80780d4 thx to Florob: add remove_item support to mod_addhoc and reload support to mod_adhoc_cmd_ping the returned pong shows the time in the note diff -r 10502594a49b -r 2be8bcce5b18 mod_adhoc/mod_adhoc.lua --- a/mod_adhoc/mod_adhoc.lua Fri Sep 25 16:56:50 2009 +0200 +++ b/mod_adhoc/mod_adhoc.lua Fri Sep 25 20:33:14 2009 +0200 @@ -39,3 +39,14 @@ module:hook("item-added/adhoc", function (event) commands[ # commands + 1] = event.item; end, 500); + +local _G = _G; +local t_remove = _G.table.remove; +module:hook("item-removed/adhoc", function (event) + module:log("debug", "Remove function called"); + for i = 1, #commands do + if commands[i].node == event.item.node then + t_remove(commands, i); + end + end +end, 500); diff -r 10502594a49b -r 2be8bcce5b18 mod_adhoc_cmd_ping/mod_adhoc_cmd_ping.lua --- a/mod_adhoc_cmd_ping/mod_adhoc_cmd_ping.lua Fri Sep 25 16:56:50 2009 +0200 +++ b/mod_adhoc_cmd_ping/mod_adhoc_cmd_ping.lua Fri Sep 25 20:33:14 2009 +0200 @@ -7,10 +7,18 @@ local st = require "util.stanza"; function ping_command_handler (item, origin, stanza) - local now = os.date("%Y-%m-%dT%X") + local now = os.date("%Y-%m-%dT%X"); origin.send(st.reply(stanza):tag("command", {xmlns="http://jabber.org/protocol/commands", status="completed", node=item.node, sessionid=now}) - :tag("note", {type="info"}):text(item.name)); + :tag("note", {type="info"}):text("Pong\n" .. now)); return true; end -module:add_item ("adhoc", { name="Ping", node="ping", handler=ping_command_handler }); +local descriptor = { name="Ping", node="ping", handler=ping_command_handler }; + +function module.unload() + module:log("debug", "Removing ping command"); + module:remove_item("adhoc", descriptor); +end + +module:add_item ("adhoc", descriptor); +