Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit 6bab3371812e0684a560b14add9660274ed721bc Author: rani <clagv.randomgames@gmail.com> Date: Tue Feb 17 20:00:24 2026 +0000 add outmessage.tengo diff --git a/scripts/outmessage.tengo b/scripts/outmessage.tengo new file mode 100644 index 0000000..c2ce556 --- /dev/null +++ b/scripts/outmessage.tengo @@ -00 +167 @@ +/* +variables available +read-only: + inAccount, inProtocol, inChannel, inGateway, inEvent + outAccount, outProtocol, outChannel, outGateway, outEvent + msgUserID + +read-write: + msgDrop, msgText, msgUsername +*/ + +text := import("text") +fmt := import("fmt") + +doQuote := func(reply, nick, ctx) { + if outProtocol == "xmpp" || outProtocol == "discord" { + // split multiline context and prepend lines with a ">" + ctx = text.join(text.split(ctx, "\n"), "\n> ") + + return "↪ " + nick + + "\n> " + ctx + "\n" + + reply + } else if outProtocol == "irc" || outProtocol == "telegram" { + ctx = text.join(text.split(ctx, "\n"), " ") + return reply + " (in reply to " + nick + ": " + ctx + ")" + } else { + return msgText + } +} + +// start - strip irc colors +// if we're not sending to an irc bridge we strip the IRC colors +if inProtocol == "irc" && outProtocol != "irc" { + re := text.re_compile(`\x03(?:\d{1,2}(?:,\d{1,2})?)?|[[:cntrl:]]`) + msgText=re.replace(msgText,"") +} +// end - strip irc colors + +// if we're not sending to a discord bridge, +// then convert custom emoji tags into url's +if (inProtocol == "discord" && outProtocol != "discord") { + rePNG := text.re_compile(`<:.*?:([0-9]+)>`) + msgText=rePNG.replace(msgText,"https://cdn.discordapp.com/emojis/$1.png") + reGIF := text.re_compile(`<a:.*?:([0-9]+)>`) + msgText=reGIF.replace(msgText,"https://cdn.discordapp.com/emojis/$1.gif") +} + +// format discord replies as quotes on xmpp +if (inProtocol == "discord" && outProtocol != "discord") { + re := text.re_compile(`(?ms)(.*?) \(in reply to (.*?): (.*?)\)$`) + if re.match(msgText) { + reply := re.replace(msgText, "$1") + nick := re.replace(msgText, "$2") + ctx := re.replace(msgText, "$3") + msgText = doQuote(reply, nick, ctx) + } +} + +if (inProtocol == "telegram" && outProtocol != "telegram") { + re := text.re_compile(`(?ms)(.*?) \(in reply to (.*?): <([^>]+)> (.*?)\)$`) + if re.match(msgText) { + reply := re.replace(msgText, "$1") + nick := re.replace(msgText, "$3") + ctx := re.replace(msgText, "$4") + msgText = doQuote(reply, nick, ctx) + } +}