Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slash Command Reply #633

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions src/renderer/apis/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -99,7 +103,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 @@ -132,12 +146,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)
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