fix: use d-api enum instead

This commit is contained in:
MARCROCK22 2024-05-18 14:17:51 -04:00
parent c9b4078a60
commit 2e680f557f
6 changed files with 35 additions and 32 deletions

View File

@ -21,7 +21,7 @@
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"chokidar": "^3.6.0", "chokidar": "^3.6.0",
"discord-api-types": "^0.37.83", "discord-api-types": "^0.37.84",
"magic-bytes.js": "^1.10.0", "magic-bytes.js": "^1.10.0",
"ts-mixer": "^6.0.4", "ts-mixer": "^6.0.4",
"ws": "^8.16.0" "ws": "^8.16.0"

10
pnpm-lock.yaml generated
View File

@ -12,8 +12,8 @@ importers:
specifier: ^3.6.0 specifier: ^3.6.0
version: 3.6.0 version: 3.6.0
discord-api-types: discord-api-types:
specifier: ^0.37.83 specifier: ^0.37.84
version: 0.37.83 version: 0.37.84
magic-bytes.js: magic-bytes.js:
specifier: ^1.10.0 specifier: ^1.10.0
version: 1.10.0 version: 1.10.0
@ -362,8 +362,8 @@ packages:
resolution: {integrity: sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==} resolution: {integrity: sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==}
engines: {node: '>=0.10'} engines: {node: '>=0.10'}
discord-api-types@0.37.83: discord-api-types@0.37.84:
resolution: {integrity: sha512-urGGYeWtWNYMKnYlZnOnDHm8fVRffQs3U0SpE8RHeiuLKb/u92APS8HoQnPTFbnXmY1vVnXjXO4dOxcAn3J+DA==} resolution: {integrity: sha512-NngmTBW8vermlbO0qNtaS7SHCWB/R96ICqflTwM/cV7zsxyQGd38E2bBlwaxLbXgb2YTF3+Yx6+qGs/3sXedCw==}
dot-prop@5.3.0: dot-prop@5.3.0:
resolution: {integrity: sha512-QM8q3zDe58hqUqjraQOmzZ1LIH9SWQJTlEKCH4kJ2oQvLZk7RbQXvtDM2XEq3fwkV9CCvvH4LA0AV+ogFsBM2Q==} resolution: {integrity: sha512-QM8q3zDe58hqUqjraQOmzZ1LIH9SWQJTlEKCH4kJ2oQvLZk7RbQXvtDM2XEq3fwkV9CCvvH4LA0AV+ogFsBM2Q==}
@ -1191,7 +1191,7 @@ snapshots:
denque@2.1.0: denque@2.1.0:
optional: true optional: true
discord-api-types@0.37.83: {} discord-api-types@0.37.84: {}
dot-prop@5.3.0: dot-prop@5.3.0:
dependencies: dependencies:

View File

@ -1,6 +1,7 @@
import { import {
ApplicationCommandOptionType, ApplicationCommandOptionType,
ChannelType, ChannelType,
InteractionContextType,
type APIApplicationCommandInteractionDataOption, type APIApplicationCommandInteractionDataOption,
type GatewayMessageCreateDispatchData, type GatewayMessageCreateDispatchData,
} from 'discord-api-types/v10'; } from 'discord-api-types/v10';
@ -8,7 +9,6 @@ import {
Command, Command,
CommandContext, CommandContext,
IgnoreCommand, IgnoreCommand,
InteractionContextTypes,
OptionResolver, OptionResolver,
SubCommand, SubCommand,
User, User,
@ -103,7 +103,7 @@ export async function onMessageCreate(
if (!command) return; if (!command) return;
if (!command.run) return self.logger.warn(`${fullCommandName} command does not have 'run' callback`); 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; if (command.guildId && !command.guildId?.includes(message.guildId!)) return;
const resolved: MakeRequired<ContextOptionsResolved> = { const resolved: MakeRequired<ContextOptionsResolved> = {

View File

@ -1,6 +1,8 @@
import { import {
ApplicationCommandOptionType, ApplicationCommandOptionType,
ApplicationCommandType, ApplicationCommandType,
type ApplicationIntegrationType,
type InteractionContextType,
type APIApplicationCommandBasicOption, type APIApplicationCommandBasicOption,
type APIApplicationCommandOption, type APIApplicationCommandOption,
type APIApplicationCommandSubcommandGroupOption, type APIApplicationCommandSubcommandGroupOption,
@ -17,7 +19,7 @@ import type {
import type { Attachment } from '../../builders'; import type { Attachment } from '../../builders';
import { magicImport, type FlatObjectKeys } from '../../common'; import { magicImport, type FlatObjectKeys } from '../../common';
import type { AllChannels, AutocompleteInteraction, GuildRole, InteractionGuildMember, User } from '../../structures'; 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 { OptionResolver } from '../optionresolver';
import type { CommandContext } from './chatcontext'; import type { CommandContext } from './chatcontext';
import type { import type {
@ -123,8 +125,8 @@ export class BaseCommand {
nsfw?: boolean; nsfw?: boolean;
description!: string; description!: string;
defaultMemberPermissions?: bigint; defaultMemberPermissions?: bigint;
integrationTypes?: IntegrationTypes[]; integrationTypes?: ApplicationIntegrationType[];
contexts?: InteractionContextTypes[]; contexts?: InteractionContextType[];
botPermissions?: bigint; botPermissions?: bigint;
name_localizations?: Partial<Record<LocaleString, string>>; name_localizations?: Partial<Record<LocaleString, string>>;
description_localizations?: Partial<Record<LocaleString, string>>; description_localizations?: Partial<Record<LocaleString, string>>;

View File

@ -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 { magicImport, type PermissionStrings } from '../../common';
import type { IntegrationTypes, InteractionContextTypes, RegisteredMiddlewares } from '../decorators'; import type { RegisteredMiddlewares } from '../decorators';
import type { MenuCommandContext } from './menucontext'; import type { MenuCommandContext } from './menucontext';
import type { UsingClient } from './shared'; import type { UsingClient } from './shared';
@ -14,8 +19,8 @@ export abstract class ContextMenuCommand {
name!: string; name!: string;
type!: ApplicationCommandType.User | ApplicationCommandType.Message; type!: ApplicationCommandType.User | ApplicationCommandType.Message;
nsfw?: boolean; nsfw?: boolean;
integrationTypes?: IntegrationTypes[]; integrationTypes?: ApplicationIntegrationType[];
contexts?: InteractionContextTypes[]; contexts?: InteractionContextType[];
description!: string; description!: string;
defaultMemberPermissions?: bigint; defaultMemberPermissions?: bigint;
botPermissions?: bigint; botPermissions?: bigint;

View File

@ -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 { FlatObjectKeys, PermissionStrings } from '../common';
import type { CommandOption, OptionsRecord, SubCommand } from './applications/chat'; import type { CommandOption, OptionsRecord, SubCommand } from './applications/chat';
import type { DefaultLocale, IgnoreCommand, MiddlewareContext } from './applications/shared'; import type { DefaultLocale, IgnoreCommand, MiddlewareContext } from './applications/shared';
export interface RegisteredMiddlewares {} 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 = type DeclareOptions =
| { | {
name: string; name: string;
@ -23,8 +19,8 @@ type DeclareOptions =
defaultMemberPermissions?: PermissionStrings | bigint; defaultMemberPermissions?: PermissionStrings | bigint;
guildId?: string[]; guildId?: string[];
nsfw?: boolean; nsfw?: boolean;
integrationTypes?: (keyof typeof IntegrationTypes)[]; integrationTypes?: (keyof typeof ApplicationIntegrationType)[];
contexts?: (keyof typeof InteractionContextTypes)[]; contexts?: (keyof typeof InteractionContextType)[];
ignore?: IgnoreCommand; ignore?: IgnoreCommand;
aliases?: string[]; aliases?: string[];
} }
@ -36,8 +32,8 @@ type DeclareOptions =
defaultMemberPermissions?: PermissionStrings | bigint; defaultMemberPermissions?: PermissionStrings | bigint;
guildId?: string[]; guildId?: string[];
nsfw?: boolean; nsfw?: boolean;
integrationTypes?: (keyof typeof IntegrationTypes)[]; integrationTypes?: (keyof typeof ApplicationIntegrationType)[];
contexts?: (keyof typeof InteractionContextTypes)[]; contexts?: (keyof typeof InteractionContextType)[];
}, },
'type' | 'description' 'type' | 'description'
> & { > & {
@ -161,8 +157,8 @@ export function Declare(declare: DeclareOptions) {
class extends target { class extends target {
name = declare.name; name = declare.name;
nsfw = declare.nsfw; nsfw = declare.nsfw;
contexts = declare.contexts?.map(i => InteractionContextTypes[i]); contexts = declare.contexts?.map(i => InteractionContextType[i]);
integrationTypes = declare.integrationTypes?.map(i => IntegrationTypes[i]); integrationTypes = declare.integrationTypes?.map(i => ApplicationIntegrationType[i]);
defaultMemberPermissions = Array.isArray(declare.defaultMemberPermissions) defaultMemberPermissions = Array.isArray(declare.defaultMemberPermissions)
? declare.defaultMemberPermissions?.reduce((acc, prev) => acc | PermissionFlagsBits[prev], BigInt(0)) ? declare.defaultMemberPermissions?.reduce((acc, prev) => acc | PermissionFlagsBits[prev], BigInt(0))
: declare.defaultMemberPermissions; : declare.defaultMemberPermissions;