commandkit 0.1.9 โ 0.1.10-dev.20231229085439
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/README.md +1 -0
- package/bin/build.mjs +1 -0
- package/bin/development.mjs +3 -2
- package/dist/index.d.mts +5 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.js +38 -9
- package/dist/index.mjs +38 -9
- package/package.json +56 -56
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ CommandKit is a library that makes it easy to handle commands and events in your
|
|
|
19
19
|
- Multiple dev guilds, users, & roles support ๐ค
|
|
20
20
|
- Automatic command updates ๐ค
|
|
21
21
|
- REST registration behaviour ๐
|
|
22
|
+
- Easy command line interface ๐ฅ๏ธ
|
|
22
23
|
- And much more! ๐งช
|
|
23
24
|
|
|
24
25
|
## Documentation
|
package/bin/build.mjs
CHANGED
package/bin/development.mjs
CHANGED
|
@@ -61,10 +61,11 @@ export async function bootstrapDevelopmentServer(opts) {
|
|
|
61
61
|
silent: true,
|
|
62
62
|
entry: [src, '!dist', '!.commandkit', `!${outDir}`].filter(Boolean),
|
|
63
63
|
watch: watchMode,
|
|
64
|
+
async onSuccess() {
|
|
65
|
+
return await injectShims('.commandkit', main, false, requirePolyfill);
|
|
66
|
+
},
|
|
64
67
|
});
|
|
65
68
|
|
|
66
|
-
await injectShims('.commandkit', main, false, requirePolyfill);
|
|
67
|
-
|
|
68
69
|
status.succeed(
|
|
69
70
|
Colors.green(`Dev server started in ${(performance.now() - start).toFixed(2)}ms!\n`),
|
|
70
71
|
);
|
package/dist/index.d.mts
CHANGED
|
@@ -257,7 +257,8 @@ declare class CommandKit {
|
|
|
257
257
|
* The handler to run when a button is clicked. This handler is called with the interaction as the first argument.
|
|
258
258
|
* If the first argument is null, it means that the interaction collector has been destroyed.
|
|
259
259
|
*/
|
|
260
|
-
type CommandKitButtonBuilderInteractionCollectorDispatch = (interaction: ButtonInteraction
|
|
260
|
+
type CommandKitButtonBuilderInteractionCollectorDispatch = (interaction: ButtonInteraction) => Awaitable<void>;
|
|
261
|
+
type CommandKitButtonBuilderOnEnd = () => Awaitable<void>;
|
|
261
262
|
type CommandKitButtonBuilderInteractionCollectorDispatchContextData = {
|
|
262
263
|
/**
|
|
263
264
|
* The message to listen for button interactions on.
|
|
@@ -299,8 +300,8 @@ declare class ButtonKit extends ButtonBuilder {
|
|
|
299
300
|
* button.onClick(null);
|
|
300
301
|
* ```
|
|
301
302
|
*/
|
|
302
|
-
onClick(handler:
|
|
303
|
-
|
|
303
|
+
onClick(handler: CommandKitButtonBuilderInteractionCollectorDispatch, data?: CommandKitButtonBuilderInteractionCollectorDispatchContextData): this;
|
|
304
|
+
onEnd(handler: CommandKitButtonBuilderOnEnd): this;
|
|
304
305
|
}
|
|
305
306
|
|
|
306
307
|
interface CommandKitConfig {
|
|
@@ -375,4 +376,4 @@ declare function createSignal<T = unknown>(value?: CommandKitSignalInitializer<T
|
|
|
375
376
|
*/
|
|
376
377
|
declare function createEffect(callback: CommandKitEffectCallback): void;
|
|
377
378
|
|
|
378
|
-
export { AutocompleteProps, ButtonKit, CommandData, CommandKit, CommandKitButtonBuilderInteractionCollectorDispatch, CommandKitButtonBuilderInteractionCollectorDispatchContextData, CommandKitConfig, CommandKitEffectCallback, CommandKitSignal, CommandKitSignalInitializer, CommandKitSignalUpdater, CommandObject, CommandOptions, CommandProps, ContextMenuCommandProps, MessageContextMenuCommandProps, ReloadType, SlashCommandProps, UserContextMenuCommandProps, ValidationProps, createEffect, createSignal, defineConfig, getConfig };
|
|
379
|
+
export { AutocompleteProps, ButtonKit, CommandData, CommandKit, CommandKitButtonBuilderInteractionCollectorDispatch, CommandKitButtonBuilderInteractionCollectorDispatchContextData, CommandKitButtonBuilderOnEnd, CommandKitConfig, CommandKitEffectCallback, CommandKitSignal, CommandKitSignalInitializer, CommandKitSignalUpdater, CommandObject, CommandOptions, CommandProps, ContextMenuCommandProps, MessageContextMenuCommandProps, ReloadType, SlashCommandProps, UserContextMenuCommandProps, ValidationProps, createEffect, createSignal, defineConfig, getConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -257,7 +257,8 @@ declare class CommandKit {
|
|
|
257
257
|
* The handler to run when a button is clicked. This handler is called with the interaction as the first argument.
|
|
258
258
|
* If the first argument is null, it means that the interaction collector has been destroyed.
|
|
259
259
|
*/
|
|
260
|
-
type CommandKitButtonBuilderInteractionCollectorDispatch = (interaction: ButtonInteraction
|
|
260
|
+
type CommandKitButtonBuilderInteractionCollectorDispatch = (interaction: ButtonInteraction) => Awaitable<void>;
|
|
261
|
+
type CommandKitButtonBuilderOnEnd = () => Awaitable<void>;
|
|
261
262
|
type CommandKitButtonBuilderInteractionCollectorDispatchContextData = {
|
|
262
263
|
/**
|
|
263
264
|
* The message to listen for button interactions on.
|
|
@@ -299,8 +300,8 @@ declare class ButtonKit extends ButtonBuilder {
|
|
|
299
300
|
* button.onClick(null);
|
|
300
301
|
* ```
|
|
301
302
|
*/
|
|
302
|
-
onClick(handler:
|
|
303
|
-
|
|
303
|
+
onClick(handler: CommandKitButtonBuilderInteractionCollectorDispatch, data?: CommandKitButtonBuilderInteractionCollectorDispatchContextData): this;
|
|
304
|
+
onEnd(handler: CommandKitButtonBuilderOnEnd): this;
|
|
304
305
|
}
|
|
305
306
|
|
|
306
307
|
interface CommandKitConfig {
|
|
@@ -375,4 +376,4 @@ declare function createSignal<T = unknown>(value?: CommandKitSignalInitializer<T
|
|
|
375
376
|
*/
|
|
376
377
|
declare function createEffect(callback: CommandKitEffectCallback): void;
|
|
377
378
|
|
|
378
|
-
export { AutocompleteProps, ButtonKit, CommandData, CommandKit, CommandKitButtonBuilderInteractionCollectorDispatch, CommandKitButtonBuilderInteractionCollectorDispatchContextData, CommandKitConfig, CommandKitEffectCallback, CommandKitSignal, CommandKitSignalInitializer, CommandKitSignalUpdater, CommandObject, CommandOptions, CommandProps, ContextMenuCommandProps, MessageContextMenuCommandProps, ReloadType, SlashCommandProps, UserContextMenuCommandProps, ValidationProps, createEffect, createSignal, defineConfig, getConfig };
|
|
379
|
+
export { AutocompleteProps, ButtonKit, CommandData, CommandKit, CommandKitButtonBuilderInteractionCollectorDispatch, CommandKitButtonBuilderInteractionCollectorDispatchContextData, CommandKitButtonBuilderOnEnd, CommandKitConfig, CommandKitEffectCallback, CommandKitSignal, CommandKitSignalInitializer, CommandKitSignalUpdater, CommandObject, CommandOptions, CommandProps, ContextMenuCommandProps, MessageContextMenuCommandProps, ReloadType, SlashCommandProps, UserContextMenuCommandProps, ValidationProps, createEffect, createSignal, defineConfig, getConfig };
|
package/dist/index.js
CHANGED
|
@@ -569,13 +569,6 @@ var CommandHandler = class {
|
|
|
569
569
|
} else {
|
|
570
570
|
commandObj.category = commandCategory;
|
|
571
571
|
}
|
|
572
|
-
if (commandObj.options?.guildOnly) {
|
|
573
|
-
console.log(
|
|
574
|
-
colors_default.yellow(
|
|
575
|
-
`\u2139\uFE0F Deprecation warning: The command "${commandObj.data.name}" uses "options.guildOnly", which will be deprecated soon. Use "data.dm_permission" instead.`
|
|
576
|
-
)
|
|
577
|
-
);
|
|
578
|
-
}
|
|
579
572
|
this.#data.commands.push(commandObj);
|
|
580
573
|
}
|
|
581
574
|
}
|
|
@@ -943,19 +936,55 @@ var CommandKit = class {
|
|
|
943
936
|
var import_discord2 = require("discord.js");
|
|
944
937
|
var ButtonKit = class extends import_discord2.ButtonBuilder {
|
|
945
938
|
#onClickHandler = null;
|
|
939
|
+
#onEndHandler = null;
|
|
946
940
|
#contextData = null;
|
|
947
941
|
#collector = null;
|
|
942
|
+
/**
|
|
943
|
+
* Sets up an inline interaction collector for this button. This collector by default allows as many interactions as possible if it is actively used.
|
|
944
|
+
* If unused, this expires after 24 hours or custom time if specified.
|
|
945
|
+
* @param handler The handler to run when the button is clicked
|
|
946
|
+
* @param data The context data to use for the interaction collector
|
|
947
|
+
* @returns This button
|
|
948
|
+
* @example
|
|
949
|
+
* ```ts
|
|
950
|
+
* const button = new ButtonKit()
|
|
951
|
+
* .setLabel('Click me')
|
|
952
|
+
* .setStyle(ButtonStyle.Primary)
|
|
953
|
+
* .setCustomId('click_me');
|
|
954
|
+
*
|
|
955
|
+
* const row = new ActionRowBuilder().addComponents(button);
|
|
956
|
+
*
|
|
957
|
+
* const message = await channel.send({ content: 'Click the button', components: [row] });
|
|
958
|
+
*
|
|
959
|
+
* button.onClick(async (interaction) => {
|
|
960
|
+
* await interaction.reply('You clicked me!');
|
|
961
|
+
* }, { message });
|
|
962
|
+
*
|
|
963
|
+
* // Remove onClick handler and destroy the interaction collector
|
|
964
|
+
* button.onClick(null);
|
|
965
|
+
* ```
|
|
966
|
+
*/
|
|
948
967
|
onClick(handler, data) {
|
|
949
968
|
if (this.data.style === import_discord2.ButtonStyle.Link) {
|
|
950
969
|
throw new TypeError('Cannot setup "onClick" handler on link buttons.');
|
|
951
970
|
}
|
|
971
|
+
if (!handler) {
|
|
972
|
+
throw new TypeError('Cannot setup "onClick" without a handler function parameter.');
|
|
973
|
+
}
|
|
952
974
|
this.#destroyCollector();
|
|
953
975
|
this.#onClickHandler = handler;
|
|
954
|
-
if (
|
|
976
|
+
if (data)
|
|
955
977
|
this.#contextData = data;
|
|
956
978
|
this.#setupInteractionCollector();
|
|
957
979
|
return this;
|
|
958
980
|
}
|
|
981
|
+
onEnd(handler) {
|
|
982
|
+
if (!handler) {
|
|
983
|
+
throw new TypeError('Cannot setup "onEnd" without a handler function parameter.');
|
|
984
|
+
}
|
|
985
|
+
this.#onEndHandler = handler;
|
|
986
|
+
return this;
|
|
987
|
+
}
|
|
959
988
|
#setupInteractionCollector() {
|
|
960
989
|
if (!this.#contextData || !this.#onClickHandler)
|
|
961
990
|
return;
|
|
@@ -992,10 +1021,10 @@ var ButtonKit = class extends import_discord2.ButtonBuilder {
|
|
|
992
1021
|
});
|
|
993
1022
|
this.#collector.on("end", () => {
|
|
994
1023
|
this.#destroyCollector();
|
|
1024
|
+
this.#onEndHandler?.();
|
|
995
1025
|
});
|
|
996
1026
|
}
|
|
997
1027
|
#destroyCollector() {
|
|
998
|
-
this.#onClickHandler?.(null);
|
|
999
1028
|
this.#collector?.stop("end");
|
|
1000
1029
|
this.#collector?.removeAllListeners();
|
|
1001
1030
|
this.#collector = null;
|
package/dist/index.mjs
CHANGED
|
@@ -536,13 +536,6 @@ var CommandHandler = class {
|
|
|
536
536
|
} else {
|
|
537
537
|
commandObj.category = commandCategory;
|
|
538
538
|
}
|
|
539
|
-
if (commandObj.options?.guildOnly) {
|
|
540
|
-
console.log(
|
|
541
|
-
colors_default.yellow(
|
|
542
|
-
`\u2139\uFE0F Deprecation warning: The command "${commandObj.data.name}" uses "options.guildOnly", which will be deprecated soon. Use "data.dm_permission" instead.`
|
|
543
|
-
)
|
|
544
|
-
);
|
|
545
|
-
}
|
|
546
539
|
this.#data.commands.push(commandObj);
|
|
547
540
|
}
|
|
548
541
|
}
|
|
@@ -914,19 +907,55 @@ import {
|
|
|
914
907
|
} from "discord.js";
|
|
915
908
|
var ButtonKit = class extends ButtonBuilder {
|
|
916
909
|
#onClickHandler = null;
|
|
910
|
+
#onEndHandler = null;
|
|
917
911
|
#contextData = null;
|
|
918
912
|
#collector = null;
|
|
913
|
+
/**
|
|
914
|
+
* Sets up an inline interaction collector for this button. This collector by default allows as many interactions as possible if it is actively used.
|
|
915
|
+
* If unused, this expires after 24 hours or custom time if specified.
|
|
916
|
+
* @param handler The handler to run when the button is clicked
|
|
917
|
+
* @param data The context data to use for the interaction collector
|
|
918
|
+
* @returns This button
|
|
919
|
+
* @example
|
|
920
|
+
* ```ts
|
|
921
|
+
* const button = new ButtonKit()
|
|
922
|
+
* .setLabel('Click me')
|
|
923
|
+
* .setStyle(ButtonStyle.Primary)
|
|
924
|
+
* .setCustomId('click_me');
|
|
925
|
+
*
|
|
926
|
+
* const row = new ActionRowBuilder().addComponents(button);
|
|
927
|
+
*
|
|
928
|
+
* const message = await channel.send({ content: 'Click the button', components: [row] });
|
|
929
|
+
*
|
|
930
|
+
* button.onClick(async (interaction) => {
|
|
931
|
+
* await interaction.reply('You clicked me!');
|
|
932
|
+
* }, { message });
|
|
933
|
+
*
|
|
934
|
+
* // Remove onClick handler and destroy the interaction collector
|
|
935
|
+
* button.onClick(null);
|
|
936
|
+
* ```
|
|
937
|
+
*/
|
|
919
938
|
onClick(handler, data) {
|
|
920
939
|
if (this.data.style === ButtonStyle.Link) {
|
|
921
940
|
throw new TypeError('Cannot setup "onClick" handler on link buttons.');
|
|
922
941
|
}
|
|
942
|
+
if (!handler) {
|
|
943
|
+
throw new TypeError('Cannot setup "onClick" without a handler function parameter.');
|
|
944
|
+
}
|
|
923
945
|
this.#destroyCollector();
|
|
924
946
|
this.#onClickHandler = handler;
|
|
925
|
-
if (
|
|
947
|
+
if (data)
|
|
926
948
|
this.#contextData = data;
|
|
927
949
|
this.#setupInteractionCollector();
|
|
928
950
|
return this;
|
|
929
951
|
}
|
|
952
|
+
onEnd(handler) {
|
|
953
|
+
if (!handler) {
|
|
954
|
+
throw new TypeError('Cannot setup "onEnd" without a handler function parameter.');
|
|
955
|
+
}
|
|
956
|
+
this.#onEndHandler = handler;
|
|
957
|
+
return this;
|
|
958
|
+
}
|
|
930
959
|
#setupInteractionCollector() {
|
|
931
960
|
if (!this.#contextData || !this.#onClickHandler)
|
|
932
961
|
return;
|
|
@@ -963,10 +992,10 @@ var ButtonKit = class extends ButtonBuilder {
|
|
|
963
992
|
});
|
|
964
993
|
this.#collector.on("end", () => {
|
|
965
994
|
this.#destroyCollector();
|
|
995
|
+
this.#onEndHandler?.();
|
|
966
996
|
});
|
|
967
997
|
}
|
|
968
998
|
#destroyCollector() {
|
|
969
|
-
this.#onClickHandler?.(null);
|
|
970
999
|
this.#collector?.stop("end");
|
|
971
1000
|
this.#collector?.removeAllListeners();
|
|
972
1001
|
this.#collector = null;
|
package/package.json
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
"files": [
|
|
18
|
-
"dist",
|
|
19
|
-
"bin"
|
|
20
|
-
],
|
|
21
|
-
"scripts": {
|
|
22
|
-
"lint": "tsc",
|
|
23
|
-
"dev": "tsup --watch",
|
|
24
|
-
"build": "tsup",
|
|
25
|
-
"deploy": "npm publish",
|
|
26
|
-
"deploy-dev": "npm publish --access public --tag dev",
|
|
27
|
-
"test": "cd ./tests && node ../bin/index.mjs dev",
|
|
28
|
-
"test:build": "cd ./tests && node ../bin/index.mjs build",
|
|
29
|
-
"test:prod": "cd ./tests && node ../bin/index.mjs start"
|
|
30
|
-
},
|
|
31
|
-
"repository": {
|
|
32
|
-
"url": "git+https://github.com/underctrl-io/commandkit.git"
|
|
33
|
-
},
|
|
34
|
-
"homepage": "https://commandkit.js.org",
|
|
35
|
-
"keywords": [
|
|
36
|
-
"discord.js",
|
|
37
|
-
"command handler",
|
|
38
|
-
"event handler"
|
|
39
|
-
],
|
|
40
|
-
"dependencies": {
|
|
41
|
-
"commander": "^11.1.0",
|
|
42
|
-
"dotenv": "^16.3.1",
|
|
43
|
-
"ora": "^7.0.1",
|
|
44
|
-
"rfdc": "^1.3.0",
|
|
45
|
-
"rimraf": "^5.0.5",
|
|
46
|
-
"tsup": "^7.2.0"
|
|
47
|
-
},
|
|
48
|
-
"devDependencies": {
|
|
49
|
-
"@types/node": "^20.5.9",
|
|
50
|
-
"discord.js": "^14.13.0",
|
|
51
|
-
"tsconfig": "workspace:*",
|
|
52
|
-
"tsx": "^3.12.8",
|
|
53
|
-
"typescript": "^5.1.6"
|
|
54
|
-
},
|
|
55
|
-
"peerDependencies": {
|
|
56
|
-
"discord.js": "^14"
|
|
2
|
+
"name": "commandkit",
|
|
3
|
+
"description": "Beginner friendly command & event handler for Discord.js",
|
|
4
|
+
"version": "0.1.10-dev.20231229085439",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"bin": "./bin/index.mjs",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"require": "./dist/index.js",
|
|
13
|
+
"import": "./dist/index.mjs",
|
|
14
|
+
"types": "./dist/index.d.ts"
|
|
57
15
|
}
|
|
58
|
-
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"bin"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"lint": "tsc",
|
|
23
|
+
"dev": "tsup --watch",
|
|
24
|
+
"build": "tsup",
|
|
25
|
+
"deploy": "npm publish",
|
|
26
|
+
"deploy-dev": "npm publish --access public --tag dev",
|
|
27
|
+
"test": "cd ./tests && node ../bin/index.mjs dev",
|
|
28
|
+
"test:build": "cd ./tests && node ../bin/index.mjs build",
|
|
29
|
+
"test:prod": "cd ./tests && node ../bin/index.mjs start"
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"url": "git+https://github.com/underctrl-io/commandkit.git"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://commandkit.js.org",
|
|
35
|
+
"keywords": [
|
|
36
|
+
"discord.js",
|
|
37
|
+
"command handler",
|
|
38
|
+
"event handler"
|
|
39
|
+
],
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"commander": "^11.1.0",
|
|
42
|
+
"dotenv": "^16.3.1",
|
|
43
|
+
"ora": "^7.0.1",
|
|
44
|
+
"rfdc": "^1.3.0",
|
|
45
|
+
"rimraf": "^5.0.5",
|
|
46
|
+
"tsup": "^7.2.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/node": "^20.5.9",
|
|
50
|
+
"discord.js": "^14.13.0",
|
|
51
|
+
"tsconfig": "workspace:*",
|
|
52
|
+
"tsx": "^3.12.8",
|
|
53
|
+
"typescript": "^5.1.6"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"discord.js": "^14"
|
|
57
|
+
}
|
|
58
|
+
}
|