plugins/msgforward.lua

1
function riddim.plugins.msgforward(bot)
2
	local compare_jid = require "prosody.util.jid".compare;
3
	local st_clone = require "prosody.util.stanza".clone;
4
	local forwards = bot.config.forwards or {};
5
 
6
	bot:hook("message", function(event)
7
		local message = event.stanza;
8
		local from = message.attr.from;
9
		local body = message:get_child("body");
10
		body = body and body:get_text();
11
		if not body then return end
12
		for jid, room in pairs(forwards) do
13
			if compare_jid(from, jid) and bot.rooms[room] then
14
				local out = st_clone(message);
15
				out.attr.to, out.attr.from, out.attr.type = nil, nil, "groupchat";
16
				bot.rooms[room]:send(out);
17
				return true;
18
			end
19
		end
20
	end);
21
end