feat: express responses

This commit is contained in:
TresAbhi committed 2023-06-27 01:43:30 +00:00
1 parent 0f46f333b5
commit f2ae698438
45 files changed
+153 -93

No files matched your search

@@ -8,24 +8,24 @@ import {
import negativeEmbed from '../../../core/interaction/negativeEmbed.js';
import normalizeInteractionReturnable from '../../../core/interaction/normalizeInteractionReturnable.js';
import warningEmbed from '../../../core/interaction/warningEmbed.js';
import { psa } from '../../../core/process/psa.js';
import { psa } from '../../../core/node/psa.js';
import { handleError } from '../../error.js';
import { commands } from '../index.js';
export default async function handleChatInputCommand(
interaction: ChatInputCommandInteraction<CacheType>,
) {
const command = commands[interaction.commandName];
const registry = commands[interaction.commandName];
console.log(interaction.toString());
await interaction.deferReply();
try {
const returnable = await command.execute(interaction);
const returnable = await registry.handler(interaction);
if (command.handlesInteraction) return;
if (registry.handlesInteraction) return;
const reply = await normalizeInteractionReturnable(returnable!);
const reply = await normalizeInteractionReturnable(returnable);
if (psa.data) {
if (!reply.embeds) reply.embeds = [];
+14 -17
View File
@@ -28,9 +28,9 @@ import searchtanks from '../../commands/searchtanks.js';
import stats from '../../commands/stats.js';
import today from '../../commands/today.js';
import verify from '../../commands/verify.js';
import { DISCORD_TOKEN } from '../../core/process/args.js';
import getClientId from '../../core/process/getClientId.js';
import isDev from '../../core/process/isDev.js';
import { DISCORD_TOKEN } from '../../core/node/args.js';
import getClientId from '../../core/node/getClientId.js';
import isDev from '../../core/node/isDev.js';
import handleAutocomplete from './handlers/autocomplete.js';
import handleButton from './handlers/button.js';
import handleChatInputCommand from './handlers/chatInputCommand.js';
@@ -46,29 +46,26 @@ export type InteractionReturnable =
| InteractionIterableReturnable
| Promise<InteractionIterableReturnable>;
export type CommandRegistry = {
export interface Registry {
inDevelopment: boolean;
inProduction: boolean;
inPublic: boolean;
}
export interface CommandRegistry<HandlesInteraction extends boolean = false>
extends Registry {
inPublic: boolean;
handlesInteraction?: HandlesInteraction;
command:
| SlashCommandBuilder
| SlashCommandSubcommandsOnlyBuilder
| Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>;
handler: (
interaction: ChatInputCommandInteraction<CacheType>,
) => HandlesInteraction extends true ? void : InteractionReturnable;
autocomplete?: (interaction: AutocompleteInteraction<CacheType>) => void;
button?: (interaction: ButtonInteraction<CacheType>) => InteractionReturnable;
} & (
| {
handlesInteraction?: false;
execute: (
interaction: ChatInputCommandInteraction<CacheType>,
) => InteractionReturnable;
}
| {
handlesInteraction: true;
execute: (interaction: ChatInputCommandInteraction<CacheType>) => void;
}
);
}
const rest = new REST().setToken(DISCORD_TOKEN);