Skip to content

Commit 6b2b9bc

Browse files
committed
feat(InteractionHandlers): initial commit 👀 🎉
chore: move to try-catch chore: commit code before rebase chore: requested changes feat: interaction handles done? 👀 chore: export the new classes in the index file fix: woops I did it again feat: wip consistent parse return types fix: make types be stricter and re-usable fix: temporary fix for a type till we get TS 4.5.0 fix: correct handler for interaction handler errors chore: the commit before the rebase chore: inside we both know what's been going on permalink: http://whatthecommit.com/6bda5f6eeb7347a96e07b6dea1d21afa fix: correct event types chore: remove deprecation warnings that aren't valid anymore fix: revert change but break something else intentionally :D chore: 🧹 chore: this really should not take 19 minutes to build (It doesn't actually take 19 minutes to build) chore: i was told to leave it alone, but i have this thing called ocd, you see permalink: http://whatthecommit.com/bf057fb0e2e7a4450250ebf7d6e1d084 chore: progress before merge with master chore: the merge of 17.11 chore: diff computing is implemented Next up: logging the diff, then testing everything?? woah?? chore: styling ree chore: revert the revert chore: perf logging chore: who's ready for the next battle? chore: small bug fixes chore: small logging refactors chore: more cleanups chore: bugs are everywhere ;w; fix: compute context menu differences too chore: forward thinking code refactor chore: woopsy daisy feat: add the registries to the container chore: relocate error listeners chore: optimize application command registries by fetching data once chore: rename the method to be cleare chore: move optional listeners around feat: interaction listeners 👀 chore: update todo comment feat: make message command listeners optional feat: add lots of events chore: remove invalid todos feat: handle registry results, chat input register shortcut chore: yet another rebase fix: last minute bugs ci: specify registry for actions/setup-node chore: gotcha chore: correct type for command in Argument contexts fix(regression): accidentally removed Command options generic chore: correct types for precondition run and their command chore: my man really called these middlewares chore: fix bad rebase chore: small missed things and cleanup chore: make event name clearer fix: handle forgotten cases fix: correct context types chore: make default logger a smidgen more useful chore(deps): update actions/setup-node commit hash to 04c56d2 (#335) Co-authored-by: Renovate Bot <[email protected]> fix(deps): update sapphire dependencies (#337) Co-authored-by: Renovate Bot <[email protected]> chore(deps): update all non-major dependencies (#336) * chore(deps): update all non-major dependencies * chore: nothing to see here, move along permalink: http://whatthecommit.com/9837f0b1d62e8f74ff6ef9865bba9003 Co-authored-by: Renovate Bot <[email protected]> Co-authored-by: Jeroen Claassens <[email protected]> fix: prevent hard errors for unauthorized guild app commands chore: someone dropped a comma fix(command): TS Only - Fixed type of re-export of `*Command.Context` fix(command): TS Only - Fixed type of re-export of `Command.Context` chore: fixed the previous commit chore(release): 2.2.1 fix: i did an oopsie fix: propagate errors chore: log the stack if possible chore: bruh moment chore: unit test crashes? chore: love debug info? me too! chore: colons help chore: support extra types chore: these types are gonna get me 2 meters underground chore: add alll the default error listeners fix: make `BooleanArgument`/`resolveBoolean`'s contexts immutable (#338) feat: add default register behavior and fix reloading support chore: hah chore: like it or not, you get logsfor errors chore: expose registries chore: check names too fix: allow `null` in setDefaultBehaviorWhenNotIdentical Co-authored-by: Antonio Román <[email protected]> chore: remove redundant destructure Co-authored-by: Antonio Román <[email protected]> chore: fix tests fix(deps): update sapphire dependencies (#342) Co-authored-by: Renovate Bot <[email protected]> Co-authored-by: Jeroen Claassens <[email protected]> chore(deps): update all non-major dependencies (#341) Co-authored-by: Renovate Bot <[email protected]> chore(deps): update actions/upload-artifact commit hash to da838ae (#340) Co-authored-by: Renovate Bot <[email protected]> chore(deps): update actions/download-artifact commit hash to f023be2 (#339) Co-authored-by: Renovate Bot <[email protected]> chore: remove old issue templates chore: remove dupe files from framework chore(deps): update actions/upload-artifact commit hash to 82c141c (#343) Co-authored-by: Renovate Bot <[email protected]> chore(deps): update all non-major dependencies (#344) build: update `@types/node` chore: use enums for internal api call type chore: get stores only once chore: undo rename of core preconditions chore: fix rebase
1 parent ab7c5b1 commit 6b2b9bc

File tree

70 files changed

+3771
-322
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+3771
-322
lines changed

src/errorListeners/CoreCommandError.ts

-14
This file was deleted.

src/index.ts

+22-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
import {
2+
acquire,
3+
getDefaultBehaviorWhenNotIdentical,
4+
registries,
5+
setDefaultBehaviorWhenNotIdentical
6+
} from './lib/utils/application-commands/ApplicationCommandRegistries';
7+
import type { ApplicationCommandRegistry } from './lib/utils/application-commands/ApplicationCommandRegistry';
8+
9+
const ApplicationCommandRegistries = {
10+
acquire,
11+
setDefaultBehaviorWhenNotIdentical,
12+
getDefaultBehaviorWhenNotIdentical,
13+
get registries(): ReadonlyMap<string, ApplicationCommandRegistry> {
14+
return registries;
15+
}
16+
};
17+
118
export {
219
AliasPiece,
320
AliasPieceOptions,
@@ -31,12 +48,16 @@ export * from './lib/structures/ArgumentStore';
3148
export * from './lib/structures/Command';
3249
export * from './lib/structures/CommandStore';
3350
export * from './lib/structures/ExtendedArgument';
51+
export * from './lib/structures/InteractionHandler';
52+
export * from './lib/structures/InteractionHandlerStore';
3453
export * from './lib/structures/Listener';
3554
export * from './lib/structures/ListenerStore';
3655
export * from './lib/structures/Precondition';
3756
export * from './lib/structures/PreconditionStore';
3857
export * from './lib/types/Enums';
3958
export * from './lib/types/Events';
59+
export { ApplicationCommandRegistries };
60+
export { ApplicationCommandRegistry, ApplicationCommandRegistryRegisterOptions } from './lib/utils/application-commands/ApplicationCommandRegistry';
4061
export * from './lib/utils/logger/ILogger';
4162
export * from './lib/utils/logger/Logger';
4263
export * from './lib/utils/preconditions/conditions/IPreconditionCondition';
@@ -47,12 +68,7 @@ export * from './lib/utils/preconditions/containers/UserPermissionsPrecondition'
4768
export * from './lib/utils/preconditions/IPreconditionContainer';
4869
export * from './lib/utils/preconditions/PreconditionContainerArray';
4970
export * from './lib/utils/preconditions/PreconditionContainerSingle';
50-
export * as CorePreconditions from './preconditions';
51-
/**
52-
* @deprecated. Please use `CorePreconditions.ClientPermissions`. `ClientPermissionsCorePrecondition` will be removed in v3.0.0
53-
*/
54-
export { CorePrecondition as ClientPermissionsCorePrecondition } from './preconditions/ClientPermissions';
55-
export type { CooldownContext } from './preconditions/Cooldown';
71+
export * as CorePreconditions from './preconditions/index';
5672

5773
/**
5874
* The [@sapphire/framework](https://github.com/sapphiredev/framework) version that you are currently using.

src/lib/SapphireClient.ts

+29-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@ import type { Plugin } from './plugins/Plugin';
66
import { PluginManager } from './plugins/PluginManager';
77
import { ArgumentStore } from './structures/ArgumentStore';
88
import { CommandStore } from './structures/CommandStore';
9+
import { InteractionHandlerStore } from './structures/InteractionHandlerStore';
910
import { ListenerStore } from './structures/ListenerStore';
1011
import { PreconditionStore } from './structures/PreconditionStore';
1112
import { BucketScope, PluginHook } from './types/Enums';
1213
import { Events } from './types/Events';
14+
import { acquire } from './utils/application-commands/ApplicationCommandRegistries';
1315
import { ILogger, LogLevel } from './utils/logger/ILogger';
1416
import { Logger } from './utils/logger/Logger';
1517

18+
container.applicationCommandRegistries = { acquire };
19+
20+
const optionalListenersPath = join(__dirname, '..', 'optional-listeners');
21+
1622
/**
1723
* A valid prefix in Sapphire.
1824
* * `string`: a single prefix, e.g. `'!'`.
@@ -103,12 +109,19 @@ export interface SapphireClientOptions {
103109
enableLoaderTraceLoggings?: boolean;
104110

105111
/**
106-
* If Sapphire should load our pre-included error event listeners that log any encountered errors to the {@link SapphireClient.logger} instance
112+
* If Sapphire should load the pre-included error event listeners that log any encountered errors to the {@link SapphireClient.logger} instance
107113
* @since 1.0.0
108114
* @default true
109115
*/
110116
loadDefaultErrorListeners?: boolean;
111117

118+
/**
119+
* If Sapphire should load the pre-included message command listeners that are used to process incoming messages for commands.
120+
* @since 3.0.0
121+
* @default false
122+
*/
123+
loadMessageCommandListeners?: boolean;
124+
112125
/**
113126
* Controls whether the bot will automatically appear to be typing when a command is accepted.
114127
* @default false
@@ -175,7 +188,7 @@ export class SapphireClient<Ready extends boolean = boolean> extends Client<Read
175188
public id: Snowflake | null = null;
176189

177190
/**
178-
* The method to be overriden by the developer.
191+
* The method to be overridden by the developer.
179192
* @since 1.0.0
180193
* @return A string for a single prefix, an array of strings for matching multiple, or null for no match (mention prefix only).
181194
* @example
@@ -244,12 +257,21 @@ export class SapphireClient<Ready extends boolean = boolean> extends Client<Read
244257
}
245258

246259
this.id = options.id ?? null;
260+
247261
this.stores
248262
.register(new ArgumentStore().registerPath(join(__dirname, '..', 'arguments'))) //
249263
.register(new CommandStore())
264+
.register(new InteractionHandlerStore())
250265
.register(new ListenerStore().registerPath(join(__dirname, '..', 'listeners')))
251266
.register(new PreconditionStore().registerPath(join(__dirname, '..', 'preconditions')));
252-
if (options.loadDefaultErrorListeners !== false) this.stores.get('listeners').registerPath(join(__dirname, '..', 'errorListeners'));
267+
268+
if (options.loadDefaultErrorListeners !== false) {
269+
this.stores.get('listeners').registerPath(join(optionalListenersPath, 'error-listeners'));
270+
}
271+
272+
if (options.loadMessageCommandListeners === true) {
273+
this.stores.get('listeners').registerPath(join(optionalListenersPath, 'message-command-listeners'));
274+
}
253275

254276
for (const plugin of SapphireClient.plugins.values(PluginHook.PostInitialization)) {
255277
plugin.hook.call(this, options);
@@ -325,11 +347,15 @@ declare module '@sapphire/pieces' {
325347
client: SapphireClient;
326348
logger: ILogger;
327349
stores: StoreRegistry;
350+
applicationCommandRegistries: {
351+
acquire: typeof acquire;
352+
};
328353
}
329354

330355
interface StoreRegistryEntries {
331356
arguments: ArgumentStore;
332357
commands: CommandStore;
358+
'interaction-handlers': InteractionHandlerStore;
333359
listeners: ListenerStore;
334360
preconditions: PreconditionStore;
335361
}

src/lib/errors/Identifiers.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,9 @@ export const enum Identifiers {
5454
PreconditionClientPermissionsNoPermissions = 'preconditionClientPermissionsNoPermissions',
5555
PreconditionUserPermissions = 'preconditionUserPermissions',
5656
PreconditionUserPermissionsNoPermissions = 'preconditionUserPermissionsNoPermissions',
57-
PreconditionThreadOnly = 'preconditionThreadOnly'
57+
PreconditionThreadOnly = 'preconditionThreadOnly',
58+
59+
PreconditionMissingMessageHandler = 'preconditionMissingMessageHandler',
60+
PreconditionMissingChatInputHandler = 'preconditionMissingChatInputHandler',
61+
PreconditionMissingContextMenuHandler = 'preconditionMissingContextMenuHandler'
5862
}

src/lib/parsers/Args.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { ArgumentError } from '../errors/ArgumentError';
1919
import { Identifiers } from '../errors/Identifiers';
2020
import { UserError } from '../errors/UserError';
2121
import type { Argument, IArgument } from '../structures/Argument';
22-
import type { Command } from '../structures/Command';
22+
import type { MessageCommand } from '../structures/Command';
2323
import { isSome, maybe, Maybe } from './Maybe';
2424
import { Err, err, isErr, isOk, ok, Ok, Result } from './Result';
2525

@@ -35,12 +35,12 @@ export class Args {
3535
/**
3636
* The command that is being run.
3737
*/
38-
public readonly command: Command;
38+
public readonly command: MessageCommand;
3939

4040
/**
4141
* The context of the command being run.
4242
*/
43-
public readonly commandContext: Command.RunContext;
43+
public readonly commandContext: MessageCommand.RunContext;
4444

4545
/**
4646
* The internal Lexure parser.
@@ -54,7 +54,7 @@ export class Args {
5454
*/
5555
private readonly states: Lexure.ArgsState[] = [];
5656

57-
public constructor(message: Message, command: Command, parser: Lexure.Args, context: Command.RunContext) {
57+
public constructor(message: Message, command: MessageCommand, parser: Lexure.Args, context: MessageCommand.RunContext) {
5858
this.message = message;
5959
this.command = command;
6060
this.parser = parser;

src/lib/parsers/Maybe.ts

+2
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,5 @@ export function isMaybe<T>(x: unknown): x is Maybe<T>;
9494
export function isMaybe<T>(x: Maybe<T> | unknown): x is Maybe<T> {
9595
return typeof x === 'object' && x !== null && typeof Reflect.get(x, 'exists') === 'boolean';
9696
}
97+
98+
export type UnwrapMaybeValue<T extends Maybe<unknown>> = T extends Some<infer V> ? V : never;

src/lib/structures/Argument.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { ArgumentError } from '../errors/ArgumentError';
55
import type { UserError } from '../errors/UserError';
66
import { Args } from '../parsers/Args';
77
import type { Result } from '../parsers/Result';
8-
import type { Command } from './Command';
8+
import type { MessageCommand } from './Command';
99

1010
/**
1111
* Defines a synchronous result of an {@link Argument}, check {@link Argument.AsyncResult} for the asynchronous version.
@@ -115,8 +115,8 @@ export interface ArgumentContext<T = unknown> extends Record<PropertyKey, unknow
115115
argument: IArgument<T>;
116116
args: Args;
117117
message: Message;
118-
command: Command;
119-
commandContext: Command.RunContext;
118+
command: MessageCommand;
119+
commandContext: MessageCommand.RunContext;
120120
minimum?: number;
121121
maximum?: number;
122122
inclusive?: boolean;

0 commit comments

Comments
 (0)