plugins/msgforward.lua

Sat, 08 Jan 2011 11:58:39 +0100

author
Kim Alvefur <zash@zash.se>
date
Sat, 08 Jan 2011 11:58:39 +0100
changeset 53
6e9f9fd3f64b
child 54
4dcb349bb667
permissions
-rw-r--r--

plugins.msgforward: New plugin that forwards messages to rooms based on sender.

function riddim.plugins.msgforward(bot)
	local compare_jid = require "util.jid".compare;
	local forwards = bot.config.forwards or {};
	bot:hook("message", function(event)
		local message = event.stanza;
		local from = message.attr.from;
		local body = message:get_child("body");
		body = body and body:get_text();
		if not body then return end
		for jid, room in pairs(forwards) do
			if compare_jid(from, jid) and bot.rooms[room] then
				bot.rooms[room]:send_message(body);
				return true;
			end
		end
	end);
end

mercurial