Skip to content

Commit

Permalink
fix: context-interactions error (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoobes authored Jan 24, 2025
1 parent 3f703c1 commit a52ad27
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/core/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 12 additions & 2 deletions src/handlers/interaction.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit a52ad27

Please sign in to comment.