plugins/msgforward.lua

Mon, 06 Dec 2021 11:27:16 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Mon, 06 Dec 2021 11:27:16 +0000
changeset 167
2073137bc943
parent 54
4dcb349bb667
permissions
-rw-r--r--

rtbl_admin: Notify subscribers on item removal (requires verse 98dc1750584d)

53
6e9f9fd3f64b plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 function riddim.plugins.msgforward(bot)
6e9f9fd3f64b plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local compare_jid = require "util.jid".compare;
54
4dcb349bb667 plugins.msgforward: Clone messages, not just the body.
Kim Alvefur <zash@zash.se>
parents: 53
diff changeset
3 local st_clone = require "util.stanza".clone;
53
6e9f9fd3f64b plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local forwards = bot.config.forwards or {};
54
4dcb349bb667 plugins.msgforward: Clone messages, not just the body.
Kim Alvefur <zash@zash.se>
parents: 53
diff changeset
5
53
6e9f9fd3f64b plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 bot:hook("message", function(event)
6e9f9fd3f64b plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 local message = event.stanza;
6e9f9fd3f64b plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 local from = message.attr.from;
6e9f9fd3f64b plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 local body = message:get_child("body");
6e9f9fd3f64b plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 body = body and body:get_text();
6e9f9fd3f64b plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 if not body then return end
6e9f9fd3f64b plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 for jid, room in pairs(forwards) do
6e9f9fd3f64b plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 if compare_jid(from, jid) and bot.rooms[room] then
54
4dcb349bb667 plugins.msgforward: Clone messages, not just the body.
Kim Alvefur <zash@zash.se>
parents: 53
diff changeset
14 local out = st_clone(message);
4dcb349bb667 plugins.msgforward: Clone messages, not just the body.
Kim Alvefur <zash@zash.se>
parents: 53
diff changeset
15 out.attr.to, out.attr.from, out.attr.type = nil, nil, "groupchat";
4dcb349bb667 plugins.msgforward: Clone messages, not just the body.
Kim Alvefur <zash@zash.se>
parents: 53
diff changeset
16 bot.rooms[room]:send(out);
53
6e9f9fd3f64b plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 return true;
6e9f9fd3f64b plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 end
6e9f9fd3f64b plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 end
6e9f9fd3f64b plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 end);
6e9f9fd3f64b plugins.msgforward: New plugin that forwards messages to rooms based on sender.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 end

mercurial