From d8132a0199908b6d526f290b219c09725085f4af Mon Sep 17 00:00:00 2001 From: MARCROCK22 <57925328+MARCROCK22@users.noreply.github.com> Date: Fri, 22 Mar 2024 21:59:42 -0400 Subject: [PATCH] integration_types and contexts support --- src/client/onmessagecreate.ts | 11 +++++++++-- src/commands/applications/chat.ts | 12 ++++++++---- src/commands/applications/menu.ts | 6 +++++- src/commands/decorators.ts | 32 ++++++++++++++++++++++--------- 4 files changed, 45 insertions(+), 16 deletions(-) diff --git a/src/client/onmessagecreate.ts b/src/client/onmessagecreate.ts index 19ddd37..ad6f861 100644 --- a/src/client/onmessagecreate.ts +++ b/src/client/onmessagecreate.ts @@ -7,12 +7,13 @@ import { import { Command, CommandContext, - type ContextOptionsResolved, + InteractionContextTypes, OptionResolver, SubCommand, User, type Client, type CommandOption, + type ContextOptionsResolved, type SeyfertChannelOption, type SeyfertIntegerOption, type SeyfertNumberOption, @@ -86,7 +87,13 @@ export async function onMessageCreate( if (!command) return; if (!command.run) return self.logger.warn(`${fullCommandName} command does not have 'run' callback`); - if (command.dm && !message.guildId) return; + if ( + [InteractionContextTypes.BOT_DM, InteractionContextTypes.PRIVATE_CHANNEL].some(i => + command.contexts?.includes(i), + ) && + !message.guildId + ) + return; if (command.guild_id && !command.guild_id?.includes(message.guildId!)) return; const resolved: MakeRequired = { diff --git a/src/commands/applications/chat.ts b/src/commands/applications/chat.ts index cffa4a4..5015a04 100644 --- a/src/commands/applications/chat.ts +++ b/src/commands/applications/chat.ts @@ -10,7 +10,7 @@ import type { } from '../../common'; import { ApplicationCommandOptionType, ApplicationCommandType, magicImport } from '../../common'; import type { AllChannels, AutocompleteInteraction, GuildRole, InteractionGuildMember, User } from '../../structures'; -import type { Groups, RegisteredMiddlewares } from '../decorators'; +import type { Groups, IntegrationTypes, InteractionContextTypes, RegisteredMiddlewares } from '../decorators'; import type { OptionResolver } from '../optionresolver'; import type { CommandContext } from './chatcontext'; import type { @@ -124,8 +124,9 @@ class BaseCommand { nsfw?: boolean; description!: string; default_member_permissions?: string; + integration_types?: IntegrationTypes[]; + contexts?: InteractionContextTypes[]; botPermissions?: bigint; - dm?: boolean; name_localizations?: Partial>; description_localizations?: Partial>; @@ -247,6 +248,8 @@ class BaseCommand { description_localizations: this.description_localizations, guild_id: this.guild_id, default_member_permissions: this.default_member_permissions, + contexts: this.contexts, + integration_types: this.integration_types, } as { name: BaseCommand['name']; type: BaseCommand['type']; @@ -256,9 +259,10 @@ class BaseCommand { description_localizations: BaseCommand['description_localizations']; guild_id: BaseCommand['guild_id']; default_member_permissions: BaseCommand['default_member_permissions']; - dm_permission?: boolean; + contexts: BaseCommand['contexts']; + integration_types: BaseCommand['integration_types']; }; - if ('dm' in this) data.dm_permission = this.dm; + if (data.contexts) console.log(data); return data; } diff --git a/src/commands/applications/menu.ts b/src/commands/applications/menu.ts index 7b99ca8..442a169 100644 --- a/src/commands/applications/menu.ts +++ b/src/commands/applications/menu.ts @@ -1,5 +1,5 @@ import { magicImport, type ApplicationCommandType, type LocaleString, type PermissionStrings } from '../../common'; -import type { RegisteredMiddlewares } from '../decorators'; +import type { IntegrationTypes, InteractionContextTypes, RegisteredMiddlewares } from '../decorators'; import type { MenuCommandContext } from './menucontext'; import type { NextFunction, PassFunction, StopFunction, UsingClient } from './shared'; @@ -13,6 +13,8 @@ export abstract class ContextMenuCommand { name!: string; type!: ApplicationCommandType.User | ApplicationCommandType.Message; nsfw?: boolean; + integration_types?: IntegrationTypes[]; + contexts?: InteractionContextTypes[]; description!: string; default_member_permissions?: string; botPermissions?: bigint; @@ -89,6 +91,8 @@ export abstract class ContextMenuCommand { guild_id: this.guild_id, dm_permission: this.dm, default_member_permissions: this.default_member_permissions, + contexts: this.contexts, + integration_types: this.integration_types, }; } diff --git a/src/commands/decorators.ts b/src/commands/decorators.ts index 3170803..2241a24 100644 --- a/src/commands/decorators.ts +++ b/src/commands/decorators.ts @@ -10,25 +10,39 @@ import type { DefaultLocale, 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; description: string; botPermissions?: PermissionStrings | bigint; - defaultPermissions?: PermissionStrings | bigint; + defaultMemberPermissions?: PermissionStrings | bigint; guildId?: string[]; - dm?: boolean; + // dm?: boolean; nsfw?: boolean; + integrationTypes?: (keyof typeof IntegrationTypes)[]; + contexts?: (keyof typeof InteractionContextTypes)[]; } | (Omit< { name: string; description: string; botPermissions?: PermissionStrings | bigint; - defaultPermissions?: PermissionStrings | bigint; + defaultMemberPermissions?: PermissionStrings | bigint; guildId?: string[]; - dm?: boolean; + // dm?: boolean; nsfw?: boolean; + integrationTypes?: (keyof typeof IntegrationTypes)[]; + contexts?: (keyof typeof InteractionContextTypes)[]; }, 'type' | 'description' > & { @@ -132,13 +146,14 @@ export function Declare(declare: DeclareOptions) { class extends target { name = declare.name; nsfw = declare.nsfw; - default_member_permissions = Array.isArray(declare.defaultPermissions) - ? declare.defaultPermissions?.reduce((acc, prev) => acc | PermissionFlagsBits[prev], BigInt(0)).toString() - : declare.defaultPermissions; + contexts = declare.contexts?.map(i => InteractionContextTypes[i]); + integration_types = declare.integrationTypes?.map(i => IntegrationTypes[i]); + default_member_permissions = Array.isArray(declare.defaultMemberPermissions) + ? declare.defaultMemberPermissions?.reduce((acc, prev) => acc | PermissionFlagsBits[prev], BigInt(0)).toString() + : declare.defaultMemberPermissions; botPermissions = Array.isArray(declare.botPermissions) ? declare.botPermissions?.reduce((acc, prev) => acc | PermissionFlagsBits[prev], BigInt(0)) : declare.botPermissions; - dm?: boolean; description = ''; type: ApplicationCommandType = ApplicationCommandType.ChatInput; guild_id?: string[]; @@ -146,7 +161,6 @@ export function Declare(declare: DeclareOptions) { super(...args); if ('description' in declare) this.description = declare.description; if ('type' in declare) this.type = declare.type; - if ('dm' in declare) this.dm = !!declare.dm; if ('guildId' in declare) this.guild_id = declare.guildId; // check if all properties are valid }