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