diff --git a/src/renderer/apis/commands.ts b/src/renderer/apis/commands.ts index a6cc8742b..9aac7efed 100644 --- a/src/renderer/apis/commands.ts +++ b/src/renderer/apis/commands.ts @@ -13,8 +13,12 @@ import type { } from "../../types"; // eslint-disable-next-line no-duplicate-imports import { ApplicationCommandOptionType } from "../../types"; +import type { + SendMessageForReplyOptions, + SendMessageOptionsForReply, +} from "../modules/common/messages"; import icon from "../assets/logo.png"; -import { constants, i18n, messages, users } from "../modules/common"; +import { constants, fluxDispatcher, i18n, messages, users } from "../modules/common"; import type { Store } from "../modules/common/flux"; import { Logger } from "../modules/logger"; import { filters, getByStoreName, waitForModule } from "../modules/webpack"; @@ -99,7 +103,17 @@ async function executeCommand( command: RepluggedCommand, ): Promise { try { + const PendingReplyStore = getByStoreName< + Store & { + getPendingReply: (channelId: string) => SendMessageForReplyOptions; + } + >("PendingReplyStore")!; + const currentChannelId = currentInfo.channel.id; + const replyOptions: SendMessageOptionsForReply = messages.getSendMessageOptionsForReply( + PendingReplyStore.getPendingReply(currentChannelId), + ); + const loadingMessage = messages.createBotMessage({ channelId: currentChannelId, content: "", @@ -132,12 +146,19 @@ async function executeCommand( if ((!result?.result && !result?.embeds) || !currentChannelId) return; if (result.send) { - void messages.sendMessage(currentChannelId, { - content: result.result!, - invalidEmojis: [], - validNonShortcutEmojis: [], - tts: false, - }); + if (replyOptions.messageReference) + fluxDispatcher.dispatch({ type: "DELETE_PENDING_REPLY", channelId: currentChannelId }); + void messages.sendMessage( + currentChannelId, + { + content: result.result!, + invalidEmojis: [], + validNonShortcutEmojis: [], + tts: false, + }, + undefined, + replyOptions, + ); } else { const botMessage = messages.createBotMessage({ channelId: currentChannelId, diff --git a/src/renderer/modules/common/messages.ts b/src/renderer/modules/common/messages.ts index 22e3d000b..8c5c62bb5 100644 --- a/src/renderer/modules/common/messages.ts +++ b/src/renderer/modules/common/messages.ts @@ -60,14 +60,14 @@ interface FocusMessageOptions { messageId: string; } -interface SendMessageForReplyOptions { +export interface SendMessageForReplyOptions { channel: Channel; message: Message; shouldMention: boolean; showMentionToggle: boolean; } -interface SendMessageOptionsForReply { +export interface SendMessageOptionsForReply { messageReference?: MessageReference; allowedMentions?: AllowedMentions; }