fix custom context in prefix commands (#159)

This commit is contained in:
JustEvil 2024-03-18 15:40:56 -06:00 committed by GitHub
parent 74159ac1da
commit c1351f32de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 12 deletions

View File

@ -27,7 +27,7 @@ import {
import type { DeepPartial, IntentStrings, OmitInsert } from '../common/types/util'; import type { DeepPartial, IntentStrings, OmitInsert } from '../common/types/util';
import { ComponentHandler } from '../components/handler'; import { ComponentHandler } from '../components/handler';
import { LangsHandler } from '../langs/handler'; import { LangsHandler } from '../langs/handler';
import type { ChatInputCommandInteraction, MessageCommandInteraction, UserCommandInteraction } from '../structures'; import type { ChatInputCommandInteraction, Message, MessageCommandInteraction, UserCommandInteraction } from '../structures';
export class BaseClient { export class BaseClient {
rest!: ApiHandler; rest!: ApiHandler;
@ -245,7 +245,8 @@ export interface BaseClientOptions {
interaction: interaction:
| ChatInputCommandInteraction<boolean> | ChatInputCommandInteraction<boolean>
| UserCommandInteraction<boolean> | UserCommandInteraction<boolean>
| MessageCommandInteraction<boolean>, | MessageCommandInteraction<boolean>
| Message
) => {}; ) => {};
globalMiddlewares?: readonly (keyof RegisteredMiddlewares)[]; globalMiddlewares?: readonly (keyof RegisteredMiddlewares)[];
} }

View File

@ -44,15 +44,15 @@ function getCommandFromContent(
const command = const command =
groupName || subcommandName groupName || subcommandName
? (parent.options?.find(opt => { ? (parent.options?.find(opt => {
if (opt instanceof SubCommand) { if (opt instanceof SubCommand) {
if (groupName) { if (groupName) {
if (opt.group !== groupName) return false; if (opt.group !== groupName) return false;
}
if (opt.group && !groupName) return false;
return subcommandName === opt.name;
} }
return false; if (opt.group && !groupName) return false;
}) as SubCommand) return subcommandName === opt.name;
}
return false;
}) as SubCommand)
: parent; : parent;
return { return {
@ -97,6 +97,8 @@ export async function onMessageCreate(
const { options, errors } = await parseOptions(self, command, rawMessage, args, resolved); const { options, errors } = await parseOptions(self, command, rawMessage, args, resolved);
const optionsResolver = new OptionResolver(self, options, parent as Command, message.guildId, resolved); const optionsResolver = new OptionResolver(self, options, parent as Command, message.guildId, resolved);
const context = new CommandContext(self, message, optionsResolver, shardId, command); const context = new CommandContext(self, message, optionsResolver, shardId, command);
const extendContext = self.options?.context?.(message) ?? {};
Object.assign(context, extendContext);
try { try {
if (command.botPermissions && message.guildId) { if (command.botPermissions && message.guildId) {
const meMember = await self.cache.members?.get(self.botId, message.guildId); const meMember = await self.cache.members?.get(self.botId, message.guildId);

View File

@ -1,7 +1,7 @@
import type { InternalRuntimeConfig, InternalRuntimeConfigHTTP, RuntimeConfig, RuntimeConfigHTTP } from './client/base'; import type { InternalRuntimeConfig, InternalRuntimeConfigHTTP, RuntimeConfig, RuntimeConfigHTTP } from './client/base';
import { GatewayIntentBits } from './common'; import { GatewayIntentBits } from './common';
import type { ClientNameEvents, EventContext } from './events'; import type { ClientNameEvents, EventContext } from './events';
import type { ChatInputCommandInteraction, MessageCommandInteraction, UserCommandInteraction } from './structures'; import type { ChatInputCommandInteraction, Message, MessageCommandInteraction, UserCommandInteraction } from './structures';
export { Logger, PermissionFlagsBits, PermissionStrings, Watcher } from './common'; export { Logger, PermissionFlagsBits, PermissionStrings, Watcher } from './common';
// //
@ -95,7 +95,7 @@ export const config = {
* }); * });
*/ */
export function extendContext<T extends {}>( export function extendContext<T extends {}>(
cb: (interaction: ChatInputCommandInteraction | UserCommandInteraction | MessageCommandInteraction) => T, cb: (interaction: ChatInputCommandInteraction | UserCommandInteraction | MessageCommandInteraction | Message) => T,
) { ) {
return cb; return cb;
} }