diff --git a/d2m/actions/send-message.js b/d2m/actions/send-message.js index 843ee20..ab5b6c6 100644 --- a/d2m/actions/send-message.js +++ b/d2m/actions/send-message.js @@ -12,8 +12,6 @@ const api = sync.require("../../matrix/api") const registerUser = sync.require("./register-user") /** @type {import("../actions/create-room")} */ const createRoom = sync.require("../actions/create-room") -/** @type {import("../../discord/utils")} */ -const dUtils = sync.require("../../discord/utils") /** * @param {import("discord-api-types/v10").GatewayMessageCreateDispatchData} message @@ -23,7 +21,7 @@ async function sendMessage(message, guild) { const roomID = await createRoom.ensureRoom(message.channel_id) let senderMxid = null - if (!dUtils.isWebhookMessage(message)) { + if (!message.webhook_id) { if (message.member) { // available on a gateway message create event senderMxid = await registerUser.syncUser(message.author, message.member, message.guild_id, roomID) } else { // well, good enough... diff --git a/d2m/converters/edit-to-changes.js b/d2m/converters/edit-to-changes.js index 9d1fc0b..6d4bbdd 100644 --- a/d2m/converters/edit-to-changes.js +++ b/d2m/converters/edit-to-changes.js @@ -24,7 +24,7 @@ async function editToChanges(message, guild, api) { const roomID = select("channel_room", "room_id", {channel_id: message.channel_id}).pluck().get() assert(roomID) /** @type {string?} Null if we don't have a sender in the room, which will happen if it's a webhook's message. The bridge bot will do the edit instead. */ - const senderMxid = from("sim").join("sim_member", "mxid").where({user_id: message.author.id, room_id: roomID}).pluck("mxid").get() || null + const senderMxid = from("sim").join("sim_member", "mxid").where({user_id: message.author.id}).pluck("mxid").get() || null const oldEventRows = select("event_message", ["event_id", "event_type", "event_subtype", "part"], {message_id: message.id}).all() diff --git a/d2m/converters/message-to-event.js b/d2m/converters/message-to-event.js index 09ac39a..3241582 100644 --- a/d2m/converters/message-to-event.js +++ b/d2m/converters/message-to-event.js @@ -194,12 +194,6 @@ async function messageToEvent(message, guild, options = {}, di) { html = "* " + html } - const flags = message.flags || 0 - if (flags & 2) { - body = `[🔀 ${message.author.username}]\n` + body - html = `🔀 ${message.author.username}
` + html - } - // Fallback body/formatted_body for replies // This branch is optional - do NOT change anything apart from the reply fallback, since it may not be run if (repliedToEventRow && options.includeReplyFallback !== false) { diff --git a/d2m/converters/message-to-event.test.js b/d2m/converters/message-to-event.test.js index 19f0111..715aa5d 100644 --- a/d2m/converters/message-to-event.test.js +++ b/d2m/converters/message-to-event.test.js @@ -490,15 +490,3 @@ test("message2event: emoji triple long name", async t => { + ':brillillillilliant_move:' }]) }) - -test("message2event: crossposted announcements say where they are crossposted from", async t => { - const events = await messageToEvent(data.special_message.crosspost_announcement, data.guild.general, {}) - t.deepEqual(events, [{ - $type: "m.room.message", - "m.mentions": {}, - msgtype: "m.text", - body: "[🔀 Chewey Bot Official Server #announcements]\nAll text based commands are now inactive on Chewey Bot\nTo continue using commands you'll need to use them as slash commands", - format: "org.matrix.custom.html", - formatted_body: "🔀 Chewey Bot Official Server #announcements
All text based commands are now inactive on Chewey Bot
To continue using commands you'll need to use them as slash commands" - }]) -}) diff --git a/d2m/discord-packets.js b/d2m/discord-packets.js index dfba8b0..0782702 100644 --- a/d2m/discord-packets.js +++ b/d2m/discord-packets.js @@ -141,6 +141,7 @@ const utils = { await eventDispatcher.onChannelOrThreadUpdate(client, message.d, true) } else if (message.t === "MESSAGE_CREATE") { + console.log(message.d) await eventDispatcher.onMessageCreate(client, message.d) } else if (message.t === "MESSAGE_UPDATE") { diff --git a/discord/utils.js b/discord/utils.js index 8856aa7..2a34008 100644 --- a/discord/utils.js +++ b/discord/utils.js @@ -47,14 +47,4 @@ function getPermissions(userRoles, guildRoles, userID, channelOverwrites) { return allowed } -/** - * Command interaction responses have a webhook_id for some reason, but still have real author info of a real bot user in the server. - * @param {DiscordTypes.APIMessage} message - */ -function isWebhookMessage(message) { - const isInteractionResponse = message.type === 20 - return message.webhook_id && !isInteractionResponse -} - module.exports.getPermissions = getPermissions -module.exports.isWebhookMessage = isWebhookMessage diff --git a/test/data.js b/test/data.js index c36f252..d6abc9d 100644 --- a/test/data.js +++ b/test/data.js @@ -2007,193 +2007,6 @@ module.exports = { }, attachments: [], guild_id: "1100319549670301727" - }, - bridge_echo_webhook: { - webhook_id: "1160692755144654970", - type: 0, - tts: false, - timestamp: "2023-10-09T21:15:58.866000+00:00", - pinned: false, - mentions: [], - mention_roles: [], - mention_everyone: false, - id: "1161049444674973706", - flags: 0, - embeds: [], - edited_timestamp: null, - content: "ready when you are", - components: [], - channel_id: "497161350934560778", - author: { - username: "cadence [they]", - id: "1160692755144654970", - discriminator: "0000", - bot: true, - avatar: "af0ead3b92cf6e448fdad80b4e7fc9e5" - }, - attachments: [], - application_id: "684280192553844747", - guild_id: "497159726455455754" - }, - crosspost_announcement: { - id: "1152745817678028840", - type: 0, - content: "All text based commands are now inactive on Chewey Bot\nTo continue using commands you'll need to use them as slash commands", - channel_id: "500454381414514688", - author: { - id: "748007224353226832", - username: "Chewey Bot Official Server #announcements", - avatar: "427b2893c574b90f1c6bb54da2c609cb", - discriminator: "0000", - public_flags: 0, - flags: 0, - bot: true - }, - attachments: [], - embeds: [], - mentions: [], - mention_roles: [], - pinned: false, - mention_everyone: false, - tts: false, - timestamp: "2023-09-16T23:20:19.916000+00:00", - edited_timestamp: null, - flags: 2, - components: [], - webhook_id: "748007224353226832", - message_reference: { - channel_id: "372274661439832065", - message_id: "1152745799596384263", - guild_id: "372271956562542592" - } - }, - }, - interaction_message: { - thinking_interaction_without_bot_user: { - webhook_id: "1109360903096369153", - type: 20, - tts: false, - timestamp: "2023-10-09T21:16:11.673000+00:00", - pinned: false, - nonce: "1161049469261709312", - mentions: [], - mention_roles: [], - mention_everyone: false, - interaction: { - user: { - username: "papiophidian", - public_flags: 4194880, - id: "320067006521147393", - global_name: "PapiOphidian", - discriminator: "0", - avatar_decoration_data: null, - avatar: "5fc4ad85c1ea876709e9a7d3374a78a1" - }, - type: 2, - name: "stats", - member: { - roles: [], - premium_since: null, - pending: false, - nick: "Brad", - mute: false, - joined_at: "2018-10-03T21:35:50.974000+00:00", - flags: 0, - deaf: false, - communication_disabled_until: null, - avatar: null - }, - id: "1161049497724534825" - }, - id: "1161049498391425196", - flags: 128, - embeds: [], - edited_timestamp: null, - content: "", - components: [], - channel_id: "497161350934560778", - author: { - username: "Amanda 🎵", - public_flags: 524288, - id: "1109360903096369153", - global_name: null, - discriminator: "2192", - bot: true, - avatar_decoration_data: null, - avatar: "e4a45abe5f8ee44f0b59b79a08bdb2ac" - }, - attachments: [], - application_id: "1109360903096369153", - guild_id: "497159726455455754" - }, - thinking_interaction: { - webhook_id: "1109360903096369153", - type: 20, - tts: false, - timestamp: "2023-10-09T21:18:45.002000+00:00", - pinned: false, - nonce: "1161050112089128960", - mentions: [], - mention_roles: [], - mention_everyone: false, - member: { - roles: [ "604073998749270046" ], - premium_since: null, - pending: false, - nick: null, - mute: false, - joined_at: "2023-10-09T21:18:30.600000+00:00", - flags: 1, - deaf: false, - communication_disabled_until: null, - avatar: null - }, - interaction: { - user: { - username: "papiophidian", - public_flags: 4194880, - id: "320067006521147393", - global_name: "PapiOphidian", - discriminator: "0", - avatar_decoration_data: null, - avatar: "5fc4ad85c1ea876709e9a7d3374a78a1" - }, - type: 2, - name: "stats", - member: { - roles: [], - premium_since: null, - pending: false, - nick: "Brad", - mute: false, - joined_at: "2018-10-03T21:35:50.974000+00:00", - flags: 0, - deaf: false, - communication_disabled_until: null, - avatar: null - }, - id: "1161050140640018472" - }, - id: "1161050141499863120", - flags: 128, - embeds: [], - edited_timestamp: null, - content: "", - components: [], - channel_id: "497161350934560778", - author: { - username: "Amanda 🎵", - public_flags: 524288, - id: "1109360903096369153", - global_name: null, - discriminator: "2192", - bot: true, - avatar_decoration_data: null, - avatar: "e4a45abe5f8ee44f0b59b79a08bdb2ac" - }, - attachments: [], - application_id: "1109360903096369153", - guild_id: "497159726455455754" } } }