From 1e5deae1f95c347c1412c77297fa45d6dd2b358f Mon Sep 17 00:00:00 2001 From: jacoobes Date: Fri, 24 Jan 2025 09:48:53 -0600 Subject: [PATCH] commit --- src/core/functions.ts | 3 +++ src/handlers/interaction.ts | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/core/functions.ts b/src/core/functions.ts index da111917..00c4a7e8 100644 --- a/src/core/functions.ts +++ b/src/core/functions.ts @@ -119,6 +119,9 @@ export function isMessageComponent(i: InteractionTypable): i is AnyMessageCompon export function isCommand(i: InteractionTypable): i is AnyCommandInteraction { return i.type === InteractionType.ApplicationCommand; } +export function isContextCommand(i: AnyCommandInteraction): i is MessageContextMenuCommandInteraction | UserContextMenuCommandInteraction { + return i.isContextMenuCommand(); +} export function isAutocomplete(i: InteractionTypable): i is AutocompleteInteraction { return i.type === InteractionType.ApplicationCommandAutocomplete; } diff --git a/src/handlers/interaction.ts b/src/handlers/interaction.ts index 2fba5cee..814db701 100644 --- a/src/handlers/interaction.ts +++ b/src/handlers/interaction.ts @@ -1,7 +1,7 @@ import type { Module } from '../types/core-modules' import { callPlugins, executeModule } from './event-utils'; import { SernError } from '../core/structures/enums' -import { createSDT, isAutocomplete, isCommand, isMessageComponent, isModal, resultPayload, treeSearch } from '../core/functions' +import { createSDT, isAutocomplete, isCommand, isContextCommand, isMessageComponent, isModal, resultPayload, treeSearch } from '../core/functions' import type { UnpackedDependencies } from '../types/utility'; import * as Id from '../core/id' import { Context } from '../core/structures/context'; @@ -29,13 +29,23 @@ export function interactionHandler(deps: UnpackedDependencies, defaultPrefix?: s } const { module, params } = modules.at(0)!; let payload; + // handles autocomplete if(isAutocomplete(event)) { //@ts-ignore stfu const { command } = treeSearch(event, module.options); payload= { module: command as Module, //autocomplete is not a true "module" warning cast! args: [event, createSDT(command, deps, params)] }; + // either CommandTypes Slash | ContextMessage | ContextUesr } else if(isCommand(event)) { - payload= { module, args: [Context.wrap(event, defaultPrefix), createSDT(module, deps, params)] }; + const sdt = createSDT(module, deps, params) + // handle CommandType.CtxUser || CommandType.CtxMsg + if(isContextCommand(event)) { + payload= { module, args: [event, sdt] }; + } else { + // handle CommandType.Slash || CommandType.Both + payload= { module, args: [Context.wrap(event, defaultPrefix), sdt] }; + } + // handles modals or components } else if (isModal(event) || isMessageComponent(event)) { payload= { module, args: [event, createSDT(module, deps, params)] } } else {