Skip to content

Commit

Permalink
reply to message
Browse files Browse the repository at this point in the history
  • Loading branch information
yofukashino committed Jun 23, 2024
1 parent 5d43dce commit b06c2aa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
36 changes: 29 additions & 7 deletions src/renderer/apis/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Check warning on line 15 in src/renderer/apis/commands.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Member 'fluxDispatcher' of the import declaration should be sorted alphabetically
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;
Expand Down Expand Up @@ -97,7 +102,17 @@ async function executeCommand<T extends CommandOptions>(
command: RepluggedCommand<T>,
): Promise<void> {
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: "",
Expand Down Expand Up @@ -130,12 +145,19 @@ async function executeCommand<T extends CommandOptions>(
if ((!result?.result && !result?.embeds) || !currentChannelId) return;

if (result.send) {
void messages.sendMessage(currentChannelId, {
content: result.result!,
invalidEmojis: [],
validNonShortcutEmojis: [],
tts: false,
});
if (replyOptions?.messageReference)

Check warning on line 148 in src/renderer/apis/commands.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unnecessary optional chain on a non-nullish value
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,
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/modules/common/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit b06c2aa

Please sign in to comment.