Files
2022-09-22 05:42:39 +02:00

45 lines
1.4 KiB
Lua

-- Copyright (C) 2015 Travis Burtrum
-- This file is MIT/X11 licensed.
-- set like so in prosody config, works on full or bare jids, or hosts:
--aliases = {
-- ["old@example.net"] = "new@example.net";
-- ["you@example.com"] = "you@example.net";
-- ["conference.example.com"] = "conference.example.net";
--}
local aliases = module:get_option("aliases", {});
local bcaddr = module:get_option("bc_prefix", "");
local alias_response = module:get_option("alias_response", "User $alias can be contacted at $target");
local st = require "util.stanza";
local jid_split = require "util.jid".split;
local function starts_with(str, start)
return str:sub(1, #start) == start
end
function handle_alias(event)
if ((event.stanza.attr.type ~= "error") and (event.stanza.attr.type == "normal")) then
local alias = event.stanza.attr.to;
local forward_stanza = event.stanza;
-- module:log("info", "alias handling - checking %s", alias);
local tonode, tohost = jid_split(alias);
if tonode ~= nil then
if starts_with(tonode, "broadcast-") then
module:log("info", "determined %s as broadcast", alias);
local target = "broadcast@"..tohost;
forward_stanza.attr.to = target;
forward_stanza.attr.origtarget = alias;
module:send(forward_stanza);
end
end
end
end
module:hook("message/bare", handle_alias, 300);
module:hook("message/full", handle_alias, 300);
module:hook("message/host", handle_alias, 300);