Compare commits

...

3 Commits
v2.1 ... main

5 changed files with 48 additions and 6 deletions

View File

@ -244,6 +244,8 @@ module.exports = {
if (row) return // The message was sent by the bridge's own webhook on discord. We don't want to reflect this back, so just drop it.
}
if (dUtils.isEphemeralMessage(message)) return // Ephemeral messages are for the eyes of the receiver only!
const {affected, row} = await speedbump.maybeDoSpeedbump(message.channel_id, message.id)
if (affected) return
@ -262,6 +264,8 @@ module.exports = {
if (row) return // The message was sent by the bridge's own webhook on discord. We don't want to reflect this back, so just drop it.
}
if (dUtils.isEphemeralMessage(data)) return // Ephemeral messages are for the eyes of the receiver only!
// Edits need to go through the speedbump as well. If the message is delayed but the edit isn't, we don't have anything to edit from.
const {affected, row} = await speedbump.maybeDoSpeedbump(data.channel_id, data.id)
if (affected) return

View File

@ -101,6 +101,14 @@ function isWebhookMessage(message) {
return message.webhook_id && !isInteractionResponse
}
/**
* Ephemeral messages can be generated if a slash command is attached to the same bot that OOYE is running on
* @param {DiscordTypes.APIMessage} message
*/
function isEphemeralMessage(message) {
return message.flags & (1 << 6);
}
/** @param {string} snowflake */
function snowflakeToTimestampExact(snowflake) {
return Number(BigInt(snowflake) >> 22n) + EPOCH
@ -116,5 +124,6 @@ module.exports.hasPermission = hasPermission
module.exports.hasSomePermissions = hasSomePermissions
module.exports.hasAllPermissions = hasAllPermissions
module.exports.isWebhookMessage = isWebhookMessage
module.exports.isEphemeralMessage = isEphemeralMessage
module.exports.snowflakeToTimestampExact = snowflakeToTimestampExact
module.exports.timestampToSnowflakeInexact = timestampToSnowflakeInexact

View File

@ -16,7 +16,7 @@ async function deleteMessage(event) {
db.prepare("DELETE FROM event_message WHERE event_id = ?").run(event.event_id)
for (const row of rows) {
db.prepare("DELETE FROM message_channel WHERE message_id = ?").run(row.message_id)
discord.snow.channel.deleteMessage(row.channel_id, row.message_id, event.content.reason)
await discord.snow.channel.deleteMessage(row.channel_id, row.message_id, event.content.reason)
}
}

View File

@ -54,16 +54,17 @@ const turndownService = new TurndownService({
*/
// @ts-ignore bad type from turndown
turndownService.escape = function (string) {
const escapedWords = string.split(" ").map(word => {
if (word.match(/^https?:\/\//)) {
return word
return string.replace(/\s+|\S+/g, part => { // match chunks of spaces or non-spaces
if (part.match(/\s/)) return part // don't process spaces
if (part.match(/^https?:\/\//)) {
return part
} else {
return markdownEscapes.reduce(function (accumulator, escape) {
return accumulator.replace(escape[0], escape[1])
}, word)
}, part)
}
})
return escapedWords.join(" ")
}
turndownService.remove("mx-reply")

View File

@ -205,6 +205,34 @@ test("event2message: links in plaintext body are not broken", async t => {
)
})
test("event2message: links in plaintext body are not broken when preceded by a newline", async t => {
t.deepEqual(
await eventToMessage({
type: "m.room.message",
sender: "@cadence:cadence.moe",
content: {
msgtype: "m.text",
body: "java redstoners will be like \"I hate bedrock edition redstone!!\" meanwhile java edition:\nhttps://youtu.be/g_ORb7bN3CM"
},
event_id: "$b1c5gJZfh1gq3zz6UkhI1whJ61JVvgvvzbdSPEYnTbY",
room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe"
}),
{
ensureJoined: [],
messagesToDelete: [],
messagesToEdit: [],
messagesToSend: [{
username: "cadence [they]",
content: "java redstoners will be like \"I hate bedrock edition redstone!!\" meanwhile java edition:\nhttps://youtu.be/g_ORb7bN3CM",
avatar_url: undefined,
allowed_mentions: {
parse: ["users", "roles"]
}
}]
}
)
})
test("event2message: links in formatted body where the text & href are the same, just post the link once", async t => {
t.deepEqual(
await eventToMessage({