Thumbnail

rani/matterbridge.git

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

commit 1c90ba40930ad7203674a2c80f0f3e6a7495c36d Author: rani <clagv.randomgames@gmail.com> Date: Mon Mar 16 15:41:08 2026 +0000 separate reply input parsing from reply output diff --git a/scripts/inmessage.tengo b/scripts/inmessage.tengo new file mode 100644 index 0000000..486c2ef --- /dev/null +++ b/scripts/inmessage.tengo @@ -00 +150 @@ +/* +variables available +read-only: + msgUserID, msgAccount, msgChannel, msgProtocol + +read-write: + msgText, msgUsername +*/ + +fmt := import("fmt") +text := import("text") + +doQuote_ := func(reply, nick, ctx) { + return reply + " (in reply to " + nick + ": " + ctx + ")" +} + +stripQuote := func(ctx) { + re := text.re_compile(`(?m)^> (?:-# )?↪ .+\n(?:> .*\n)+(.*)`) + return re.replace(ctx, "$1") +} + +doQuote := func(...reStrs) { + for reStr in reStrs { + re := text.re_compile(reStr) + if re.match(msgText) { + reply := re.replace(msgText, "$1") + nick := re.replace(msgText, "$2") + ctx := re.replace(msgText, "$3") + ctx = stripQuote(ctx) + msgText = doQuote_(reply, nick, ctx) + break + } + } +} + +if msgText != "" { + if msgProtocol == "discord" { + doQuote(`(?ms)(.*?) \(in reply to (.*?): (.*?)\)$`) + } else if msgProtocol == "xmpp" { + doQuote( + `(?ms)(.*?) \(in reply to (.*?) \[b]: (.*?)\)$`, + `(?ms)(.*?) \(in reply to (.*?): (.*?)\)$` + ) + } else if msgProtocol == "telegram" { + doQuote( + `(?ms)(.*?) \(in reply to lulbridge: <([^>]+)> (.*?)\)$`, + `(?ms)(.*?) \(in reply to (.*?): (.*?)\)$` + ) + } +} diff --git a/scripts/outmessage.tengo b/scripts/outmessage.tengo index 8bea57d..30b5dd4 100644 --- a/scripts/outmessage.tengo +++ b/scripts/outmessage.tengo @@ -2125 +2111 @@ doQuote_ := func(reply, nick, ctx) { return prefix + nick + "\n> " + ctx + "\n" + reply - } else if outProtocol == "irc" || - outProtocol == "telegram" || - outProtocol == "matrix" { - ctx = text.join(text.split(ctx, "\n"), " ") - return reply + " (in reply to " + nick + ": " + ctx + ")" } else { return msgText }  }   -stripQuote := func(ctx) { - // > ↪ NICK - // > ... - // > ... - // ctx - re := text.re_compile(`(?m)^> (?:-# )?↪ .+\n(?:> .*\n)+(.*)`) - return re.replace(ctx, "$1") -} -  // match $1 must be the reply  // match $2 must be the nick  // match $3 must be the context @@ -507 +366 @@ doQuote := func(...reStrs) { reply := re.replace(msgText, "$1") nick := re.replace(msgText, "$2") ctx := re.replace(msgText, "$3") - ctx = stripQuote(ctx) msgText = doQuote_(reply, nick, ctx) break } @@ -7421 +595 @@ if (inProtocol == "discord" && outProtocol != "discord") { msgText=reGIF.replace(msgText,"https://cdn.discordapp.com/emojis/$1.gif")  }   -// format discord replies as quotes on xmpp -if (inProtocol == "discord") { - doQuote(`(?ms)(.*?) \(in reply to (.*?): (.*?)\)$`) -} - -if (inProtocol == "xmpp") { - doQuote( - `(?ms)(.*?) \(in reply to (.*?) \[b]: (.*?)\)$`, - `(?ms)(.*?) \(in reply to (.*?): (.*?)\)$` - ) -} - -if (inProtocol == "telegram") { - doQuote( - `(?ms)(.*?) \(in reply to lulbridge: <([^>]+)> (.*?)\)$`, - `(?ms)(.*?) \(in reply to (.*?): (.*?)\)$` - ) -} +// format replies from all protocols to all protocols +doQuote(`(?ms)(.*?) \(in reply to (.*?): (.*?)\)$`)