commandkit 0.1.11-dev.20250306101654 → 0.1.11-dev.20250307192025
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +290 -252
- package/dist/index.js +967 -426
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as discord_js from 'discord.js';
|
|
2
|
-
import { RESTPostAPIApplicationCommandsJSONBody, Client, Interaction, CacheType, PermissionsString, ChatInputCommandInteraction, ContextMenuCommandInteraction, UserContextMenuCommandInteraction, MessageContextMenuCommandInteraction, AutocompleteInteraction, ClientEvents, Awaitable, ButtonBuilder, ButtonInteraction, Events, ModalBuilder, ModalSubmitInteraction, ActionRowBuilder, TextInputBuilder, ButtonStyle, ComponentEmojiResolvable, TextInputStyle, Locale, Message as Message$1, ApplicationCommandOptionType, GuildMember, Attachment, User, Role, CommandInteractionOption, SlashCommandBuilder, ContextMenuCommandBuilder, PartialMessage } from 'discord.js';
|
|
2
|
+
import { RESTPostAPIApplicationCommandsJSONBody, Client, Interaction, CacheType, PermissionsString, ChatInputCommandInteraction, ContextMenuCommandInteraction, UserContextMenuCommandInteraction, MessageContextMenuCommandInteraction, AutocompleteInteraction, ClientEvents, Awaitable, ButtonBuilder, ButtonInteraction, Events, ModalBuilder, ModalSubmitInteraction, ActionRowBuilder, TextInputBuilder, ButtonStyle, ComponentEmojiResolvable, TextInputStyle, Locale, Message as Message$1, ApplicationCommandOptionType, GuildMember, Attachment, User, Role, CommandInteractionOption, Collection, SlashCommandBuilder, ContextMenuCommandBuilder, PartialMessage } from 'discord.js';
|
|
3
3
|
import EventEmitter from 'node:events';
|
|
4
4
|
import { Channel } from 'diagnostics_channel';
|
|
5
5
|
import * as commander from 'commander';
|
|
@@ -1008,163 +1008,154 @@ declare class MiddlewareContext<T extends CommandExecutionMode = CommandExecutio
|
|
|
1008
1008
|
}
|
|
1009
1009
|
|
|
1010
1010
|
/**
|
|
1011
|
-
*
|
|
1012
|
-
*
|
|
1011
|
+
* Represents a command file info parsed from the file system.
|
|
1012
|
+
* It does not contain any command specific data, as that's loaded later by the command handler.
|
|
1013
1013
|
*/
|
|
1014
|
-
|
|
1015
|
-
/**
|
|
1016
|
-
* Maps file type identifiers to their respective matchers.
|
|
1017
|
-
* Used to identify command and middleware files in the directory structure.
|
|
1018
|
-
*/
|
|
1019
|
-
type CommandsRouterMatchersMap = Record<'command' | 'middleware', CommandsRouterMatcher>;
|
|
1020
|
-
/**
|
|
1021
|
-
* Configuration options for the CommandsRouter
|
|
1022
|
-
*/
|
|
1023
|
-
interface CommandsRouterOptions {
|
|
1014
|
+
interface ParsedCommand {
|
|
1024
1015
|
/**
|
|
1025
|
-
* The
|
|
1016
|
+
* The unique identifier of the command. This is used to distinguish between commands that may have the same name.
|
|
1026
1017
|
*/
|
|
1027
|
-
|
|
1018
|
+
id: string;
|
|
1028
1019
|
/**
|
|
1029
|
-
* The
|
|
1020
|
+
* The file name of the command.
|
|
1030
1021
|
*/
|
|
1031
|
-
matcher?: Partial<CommandsRouterMatchersMap>;
|
|
1032
|
-
}
|
|
1033
|
-
/**
|
|
1034
|
-
* Represents a parsed command with its metadata
|
|
1035
|
-
* @interface ParsedCommand
|
|
1036
|
-
*/
|
|
1037
|
-
interface ParsedCommand {
|
|
1038
|
-
/** Command name derived from the file name without extension */
|
|
1039
1022
|
name: string;
|
|
1040
|
-
/**
|
|
1023
|
+
/**
|
|
1024
|
+
* The absolute path to the command file.
|
|
1025
|
+
*/
|
|
1041
1026
|
path: string;
|
|
1042
|
-
/**
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
/**
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1027
|
+
/**
|
|
1028
|
+
* The relative path from the cwd to the command file.
|
|
1029
|
+
*/
|
|
1030
|
+
relativePath: string;
|
|
1031
|
+
/**
|
|
1032
|
+
* The category of this command. This will be the parent directory segment that matches /(category)/ in the path.
|
|
1033
|
+
* When there are multiple segments, they are combined with a colon.
|
|
1034
|
+
* Example: `/commands/(games)/tictactoe.js` -> category is `games`
|
|
1035
|
+
* Example: `/commands/(games)/(fun)/tictactoe.js` -> category is `games:fun`
|
|
1036
|
+
* Category is `null` if the parent directory segment does not match `/(\w+)/`.
|
|
1037
|
+
*/
|
|
1051
1038
|
category: string | null;
|
|
1039
|
+
/**
|
|
1040
|
+
* Array of ids referencing the associated middleware for this command.
|
|
1041
|
+
*/
|
|
1042
|
+
middlewares: string[];
|
|
1043
|
+
/**
|
|
1044
|
+
* Array of ids referencing the associated subcommands for this command.
|
|
1045
|
+
*/
|
|
1046
|
+
subcommands: string[];
|
|
1052
1047
|
}
|
|
1053
1048
|
/**
|
|
1054
|
-
* Represents a parsed
|
|
1055
|
-
* @interface ParsedMiddleware
|
|
1049
|
+
* Represents a middleware file info parsed from the file system.
|
|
1056
1050
|
*/
|
|
1057
1051
|
interface ParsedMiddleware {
|
|
1058
|
-
/** Unique identifier used to reference this middleware */
|
|
1059
|
-
id: string;
|
|
1060
|
-
/** Middleware name derived from the file path */
|
|
1061
|
-
name: string;
|
|
1062
|
-
/** Path to the middleware file, relative to the entrypoint */
|
|
1063
|
-
path: string;
|
|
1064
|
-
/** Absolute path to the middleware file */
|
|
1065
|
-
fullPath: string;
|
|
1066
|
-
/** Category the middleware belongs to, if any */
|
|
1067
|
-
category: string | null;
|
|
1068
|
-
}
|
|
1069
|
-
/**
|
|
1070
|
-
* Complete tree structure of all commands and middleware
|
|
1071
|
-
* @interface CommandsTree
|
|
1072
|
-
*/
|
|
1073
|
-
interface CommandsTree {
|
|
1074
|
-
/** Map of command names to their parsed metadata */
|
|
1075
|
-
commands: Record<string, ParsedCommand>;
|
|
1076
|
-
/** Map of middleware IDs to their parsed metadata */
|
|
1077
|
-
middleware: Record<string, ParsedMiddleware>;
|
|
1078
|
-
}
|
|
1079
|
-
/**
|
|
1080
|
-
* Result of a successful command match operation
|
|
1081
|
-
* @interface CommandMatchResult
|
|
1082
|
-
*/
|
|
1083
|
-
interface CommandMatchResult {
|
|
1084
|
-
/** The matched command metadata */
|
|
1085
|
-
command: ParsedCommand;
|
|
1086
|
-
/** Array of middleware that apply to the matched command */
|
|
1087
|
-
middlewares: ParsedMiddleware[];
|
|
1088
|
-
}
|
|
1089
|
-
/**
|
|
1090
|
-
* CommandsRouter handles the discovery and routing of commands and middleware files
|
|
1091
|
-
* in a directory structure. It supports nested commands and middleware inheritance.
|
|
1092
|
-
*/
|
|
1093
|
-
declare class CommandsRouter {
|
|
1094
|
-
private readonly options;
|
|
1095
|
-
private commands;
|
|
1096
|
-
private middlewares;
|
|
1097
|
-
/**
|
|
1098
|
-
* Creates a new CommandsRouter instance
|
|
1099
|
-
* @param options - Configuration options for the router
|
|
1100
|
-
*/
|
|
1101
|
-
constructor(options: CommandsRouterOptions);
|
|
1102
1052
|
/**
|
|
1103
|
-
*
|
|
1053
|
+
* The unique identifier of the middleware. This is used to distinguish between middlewares that may have the same name.
|
|
1104
1054
|
*/
|
|
1105
|
-
|
|
1055
|
+
id: string;
|
|
1106
1056
|
/**
|
|
1107
|
-
*
|
|
1057
|
+
* The file name of the middleware.
|
|
1108
1058
|
*/
|
|
1109
|
-
|
|
1059
|
+
name: string;
|
|
1110
1060
|
/**
|
|
1111
|
-
*
|
|
1061
|
+
* The absolute path to the middleware file.
|
|
1112
1062
|
*/
|
|
1113
|
-
|
|
1114
|
-
commands: Map<string, ParsedCommand>;
|
|
1115
|
-
middleware: Map<string, ParsedMiddleware>;
|
|
1116
|
-
};
|
|
1063
|
+
path: string;
|
|
1117
1064
|
/**
|
|
1118
|
-
*
|
|
1065
|
+
* The relative path from the cwd to the middleware file.
|
|
1119
1066
|
*/
|
|
1120
|
-
|
|
1067
|
+
relativePath: string;
|
|
1121
1068
|
/**
|
|
1122
|
-
*
|
|
1123
|
-
* @param matcher - The matcher to use
|
|
1124
|
-
* @param path - The file path to test
|
|
1125
|
-
* @returns boolean indicating if the path matches
|
|
1069
|
+
* The category of this middleware. This will be the parent directory segment that matches /(category)/ in the path.
|
|
1126
1070
|
*/
|
|
1127
|
-
|
|
1071
|
+
category: string | null;
|
|
1072
|
+
}
|
|
1073
|
+
/**
|
|
1074
|
+
* Represents a subcommand file info parsed from the file system.
|
|
1075
|
+
*/
|
|
1076
|
+
interface ParsedSubCommand {
|
|
1128
1077
|
/**
|
|
1129
|
-
*
|
|
1130
|
-
* @param path - The absolute path to convert
|
|
1078
|
+
* The unique identifier of the subcommand. This is used to distinguish between subcommands that may have the same name.
|
|
1131
1079
|
*/
|
|
1132
|
-
|
|
1080
|
+
id: string;
|
|
1133
1081
|
/**
|
|
1134
|
-
*
|
|
1135
|
-
* @param commandOrSegment - Command name or array of path segments
|
|
1136
|
-
* @returns Matched command and its middlewares, or null if no match
|
|
1082
|
+
* The name of the subcommand.
|
|
1137
1083
|
*/
|
|
1138
|
-
|
|
1084
|
+
name: string;
|
|
1139
1085
|
/**
|
|
1140
|
-
*
|
|
1086
|
+
* The group name of the subcommand. This is used to group subcommands together in the Discord UI.
|
|
1141
1087
|
*/
|
|
1142
|
-
|
|
1088
|
+
group: string | null;
|
|
1143
1089
|
/**
|
|
1144
|
-
*
|
|
1090
|
+
* The absolute path to the subcommand file.
|
|
1145
1091
|
*/
|
|
1146
|
-
|
|
1092
|
+
path: string;
|
|
1147
1093
|
/**
|
|
1148
|
-
*
|
|
1149
|
-
* @returns Promise resolving to the complete commands tree
|
|
1094
|
+
* The relative path from the cwd to the subcommand file.
|
|
1150
1095
|
*/
|
|
1151
|
-
|
|
1096
|
+
relativePath: string;
|
|
1152
1097
|
/**
|
|
1153
|
-
*
|
|
1154
|
-
* @returns CommandsTree containing all commands and middleware
|
|
1098
|
+
* Array of ids referencing the associated middleware for this subcommand.
|
|
1155
1099
|
*/
|
|
1156
|
-
|
|
1100
|
+
middlewares: string[];
|
|
1101
|
+
}
|
|
1102
|
+
/**
|
|
1103
|
+
* Represents a JSON compatible object that contains all the parsed commands, middlewares, and subcommands.
|
|
1104
|
+
*/
|
|
1105
|
+
interface CommandTree {
|
|
1106
|
+
commands: Record<string, ParsedCommand>;
|
|
1107
|
+
middlewares: Record<string, ParsedMiddleware>;
|
|
1108
|
+
subcommands: Record<string, ParsedSubCommand>;
|
|
1109
|
+
}
|
|
1110
|
+
/**
|
|
1111
|
+
* Represents the scanned and parsed command files.
|
|
1112
|
+
*/
|
|
1113
|
+
interface ParsedCommandData {
|
|
1114
|
+
commands: Collection<string, ParsedCommand>;
|
|
1115
|
+
middlewares: Collection<string, ParsedMiddleware>;
|
|
1116
|
+
subcommands: Collection<string, ParsedSubCommand>;
|
|
1117
|
+
}
|
|
1118
|
+
interface CommandsRouterOptions {
|
|
1157
1119
|
/**
|
|
1158
|
-
*
|
|
1159
|
-
* @param dir - Directory to scan
|
|
1160
|
-
* @param entries - Accumulator for found files
|
|
1161
|
-
* @returns Promise resolving to array of file paths
|
|
1120
|
+
* The path to the directory containing the command files.
|
|
1162
1121
|
*/
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
private
|
|
1167
|
-
private
|
|
1122
|
+
entrypoint: string;
|
|
1123
|
+
}
|
|
1124
|
+
declare class CommandsRouter {
|
|
1125
|
+
private options;
|
|
1126
|
+
private commands;
|
|
1127
|
+
private middlewares;
|
|
1128
|
+
private subcommands;
|
|
1129
|
+
constructor(options: CommandsRouterOptions);
|
|
1130
|
+
isValidPath(): boolean;
|
|
1131
|
+
get entrypoint(): string;
|
|
1132
|
+
clear(): void;
|
|
1133
|
+
reload(): Promise<CommandTree>;
|
|
1134
|
+
visualize(): string;
|
|
1135
|
+
getData(): ParsedCommandData;
|
|
1136
|
+
toJSON(): CommandTree;
|
|
1137
|
+
scan(): Promise<CommandTree>;
|
|
1138
|
+
private scanDeep;
|
|
1139
|
+
private processMiddleware;
|
|
1140
|
+
private processSubcommand;
|
|
1141
|
+
private processCommand;
|
|
1142
|
+
/**
|
|
1143
|
+
* Gets the appropriate file name, handling index files specially
|
|
1144
|
+
* For index files, it returns the parent directory name (excluding category markers)
|
|
1145
|
+
*/
|
|
1146
|
+
private getAppropriateFileName;
|
|
1147
|
+
/**
|
|
1148
|
+
* Extract the clean directory name, removing any category markers
|
|
1149
|
+
*/
|
|
1150
|
+
private getDirectoryName;
|
|
1151
|
+
private isCategoryDirectory;
|
|
1152
|
+
private applyMiddlewareToCommands;
|
|
1153
|
+
private applySubcommandToCommands;
|
|
1154
|
+
private extractCategory;
|
|
1155
|
+
private getRelativePath;
|
|
1156
|
+
private isMiddleware;
|
|
1157
|
+
private shouldIgnore;
|
|
1158
|
+
private extractName;
|
|
1168
1159
|
}
|
|
1169
1160
|
|
|
1170
1161
|
/**
|
|
@@ -1261,6 +1252,10 @@ declare class CommandRegistrar {
|
|
|
1261
1252
|
* Gets the commands data.
|
|
1262
1253
|
*/
|
|
1263
1254
|
getCommandsData(): CommandData[];
|
|
1255
|
+
/**
|
|
1256
|
+
* Process and merge subcommands into the parent command's options
|
|
1257
|
+
*/
|
|
1258
|
+
private processSubcommands;
|
|
1264
1259
|
/**
|
|
1265
1260
|
* Registers loaded commands.
|
|
1266
1261
|
*/
|
|
@@ -1290,6 +1285,7 @@ interface AppCommandMiddleware {
|
|
|
1290
1285
|
interface LoadedCommand {
|
|
1291
1286
|
command: ParsedCommand;
|
|
1292
1287
|
data: AppCommand;
|
|
1288
|
+
subcommands?: ParsedSubCommand[];
|
|
1293
1289
|
guilds?: string[];
|
|
1294
1290
|
}
|
|
1295
1291
|
interface LoadedMiddleware {
|
|
@@ -1298,29 +1294,192 @@ interface LoadedMiddleware {
|
|
|
1298
1294
|
}
|
|
1299
1295
|
interface PreparedAppCommandExecution {
|
|
1300
1296
|
command: LoadedCommand;
|
|
1297
|
+
subcommand?: LoadedSubCommand | null;
|
|
1301
1298
|
middlewares: LoadedMiddleware[];
|
|
1302
1299
|
messageCommandParser?: MessageCommandParser;
|
|
1303
1300
|
}
|
|
1301
|
+
interface LoadedSubCommand {
|
|
1302
|
+
subcommand: ParsedSubCommand;
|
|
1303
|
+
data: AppCommand;
|
|
1304
|
+
}
|
|
1304
1305
|
type CommandBuilderLike = SlashCommandBuilder | ContextMenuCommandBuilder | Record<string, any>;
|
|
1305
1306
|
declare class AppCommandHandler {
|
|
1306
1307
|
readonly commandkit: CommandKit;
|
|
1307
1308
|
private loadedCommands;
|
|
1309
|
+
private loadedSubCommands;
|
|
1308
1310
|
private loadedMiddlewares;
|
|
1311
|
+
private commandNameToId;
|
|
1312
|
+
private subcommandPathToId;
|
|
1309
1313
|
readonly registrar: CommandRegistrar;
|
|
1310
1314
|
private onInteraction;
|
|
1311
1315
|
private onMessageCreate;
|
|
1312
1316
|
private onMessageUpdate;
|
|
1313
1317
|
constructor(commandkit: CommandKit);
|
|
1314
1318
|
getCommandsArray(): LoadedCommand[];
|
|
1319
|
+
/**
|
|
1320
|
+
* Get subcommand data by ID for the command registrar
|
|
1321
|
+
*/
|
|
1322
|
+
getSubcommandData(id: string): any;
|
|
1315
1323
|
registerCommandHandler(): void;
|
|
1316
1324
|
getExecutionMode(source: Interaction | Message$1): CommandExecutionMode;
|
|
1317
|
-
runCommand(
|
|
1325
|
+
runCommand(prepared: PreparedAppCommandExecution, source: Interaction | Message$1): Promise<void>;
|
|
1318
1326
|
prepareCommandRun(source: Interaction | Message$1): Promise<PreparedAppCommandExecution | null>;
|
|
1319
1327
|
reloadCommands(): Promise<void>;
|
|
1320
1328
|
loadCommands(): Promise<void>;
|
|
1329
|
+
private loadMiddleware;
|
|
1330
|
+
private loadCommand;
|
|
1331
|
+
private loadSubcommand;
|
|
1321
1332
|
applyLocalizations(command: CommandBuilderLike): Promise<discord_js.RESTPostAPIContextMenuApplicationCommandsJSONBody | CommandBuilderLike>;
|
|
1322
1333
|
}
|
|
1323
1334
|
|
|
1335
|
+
declare class MemoryCache extends CacheProvider {
|
|
1336
|
+
#private;
|
|
1337
|
+
get<T>(key: string): Promise<CacheEntry<T> | undefined>;
|
|
1338
|
+
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
1339
|
+
exists(key: string): Promise<boolean>;
|
|
1340
|
+
delete(key: string): Promise<void>;
|
|
1341
|
+
clear(): Promise<void>;
|
|
1342
|
+
expire(key: string, ttl: number): Promise<void>;
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
/**
|
|
1346
|
+
* Context for managing cache operations within an async scope
|
|
1347
|
+
*/
|
|
1348
|
+
interface CacheContext {
|
|
1349
|
+
params: {
|
|
1350
|
+
/** Custom name for the cache entry */
|
|
1351
|
+
name?: string;
|
|
1352
|
+
/** Time-to-live in milliseconds */
|
|
1353
|
+
ttl?: number;
|
|
1354
|
+
};
|
|
1355
|
+
}
|
|
1356
|
+
/**
|
|
1357
|
+
* Represents an async function that can be cached
|
|
1358
|
+
* @template R - Array of argument types
|
|
1359
|
+
* @template T - Return type
|
|
1360
|
+
*/
|
|
1361
|
+
type AsyncFunction<R extends any[] = any[], T = any> = (...args: R) => Promise<T>;
|
|
1362
|
+
/**
|
|
1363
|
+
* Configuration options for cache behavior
|
|
1364
|
+
*/
|
|
1365
|
+
interface CacheMetadata {
|
|
1366
|
+
/** Time-to-live duration in milliseconds or as a string (e.g., '1h', '5m') */
|
|
1367
|
+
ttl?: number | string;
|
|
1368
|
+
/** Custom name for the cache entry */
|
|
1369
|
+
name?: string;
|
|
1370
|
+
}
|
|
1371
|
+
/**
|
|
1372
|
+
* Internal cache implementation
|
|
1373
|
+
* @internal
|
|
1374
|
+
* @private
|
|
1375
|
+
* This is used directly by the compiler if the function is annotated with `"use cache"` directive.
|
|
1376
|
+
* @example
|
|
1377
|
+
* ```ts
|
|
1378
|
+
* async function myCachedFunction() {
|
|
1379
|
+
* "use cache";
|
|
1380
|
+
* // can use cacheTag() and cacheLife() here to customize cache behavior
|
|
1381
|
+
* return await db.query('SELECT * FROM users');
|
|
1382
|
+
* }
|
|
1383
|
+
* ```
|
|
1384
|
+
*/
|
|
1385
|
+
declare function useCache<R extends any[], F extends AsyncFunction<R>>(fn: F, id?: string, params?: CacheMetadata): F;
|
|
1386
|
+
/**
|
|
1387
|
+
* Wraps an async function with caching capability
|
|
1388
|
+
* @template R - Array of argument types
|
|
1389
|
+
* @template F - Type of the async function
|
|
1390
|
+
* @param fn - The async function to cache
|
|
1391
|
+
* @param params - Optional cache configuration
|
|
1392
|
+
* @returns The wrapped function with caching behavior
|
|
1393
|
+
* @example
|
|
1394
|
+
* ```ts
|
|
1395
|
+
* const cachedFetch = cache(async (id: string) => {
|
|
1396
|
+
* return await db.findOne(id);
|
|
1397
|
+
* }, { ttl: '1h' });
|
|
1398
|
+
* ```
|
|
1399
|
+
*/
|
|
1400
|
+
declare function cache<R extends any[], F extends AsyncFunction<R>>(fn: F, params?: CacheMetadata): F;
|
|
1401
|
+
/**
|
|
1402
|
+
* Sets a custom identifier for the current cache operation
|
|
1403
|
+
* @param tag - The custom cache tag
|
|
1404
|
+
* @throws {Error} When called outside a cached function or without a tag
|
|
1405
|
+
* @example
|
|
1406
|
+
* ```ts
|
|
1407
|
+
* const fetchUser = cache(async (id: string) => {
|
|
1408
|
+
* cacheTag(`user:${id}`);
|
|
1409
|
+
* return await db.users.findOne(id);
|
|
1410
|
+
* });
|
|
1411
|
+
* ```
|
|
1412
|
+
*/
|
|
1413
|
+
declare function cacheTag(tag: string): void;
|
|
1414
|
+
/**
|
|
1415
|
+
* Sets the TTL for the current cache operation
|
|
1416
|
+
* @param ttl - Time-to-live in milliseconds or as a string (e.g., '1h', '5m')
|
|
1417
|
+
* @throws {Error} When called outside a cached function or with invalid TTL
|
|
1418
|
+
* @example
|
|
1419
|
+
* ```ts
|
|
1420
|
+
* const fetchData = cache(async () => {
|
|
1421
|
+
* cacheLife('30m');
|
|
1422
|
+
* return await expensiveOperation();
|
|
1423
|
+
* });
|
|
1424
|
+
* ```
|
|
1425
|
+
*/
|
|
1426
|
+
declare function cacheLife(ttl: number | string): void;
|
|
1427
|
+
/**
|
|
1428
|
+
* Removes a cached value by its tag
|
|
1429
|
+
* @param tag - The cache tag to invalidate
|
|
1430
|
+
* @throws {Error} When the cache key is not found
|
|
1431
|
+
* @example
|
|
1432
|
+
* ```ts
|
|
1433
|
+
* await invalidate('user:123');
|
|
1434
|
+
* ```
|
|
1435
|
+
*/
|
|
1436
|
+
declare function invalidate(tag: string): Promise<void>;
|
|
1437
|
+
/**
|
|
1438
|
+
* Forces a refresh of cached data by its tag (on-demand revalidation)
|
|
1439
|
+
* @template T - Type of the cached value
|
|
1440
|
+
* @param tag - The cache tag to revalidate
|
|
1441
|
+
* @param args - Arguments to pass to the cached function
|
|
1442
|
+
* @returns Fresh data from the cached function
|
|
1443
|
+
* @throws {Error} When the cache key or function is not found
|
|
1444
|
+
* @example
|
|
1445
|
+
* ```ts
|
|
1446
|
+
* const freshData = await revalidate('user:123');
|
|
1447
|
+
* ```
|
|
1448
|
+
*/
|
|
1449
|
+
declare function revalidate<T = unknown>(tag: string, ...args: any[]): Promise<T>;
|
|
1450
|
+
/**
|
|
1451
|
+
* Checks if a function is wrapped with cache functionality
|
|
1452
|
+
* @param fn - Function to check
|
|
1453
|
+
* @returns True if the function is cached
|
|
1454
|
+
* @example
|
|
1455
|
+
* ```ts
|
|
1456
|
+
* if (isCachedFunction(myFunction)) {
|
|
1457
|
+
* console.log('Function is cached');
|
|
1458
|
+
* }
|
|
1459
|
+
* ```
|
|
1460
|
+
*/
|
|
1461
|
+
declare function isCachedFunction(fn: GenericFunction): boolean;
|
|
1462
|
+
|
|
1463
|
+
type ListenerFunction = GenericFunction | AsyncFunction;
|
|
1464
|
+
declare class CommandKitEventsChannel {
|
|
1465
|
+
readonly commandkit: CommandKit;
|
|
1466
|
+
private emitter;
|
|
1467
|
+
constructor(commandkit: CommandKit);
|
|
1468
|
+
to(namespace: string): {
|
|
1469
|
+
on: (event: string, listener: ListenerFunction) => void;
|
|
1470
|
+
off: (event: string, listener: ListenerFunction) => void;
|
|
1471
|
+
once: (event: string, listener: ListenerFunction) => void;
|
|
1472
|
+
emit: (event: string, ...args: any[]) => boolean;
|
|
1473
|
+
removeAllListeners: (event: string) => void;
|
|
1474
|
+
};
|
|
1475
|
+
on(namespace: string, event: string, listener: ListenerFunction): void;
|
|
1476
|
+
off(namespace: string, event: string, listener: ListenerFunction): void;
|
|
1477
|
+
once(namespace: string, event: string, listener: ListenerFunction): void;
|
|
1478
|
+
emit(namespace: string, event: string, ...args: any[]): boolean;
|
|
1479
|
+
removeAllListeners(namespace: string): void;
|
|
1480
|
+
removeAllListeners(namespace: string, event: string): void;
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1324
1483
|
declare class AppEventsHandler {
|
|
1325
1484
|
readonly commandkit: CommandKit;
|
|
1326
1485
|
private loadedEvents;
|
|
@@ -1484,6 +1643,7 @@ declare class DefaultLocalizationStrategy implements LocalizationStrategy {
|
|
|
1484
1643
|
private translations;
|
|
1485
1644
|
constructor(commandkit: CommandKit);
|
|
1486
1645
|
locateTranslation(scope: string, locale: Locale): Promise<Translation | null>;
|
|
1646
|
+
private generateLocaleTypes;
|
|
1487
1647
|
getTranslationStrict(scope: string, locale: Locale): Promise<Translation>;
|
|
1488
1648
|
getTranslation(scope: string, locale: Locale): Promise<Translation | null>;
|
|
1489
1649
|
translate(request: LocalizationTranslationRequest): Promise<TranslationResult>;
|
|
@@ -1561,140 +1721,13 @@ declare abstract class RuntimePlugin<T extends PluginOptions = PluginOptions> ex
|
|
|
1561
1721
|
executeCommand(ctx: CommandKitPluginRuntime, source: Interaction | Message$1, command: PreparedAppCommandExecution, execute: () => Promise<any>): Promise<boolean>;
|
|
1562
1722
|
}
|
|
1563
1723
|
|
|
1564
|
-
declare class MemoryCache extends CacheProvider {
|
|
1565
|
-
#private;
|
|
1566
|
-
get<T>(key: string): Promise<CacheEntry<T> | undefined>;
|
|
1567
|
-
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
1568
|
-
exists(key: string): Promise<boolean>;
|
|
1569
|
-
delete(key: string): Promise<void>;
|
|
1570
|
-
clear(): Promise<void>;
|
|
1571
|
-
expire(key: string, ttl: number): Promise<void>;
|
|
1572
|
-
}
|
|
1573
|
-
|
|
1574
|
-
/**
|
|
1575
|
-
* Context for managing cache operations within an async scope
|
|
1576
|
-
*/
|
|
1577
|
-
interface CacheContext {
|
|
1578
|
-
params: {
|
|
1579
|
-
/** Custom name for the cache entry */
|
|
1580
|
-
name?: string;
|
|
1581
|
-
/** Time-to-live in milliseconds */
|
|
1582
|
-
ttl?: number;
|
|
1583
|
-
};
|
|
1584
|
-
}
|
|
1585
|
-
/**
|
|
1586
|
-
* Represents an async function that can be cached
|
|
1587
|
-
* @template R - Array of argument types
|
|
1588
|
-
* @template T - Return type
|
|
1589
|
-
*/
|
|
1590
|
-
type AsyncFunction<R extends any[] = any[], T = any> = (...args: R) => Promise<T>;
|
|
1591
|
-
/**
|
|
1592
|
-
* Configuration options for cache behavior
|
|
1593
|
-
*/
|
|
1594
|
-
interface CacheMetadata {
|
|
1595
|
-
/** Time-to-live duration in milliseconds or as a string (e.g., '1h', '5m') */
|
|
1596
|
-
ttl?: number | string;
|
|
1597
|
-
/** Custom name for the cache entry */
|
|
1598
|
-
name?: string;
|
|
1599
|
-
}
|
|
1600
|
-
/**
|
|
1601
|
-
* Internal cache implementation
|
|
1602
|
-
* @internal
|
|
1603
|
-
* @private
|
|
1604
|
-
* This is used directly by the compiler if the function is annotated with `"use cache"` directive.
|
|
1605
|
-
* @example
|
|
1606
|
-
* ```ts
|
|
1607
|
-
* async function myCachedFunction() {
|
|
1608
|
-
* "use cache";
|
|
1609
|
-
* // can use cacheTag() and cacheLife() here to customize cache behavior
|
|
1610
|
-
* return await db.query('SELECT * FROM users');
|
|
1611
|
-
* }
|
|
1612
|
-
* ```
|
|
1613
|
-
*/
|
|
1614
|
-
declare function useCache<R extends any[], F extends AsyncFunction<R>>(fn: F, id?: string, params?: CacheMetadata): F;
|
|
1615
|
-
/**
|
|
1616
|
-
* Wraps an async function with caching capability
|
|
1617
|
-
* @template R - Array of argument types
|
|
1618
|
-
* @template F - Type of the async function
|
|
1619
|
-
* @param fn - The async function to cache
|
|
1620
|
-
* @param params - Optional cache configuration
|
|
1621
|
-
* @returns The wrapped function with caching behavior
|
|
1622
|
-
* @example
|
|
1623
|
-
* ```ts
|
|
1624
|
-
* const cachedFetch = cache(async (id: string) => {
|
|
1625
|
-
* return await db.findOne(id);
|
|
1626
|
-
* }, { ttl: '1h' });
|
|
1627
|
-
* ```
|
|
1628
|
-
*/
|
|
1629
|
-
declare function cache<R extends any[], F extends AsyncFunction<R>>(fn: F, params?: CacheMetadata): F;
|
|
1630
|
-
/**
|
|
1631
|
-
* Sets a custom identifier for the current cache operation
|
|
1632
|
-
* @param tag - The custom cache tag
|
|
1633
|
-
* @throws {Error} When called outside a cached function or without a tag
|
|
1634
|
-
* @example
|
|
1635
|
-
* ```ts
|
|
1636
|
-
* const fetchUser = cache(async (id: string) => {
|
|
1637
|
-
* cacheTag(`user:${id}`);
|
|
1638
|
-
* return await db.users.findOne(id);
|
|
1639
|
-
* });
|
|
1640
|
-
* ```
|
|
1641
|
-
*/
|
|
1642
|
-
declare function cacheTag(tag: string): void;
|
|
1643
|
-
/**
|
|
1644
|
-
* Sets the TTL for the current cache operation
|
|
1645
|
-
* @param ttl - Time-to-live in milliseconds or as a string (e.g., '1h', '5m')
|
|
1646
|
-
* @throws {Error} When called outside a cached function or with invalid TTL
|
|
1647
|
-
* @example
|
|
1648
|
-
* ```ts
|
|
1649
|
-
* const fetchData = cache(async () => {
|
|
1650
|
-
* cacheLife('30m');
|
|
1651
|
-
* return await expensiveOperation();
|
|
1652
|
-
* });
|
|
1653
|
-
* ```
|
|
1654
|
-
*/
|
|
1655
|
-
declare function cacheLife(ttl: number | string): void;
|
|
1656
|
-
/**
|
|
1657
|
-
* Removes a cached value by its tag
|
|
1658
|
-
* @param tag - The cache tag to invalidate
|
|
1659
|
-
* @throws {Error} When the cache key is not found
|
|
1660
|
-
* @example
|
|
1661
|
-
* ```ts
|
|
1662
|
-
* await invalidate('user:123');
|
|
1663
|
-
* ```
|
|
1664
|
-
*/
|
|
1665
|
-
declare function invalidate(tag: string): Promise<void>;
|
|
1666
|
-
/**
|
|
1667
|
-
* Forces a refresh of cached data by its tag (on-demand revalidation)
|
|
1668
|
-
* @template T - Type of the cached value
|
|
1669
|
-
* @param tag - The cache tag to revalidate
|
|
1670
|
-
* @param args - Arguments to pass to the cached function
|
|
1671
|
-
* @returns Fresh data from the cached function
|
|
1672
|
-
* @throws {Error} When the cache key or function is not found
|
|
1673
|
-
* @example
|
|
1674
|
-
* ```ts
|
|
1675
|
-
* const freshData = await revalidate('user:123');
|
|
1676
|
-
* ```
|
|
1677
|
-
*/
|
|
1678
|
-
declare function revalidate<T = unknown>(tag: string, ...args: any[]): Promise<T>;
|
|
1679
|
-
/**
|
|
1680
|
-
* Checks if a function is wrapped with cache functionality
|
|
1681
|
-
* @param fn - Function to check
|
|
1682
|
-
* @returns True if the function is cached
|
|
1683
|
-
* @example
|
|
1684
|
-
* ```ts
|
|
1685
|
-
* if (isCachedFunction(myFunction)) {
|
|
1686
|
-
* console.log('Function is cached');
|
|
1687
|
-
* }
|
|
1688
|
-
* ```
|
|
1689
|
-
*/
|
|
1690
|
-
declare function isCachedFunction(fn: GenericFunction): boolean;
|
|
1691
|
-
|
|
1692
1724
|
declare class CommandKitPluginRuntime extends EventTarget {
|
|
1693
1725
|
readonly commandkit: CommandKit;
|
|
1694
1726
|
private plugins;
|
|
1695
1727
|
private onClientLogin;
|
|
1696
1728
|
constructor(commandkit: CommandKit);
|
|
1697
1729
|
getPlugin(pluginName: string): RuntimePlugin | null;
|
|
1730
|
+
softRegisterPlugin(plugin: RuntimePlugin): Promise<void>;
|
|
1698
1731
|
registerPlugin(plugin: RuntimePlugin): Promise<void>;
|
|
1699
1732
|
unregisterPlugin(plugin: RuntimePlugin): Promise<void>;
|
|
1700
1733
|
unregisterAllPlugins(): Promise<void>;
|
|
@@ -1719,6 +1752,7 @@ declare class CommandKit extends EventEmitter {
|
|
|
1719
1752
|
readonly commandHandler: AppCommandHandler;
|
|
1720
1753
|
readonly eventHandler: AppEventsHandler;
|
|
1721
1754
|
readonly plugins: CommandKitPluginRuntime;
|
|
1755
|
+
readonly events: CommandKitEventsChannel;
|
|
1722
1756
|
static instance: CommandKit | undefined;
|
|
1723
1757
|
/**
|
|
1724
1758
|
* Create a new command and event handler with CommandKit.
|
|
@@ -1732,6 +1766,10 @@ declare class CommandKit extends EventEmitter {
|
|
|
1732
1766
|
* @param token The application token to connect to the discord gateway. If not provided, it will use the `TOKEN` or `DISCORD_TOKEN` environment variable. If set to `false`, it will not login.
|
|
1733
1767
|
*/
|
|
1734
1768
|
start(token?: string | false): Promise<void>;
|
|
1769
|
+
/**
|
|
1770
|
+
* Loads all the plugins.
|
|
1771
|
+
*/
|
|
1772
|
+
loadPlugins(): Promise<void>;
|
|
1735
1773
|
/**
|
|
1736
1774
|
* Whether or not the commandkit application has started.
|
|
1737
1775
|
*/
|
|
@@ -1965,4 +2003,4 @@ declare const version: string;
|
|
|
1965
2003
|
*/
|
|
1966
2004
|
declare function bootstrapCommandkitCLI(argv: string[], options?: commander.ParseOptions | undefined): Promise<void>;
|
|
1967
2005
|
|
|
1968
|
-
export { ActionRow, type ActionRowProps, type AnyCommandExecute, type AnyCommandKitElement, AppCommandHandler, type AsyncFunction, type AutocompleteCommand, type AutocompleteCommandContext, type AutocompleteCommandMiddlewareContext, type AutocompleteProps, Button, type ButtonChildrenLike, ButtonKit, type ButtonKitPredicate, type ButtonProps, type CacheContext, type CacheEntry, type CacheMetadata, CacheProvider, type CommandContext, type CommandContextOptions, type CommandData, CommandExecutionMode, type CommandFileObject, CommandKit, type CommandKitButtonBuilderInteractionCollectorDispatch, type CommandKitButtonBuilderInteractionCollectorDispatchContextData, type CommandKitButtonBuilderOnEnd, type CommandKitConfiguration, type CommandKitElement, type CommandKitElementData, CommandKitEnvironment, type CommandKitEnvironmentInternalData, CommandKitEnvironmentType, type CommandKitLoggerOptions, type CommandKitModalBuilderInteractionCollectorDispatch, type CommandKitModalBuilderInteractionCollectorDispatchContextData, type CommandKitModalBuilderOnEnd, type CommandKitOptions, type
|
|
2006
|
+
export { ActionRow, type ActionRowProps, type AnyCommandExecute, type AnyCommandKitElement, AppCommandHandler, type AsyncFunction, type AutocompleteCommand, type AutocompleteCommandContext, type AutocompleteCommandMiddlewareContext, type AutocompleteProps, Button, type ButtonChildrenLike, ButtonKit, type ButtonKitPredicate, type ButtonProps, type CacheContext, type CacheEntry, type CacheMetadata, CacheProvider, type CommandContext, type CommandContextOptions, type CommandData, CommandExecutionMode, type CommandFileObject, CommandKit, type CommandKitButtonBuilderInteractionCollectorDispatch, type CommandKitButtonBuilderInteractionCollectorDispatchContextData, type CommandKitButtonBuilderOnEnd, type CommandKitConfiguration, type CommandKitElement, type CommandKitElementData, CommandKitEnvironment, type CommandKitEnvironmentInternalData, CommandKitEnvironmentType, type CommandKitLoggerOptions, type CommandKitModalBuilderInteractionCollectorDispatch, type CommandKitModalBuilderInteractionCollectorDispatchContextData, type CommandKitModalBuilderOnEnd, type CommandKitOptions, type CommandObject, type CommandOptions, type CommandProps, type CommandTree, CommandsRouter, type CommandsRouterOptions, Context, type ContextMenuCommandProps, type ContextParameters, DefaultLocalizationStrategy, DefaultLogger, ElementType, EventInterceptor, type EventInterceptorContextData, type EventInterceptorErrorHandler, EventsRouter, type EventsRouterOptions, type EventsTree, Fragment, type FragmentElementProps, type GenericFunction, type ILogger, type InteractionCommandContext, type InteractionCommandMiddlewareContext, type LoadedCommand, Localization, type LocalizationConfig, type LocalizationStrategy, type LocalizationTranslationRequest, Logger, type LoggerImpl, type MaybeArray, MemoryCache, type MessageCommand, type MessageCommandContext, type MessageCommandMiddlewareContext, MessageCommandOptions, type MessageCommandOptionsSchema, MessageCommandParser, type MessageContextMenuCommand, type MessageContextMenuCommandContext, type MessageContextMenuCommandMiddlewareContext, type MessageContextMenuCommandProps, MiddlewareContext, Modal, ModalKit, type ModalKitPredicate, type ModalProps, type OnButtonKitClick, type OnButtonKitEnd, type OnModalKitEnd, type OnModalKitSubmit, ParagraphInput, type ParsedCommand, type ParsedCommandData, type ParsedEvent, type ParsedMessageCommand, type ParsedMiddleware, type ParsedSubCommand, type PreparedAppCommandExecution, type ReloadOptions, ReloadType, ShortInput, type SlashCommand, type SlashCommandContext, type SlashCommandMiddlewareContext, type SlashCommandProps, TextInput, type TextInputProps, type TranslatableArguments, type TranslatableCommand, type TranslatableCommandOptions, type Translation, type TranslationResult, type Translator, type UserContextMenuCommand, type UserContextMenuCommandContext, type UserContextMenuCommandMiddlewareContext, type UserContextMenuCommandProps, type ValidationProps, afterCommand, bootstrapCommandkitCLI, cache, cacheLife, cacheTag, cancelAfterCommand, createElement, createLogger, CommandKit as default, defineConfig, dmOnly, exitContext, exitMiddleware, getCommandKit, getConfig, getContext, getElement, guildOnly, invalidate, isCachedFunction, isCommandKitElement, makeContextAwareFunction, redirect, rethrow, revalidate, useCache as super_duper_secret_internal_for_use_cache_directive_of_commandkit_cli_do_not_use_it_directly_or_you_will_be_fired_from_your_job_kthxbai, useEnvironment, version };
|