From b6b65992f70622bda27de7d1984f3d0ee0a5f8c5 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Tue, 14 May 2024 23:07:54 +1200 Subject: [PATCH 1/2] Forward redaction errors to error handler --- m2d/actions/redact.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/m2d/actions/redact.js b/m2d/actions/redact.js index 26a7142..7569df4 100644 --- a/m2d/actions/redact.js +++ b/m2d/actions/redact.js @@ -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) } } From 1f5865b0d8a14ba56b07cc1d4f94c5e57ed058c4 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Tue, 14 May 2024 23:09:51 +1200 Subject: [PATCH 2/2] Avoid sending ephemeral messages from Discord --- d2m/event-dispatcher.js | 4 ++++ discord/utils.js | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/d2m/event-dispatcher.js b/d2m/event-dispatcher.js index 54d858a..ec04750 100644 --- a/d2m/event-dispatcher.js +++ b/d2m/event-dispatcher.js @@ -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 diff --git a/discord/utils.js b/discord/utils.js index 2726a1a..c7045ec 100644 --- a/discord/utils.js +++ b/discord/utils.js @@ -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