From 2e680f557faa98a69841d21b1e3f037f25ae496b Mon Sep 17 00:00:00 2001 From: MARCROCK22 <57925328+MARCROCK22@users.noreply.github.com> Date: Sat, 18 May 2024 14:17:51 -0400 Subject: [PATCH] fix: use d-api enum instead --- package.json | 2 +- pnpm-lock.yaml | 10 +++++----- src/client/onmessagecreate.ts | 4 ++-- src/commands/applications/chat.ts | 8 +++++--- src/commands/applications/menu.ts | 13 +++++++++---- src/commands/decorators.ts | 30 +++++++++++++----------------- 6 files changed, 35 insertions(+), 32 deletions(-) diff --git a/package.json b/package.json index fb33ce3..def53c5 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "license": "Apache-2.0", "dependencies": { "chokidar": "^3.6.0", - "discord-api-types": "^0.37.83", + "discord-api-types": "^0.37.84", "magic-bytes.js": "^1.10.0", "ts-mixer": "^6.0.4", "ws": "^8.16.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 281ed39..b24e05e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,8 +12,8 @@ importers: specifier: ^3.6.0 version: 3.6.0 discord-api-types: - specifier: ^0.37.83 - version: 0.37.83 + specifier: ^0.37.84 + version: 0.37.84 magic-bytes.js: specifier: ^1.10.0 version: 1.10.0 @@ -362,8 +362,8 @@ packages: resolution: {integrity: sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==} engines: {node: '>=0.10'} - discord-api-types@0.37.83: - resolution: {integrity: sha512-urGGYeWtWNYMKnYlZnOnDHm8fVRffQs3U0SpE8RHeiuLKb/u92APS8HoQnPTFbnXmY1vVnXjXO4dOxcAn3J+DA==} + discord-api-types@0.37.84: + resolution: {integrity: sha512-NngmTBW8vermlbO0qNtaS7SHCWB/R96ICqflTwM/cV7zsxyQGd38E2bBlwaxLbXgb2YTF3+Yx6+qGs/3sXedCw==} dot-prop@5.3.0: resolution: {integrity: sha512-QM8q3zDe58hqUqjraQOmzZ1LIH9SWQJTlEKCH4kJ2oQvLZk7RbQXvtDM2XEq3fwkV9CCvvH4LA0AV+ogFsBM2Q==} @@ -1191,7 +1191,7 @@ snapshots: denque@2.1.0: optional: true - discord-api-types@0.37.83: {} + discord-api-types@0.37.84: {} dot-prop@5.3.0: dependencies: diff --git a/src/client/onmessagecreate.ts b/src/client/onmessagecreate.ts index 1b6ee5e..13684d9 100644 --- a/src/client/onmessagecreate.ts +++ b/src/client/onmessagecreate.ts @@ -1,6 +1,7 @@ import { ApplicationCommandOptionType, ChannelType, + InteractionContextType, type APIApplicationCommandInteractionDataOption, type GatewayMessageCreateDispatchData, } from 'discord-api-types/v10'; @@ -8,7 +9,6 @@ import { Command, CommandContext, IgnoreCommand, - InteractionContextTypes, OptionResolver, SubCommand, User, @@ -103,7 +103,7 @@ export async function onMessageCreate( if (!command) return; if (!command.run) return self.logger.warn(`${fullCommandName} command does not have 'run' callback`); - if (!command.contexts?.includes(InteractionContextTypes.BOT_DM) && !message.guildId) return; + if (!command.contexts?.includes(InteractionContextType.BotDM) && !message.guildId) return; if (command.guildId && !command.guildId?.includes(message.guildId!)) return; const resolved: MakeRequired = { diff --git a/src/commands/applications/chat.ts b/src/commands/applications/chat.ts index baa9c03..67c4722 100644 --- a/src/commands/applications/chat.ts +++ b/src/commands/applications/chat.ts @@ -1,6 +1,8 @@ import { ApplicationCommandOptionType, ApplicationCommandType, + type ApplicationIntegrationType, + type InteractionContextType, type APIApplicationCommandBasicOption, type APIApplicationCommandOption, type APIApplicationCommandSubcommandGroupOption, @@ -17,7 +19,7 @@ import type { import type { Attachment } from '../../builders'; import { magicImport, type FlatObjectKeys } from '../../common'; import type { AllChannels, AutocompleteInteraction, GuildRole, InteractionGuildMember, User } from '../../structures'; -import type { Groups, IntegrationTypes, InteractionContextTypes, RegisteredMiddlewares } from '../decorators'; +import type { Groups, RegisteredMiddlewares } from '../decorators'; import type { OptionResolver } from '../optionresolver'; import type { CommandContext } from './chatcontext'; import type { @@ -123,8 +125,8 @@ export class BaseCommand { nsfw?: boolean; description!: string; defaultMemberPermissions?: bigint; - integrationTypes?: IntegrationTypes[]; - contexts?: InteractionContextTypes[]; + integrationTypes?: ApplicationIntegrationType[]; + contexts?: InteractionContextType[]; botPermissions?: bigint; name_localizations?: Partial>; description_localizations?: Partial>; diff --git a/src/commands/applications/menu.ts b/src/commands/applications/menu.ts index b08f8fb..96fbb00 100644 --- a/src/commands/applications/menu.ts +++ b/src/commands/applications/menu.ts @@ -1,6 +1,11 @@ -import type { ApplicationCommandType, LocaleString } from 'discord-api-types/v10'; +import type { + ApplicationCommandType, + ApplicationIntegrationType, + InteractionContextType, + LocaleString, +} from 'discord-api-types/v10'; import { magicImport, type PermissionStrings } from '../../common'; -import type { IntegrationTypes, InteractionContextTypes, RegisteredMiddlewares } from '../decorators'; +import type { RegisteredMiddlewares } from '../decorators'; import type { MenuCommandContext } from './menucontext'; import type { UsingClient } from './shared'; @@ -14,8 +19,8 @@ export abstract class ContextMenuCommand { name!: string; type!: ApplicationCommandType.User | ApplicationCommandType.Message; nsfw?: boolean; - integrationTypes?: IntegrationTypes[]; - contexts?: InteractionContextTypes[]; + integrationTypes?: ApplicationIntegrationType[]; + contexts?: InteractionContextType[]; description!: string; defaultMemberPermissions?: bigint; botPermissions?: bigint; diff --git a/src/commands/decorators.ts b/src/commands/decorators.ts index ae84d73..69bd269 100644 --- a/src/commands/decorators.ts +++ b/src/commands/decorators.ts @@ -1,20 +1,16 @@ -import { ApplicationCommandType, PermissionFlagsBits, type LocaleString } from 'discord-api-types/v10'; +import { + ApplicationCommandType, + ApplicationIntegrationType, + InteractionContextType, + PermissionFlagsBits, + type LocaleString, +} from 'discord-api-types/v10'; import type { FlatObjectKeys, PermissionStrings } from '../common'; import type { CommandOption, OptionsRecord, SubCommand } from './applications/chat'; import type { DefaultLocale, IgnoreCommand, MiddlewareContext } from './applications/shared'; export interface RegisteredMiddlewares {} -export enum IntegrationTypes { - GUILD_INSTALL = 0, - USER_INSTALL = 1, -} -export enum InteractionContextTypes { - GUILD = 0, - BOT_DM = 1, - PRIVATE_CHANNEL = 2, -} - type DeclareOptions = | { name: string; @@ -23,8 +19,8 @@ type DeclareOptions = defaultMemberPermissions?: PermissionStrings | bigint; guildId?: string[]; nsfw?: boolean; - integrationTypes?: (keyof typeof IntegrationTypes)[]; - contexts?: (keyof typeof InteractionContextTypes)[]; + integrationTypes?: (keyof typeof ApplicationIntegrationType)[]; + contexts?: (keyof typeof InteractionContextType)[]; ignore?: IgnoreCommand; aliases?: string[]; } @@ -36,8 +32,8 @@ type DeclareOptions = defaultMemberPermissions?: PermissionStrings | bigint; guildId?: string[]; nsfw?: boolean; - integrationTypes?: (keyof typeof IntegrationTypes)[]; - contexts?: (keyof typeof InteractionContextTypes)[]; + integrationTypes?: (keyof typeof ApplicationIntegrationType)[]; + contexts?: (keyof typeof InteractionContextType)[]; }, 'type' | 'description' > & { @@ -161,8 +157,8 @@ export function Declare(declare: DeclareOptions) { class extends target { name = declare.name; nsfw = declare.nsfw; - contexts = declare.contexts?.map(i => InteractionContextTypes[i]); - integrationTypes = declare.integrationTypes?.map(i => IntegrationTypes[i]); + contexts = declare.contexts?.map(i => InteractionContextType[i]); + integrationTypes = declare.integrationTypes?.map(i => ApplicationIntegrationType[i]); defaultMemberPermissions = Array.isArray(declare.defaultMemberPermissions) ? declare.defaultMemberPermissions?.reduce((acc, prev) => acc | PermissionFlagsBits[prev], BigInt(0)) : declare.defaultMemberPermissions;