From b06c2aacc2c13330f38e4015d89012815b513e23 Mon Sep 17 00:00:00 2001 From: Tharki-God Date: Sun, 23 Jun 2024 14:13:22 +0530 Subject: [PATCH] reply to message --- src/renderer/apis/commands.ts | 36 ++++++++++++++++++++----- src/renderer/modules/common/messages.ts | 4 +-- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/renderer/apis/commands.ts b/src/renderer/apis/commands.ts index fbd7f4f8e..7b90b70e1 100644 --- a/src/renderer/apis/commands.ts +++ b/src/renderer/apis/commands.ts @@ -12,11 +12,16 @@ import type { } from "../../types"; // eslint-disable-next-line no-duplicate-imports import { ApplicationCommandOptionType } from "../../types"; -import { constants, i18n, messages, users } from "../modules/common"; +import { constants, i18n, messages, users, fluxDispatcher } from "../modules/common"; +import type { + SendMessageForReplyOptions, + SendMessageOptionsForReply, +} from "../modules/common/messages"; import type { Store } from "../modules/common/flux"; import { Logger } from "../modules/logger"; import { filters, getByStoreName, waitForModule } from "../modules/webpack"; import icon from "../assets/logo.png"; + const logger = Logger.api("Commands"); let RepluggedUser: User | undefined; @@ -97,7 +102,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: "", @@ -130,12 +145,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; }