Comparison of all the stuff I did. #6

Merged
Guzio merged 48 commits from fuckery into main 2026-03-02 15:17:09 +00:00
2 changed files with 18 additions and 8 deletions
Showing only changes of commit f734b0619f - Show all commits

View file

@ -211,7 +211,16 @@ async event => {
if (utils.eventSenderIsFromDiscord(event.sender)) return
const messageResponses = await sendEvent.sendEvent(event)
if (!messageResponses.length) return
if (event.content["m.relates_to"]?.rel_type === "m.thread"){
/** @type {string|undefined} */
let executedCommand
if (event.type === "m.room.message" && event.content.msgtype === "m.text") {
executedCommand = await matrixCommandHandler.parseAndExecute(
// @ts-ignore - TypeScript doesn't know that the event.content.msgtype === "m.text" ensures that event isn't of type Ty.Event.Outer_M_Room_Message_File (which, indeed, wouldn't fit here)
event
)
}
if (event.content["m.relates_to"]?.rel_type === "m.thread" && executedCommand !== "thread"){
api.sendEvent(event.room_id, "m.room.message", {
"body": "⚠️ **This message may not have bridged to Discord in the way you thought it would!**\n\nIt seems like you sent this message inside a Matrix thread. Matrix threads don't work like Discord threads - they are effectively just „fancy replies”, not independent rooms/channels (any „thread-like appearance” is handled purely client-side - and even then, most Matrix clients don't handle it particularly well), and as such, they are bridged as replies to Discord. _Discord users will not be aware that you sent this message inside a thread - it will go directly onto the main channel. If the thread you sent this message in is old, such a random reply may be distracting to Discord users!_\n\nFor the sake of Discord parity (as well as better support in numerous Matrix clients - as stated above, most Matrix clients don't handle threads particularly well, and they just render in-thread messages as fancy replies), it is recommended to send threaded messages inside a separate Matrix room that gets bridged to Discord. If you sent this message in a pre-existing Matrix thread, please look around to see if anyone has created such a room for it. If this is the first message (ie. the thread was just created) or noone's made a thread-room for this thread, it is recommended you create one with `/thread <Thread Name>` (on Matrix) and continue the conversation there.\n\n*You can read more about the rationale behind this design choice [here](https://gitdab.com/cadence/out-of-your-element/src/branch/main/docs/threads-as-rooms.md).*",
"format": "org.matrix.custom.html",
@ -226,10 +235,7 @@ async event => {
"msgtype": "m.text"
})
}
if (event.type === "m.room.message" && event.content.msgtype === "m.text") {
// @ts-ignore
await matrixCommandHandler.execute(event)
}
retrigger.messageFinishedBridging(event.event_id)
await api.ackEvent(event)
}))

View file

@ -274,8 +274,11 @@ const commands = [{
}]
/** @type {CommandExecute} */
async function execute(event) {
/**
* @param {Ty.Event.Outer_M_Room_Message} event
* @returns {Promise<string|undefined>} the executed command's name or undefined if no command execution was performed
*/
async function parseAndExecute(event) {
let realBody = event.content.body
while (realBody.startsWith("> ")) {
const i = realBody.indexOf("\n")
@ -296,7 +299,8 @@ async function execute(event) {
if (!command) return
await command.execute(event, realBody, words)
return words[0]
}
module.exports.execute = execute
module.exports.parseAndExecute = parseAndExecute
module.exports.onReactionAdd = onReactionAdd