commandkit 0.1.9 โ 0.1.10
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 -2
- package/dist/index.mjs +38 -2
- package/package.json +1 -1
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
|
@@ -943,19 +943,55 @@ var CommandKit = class {
|
|
|
943
943
|
var import_discord2 = require("discord.js");
|
|
944
944
|
var ButtonKit = class extends import_discord2.ButtonBuilder {
|
|
945
945
|
#onClickHandler = null;
|
|
946
|
+
#onEndHandler = null;
|
|
946
947
|
#contextData = null;
|
|
947
948
|
#collector = null;
|
|
949
|
+
/**
|
|
950
|
+
* Sets up an inline interaction collector for this button. This collector by default allows as many interactions as possible if it is actively used.
|
|
951
|
+
* If unused, this expires after 24 hours or custom time if specified.
|
|
952
|
+
* @param handler The handler to run when the button is clicked
|
|
953
|
+
* @param data The context data to use for the interaction collector
|
|
954
|
+
* @returns This button
|
|
955
|
+
* @example
|
|
956
|
+
* ```ts
|
|
957
|
+
* const button = new ButtonKit()
|
|
958
|
+
* .setLabel('Click me')
|
|
959
|
+
* .setStyle(ButtonStyle.Primary)
|
|
960
|
+
* .setCustomId('click_me');
|
|
961
|
+
*
|
|
962
|
+
* const row = new ActionRowBuilder().addComponents(button);
|
|
963
|
+
*
|
|
964
|
+
* const message = await channel.send({ content: 'Click the button', components: [row] });
|
|
965
|
+
*
|
|
966
|
+
* button.onClick(async (interaction) => {
|
|
967
|
+
* await interaction.reply('You clicked me!');
|
|
968
|
+
* }, { message });
|
|
969
|
+
*
|
|
970
|
+
* // Remove onClick handler and destroy the interaction collector
|
|
971
|
+
* button.onClick(null);
|
|
972
|
+
* ```
|
|
973
|
+
*/
|
|
948
974
|
onClick(handler, data) {
|
|
949
975
|
if (this.data.style === import_discord2.ButtonStyle.Link) {
|
|
950
976
|
throw new TypeError('Cannot setup "onClick" handler on link buttons.');
|
|
951
977
|
}
|
|
978
|
+
if (!handler) {
|
|
979
|
+
throw new TypeError('Cannot setup "onClick" without a handler function parameter.');
|
|
980
|
+
}
|
|
952
981
|
this.#destroyCollector();
|
|
953
982
|
this.#onClickHandler = handler;
|
|
954
|
-
if (
|
|
983
|
+
if (data)
|
|
955
984
|
this.#contextData = data;
|
|
956
985
|
this.#setupInteractionCollector();
|
|
957
986
|
return this;
|
|
958
987
|
}
|
|
988
|
+
onEnd(handler) {
|
|
989
|
+
if (!handler) {
|
|
990
|
+
throw new TypeError('Cannot setup "onEnd" without a handler function parameter.');
|
|
991
|
+
}
|
|
992
|
+
this.#onEndHandler = handler;
|
|
993
|
+
return this;
|
|
994
|
+
}
|
|
959
995
|
#setupInteractionCollector() {
|
|
960
996
|
if (!this.#contextData || !this.#onClickHandler)
|
|
961
997
|
return;
|
|
@@ -992,10 +1028,10 @@ var ButtonKit = class extends import_discord2.ButtonBuilder {
|
|
|
992
1028
|
});
|
|
993
1029
|
this.#collector.on("end", () => {
|
|
994
1030
|
this.#destroyCollector();
|
|
1031
|
+
this.#onEndHandler?.();
|
|
995
1032
|
});
|
|
996
1033
|
}
|
|
997
1034
|
#destroyCollector() {
|
|
998
|
-
this.#onClickHandler?.(null);
|
|
999
1035
|
this.#collector?.stop("end");
|
|
1000
1036
|
this.#collector?.removeAllListeners();
|
|
1001
1037
|
this.#collector = null;
|
package/dist/index.mjs
CHANGED
|
@@ -914,19 +914,55 @@ import {
|
|
|
914
914
|
} from "discord.js";
|
|
915
915
|
var ButtonKit = class extends ButtonBuilder {
|
|
916
916
|
#onClickHandler = null;
|
|
917
|
+
#onEndHandler = null;
|
|
917
918
|
#contextData = null;
|
|
918
919
|
#collector = null;
|
|
920
|
+
/**
|
|
921
|
+
* Sets up an inline interaction collector for this button. This collector by default allows as many interactions as possible if it is actively used.
|
|
922
|
+
* If unused, this expires after 24 hours or custom time if specified.
|
|
923
|
+
* @param handler The handler to run when the button is clicked
|
|
924
|
+
* @param data The context data to use for the interaction collector
|
|
925
|
+
* @returns This button
|
|
926
|
+
* @example
|
|
927
|
+
* ```ts
|
|
928
|
+
* const button = new ButtonKit()
|
|
929
|
+
* .setLabel('Click me')
|
|
930
|
+
* .setStyle(ButtonStyle.Primary)
|
|
931
|
+
* .setCustomId('click_me');
|
|
932
|
+
*
|
|
933
|
+
* const row = new ActionRowBuilder().addComponents(button);
|
|
934
|
+
*
|
|
935
|
+
* const message = await channel.send({ content: 'Click the button', components: [row] });
|
|
936
|
+
*
|
|
937
|
+
* button.onClick(async (interaction) => {
|
|
938
|
+
* await interaction.reply('You clicked me!');
|
|
939
|
+
* }, { message });
|
|
940
|
+
*
|
|
941
|
+
* // Remove onClick handler and destroy the interaction collector
|
|
942
|
+
* button.onClick(null);
|
|
943
|
+
* ```
|
|
944
|
+
*/
|
|
919
945
|
onClick(handler, data) {
|
|
920
946
|
if (this.data.style === ButtonStyle.Link) {
|
|
921
947
|
throw new TypeError('Cannot setup "onClick" handler on link buttons.');
|
|
922
948
|
}
|
|
949
|
+
if (!handler) {
|
|
950
|
+
throw new TypeError('Cannot setup "onClick" without a handler function parameter.');
|
|
951
|
+
}
|
|
923
952
|
this.#destroyCollector();
|
|
924
953
|
this.#onClickHandler = handler;
|
|
925
|
-
if (
|
|
954
|
+
if (data)
|
|
926
955
|
this.#contextData = data;
|
|
927
956
|
this.#setupInteractionCollector();
|
|
928
957
|
return this;
|
|
929
958
|
}
|
|
959
|
+
onEnd(handler) {
|
|
960
|
+
if (!handler) {
|
|
961
|
+
throw new TypeError('Cannot setup "onEnd" without a handler function parameter.');
|
|
962
|
+
}
|
|
963
|
+
this.#onEndHandler = handler;
|
|
964
|
+
return this;
|
|
965
|
+
}
|
|
930
966
|
#setupInteractionCollector() {
|
|
931
967
|
if (!this.#contextData || !this.#onClickHandler)
|
|
932
968
|
return;
|
|
@@ -963,10 +999,10 @@ var ButtonKit = class extends ButtonBuilder {
|
|
|
963
999
|
});
|
|
964
1000
|
this.#collector.on("end", () => {
|
|
965
1001
|
this.#destroyCollector();
|
|
1002
|
+
this.#onEndHandler?.();
|
|
966
1003
|
});
|
|
967
1004
|
}
|
|
968
1005
|
#destroyCollector() {
|
|
969
|
-
this.#onClickHandler?.(null);
|
|
970
1006
|
this.#collector?.stop("end");
|
|
971
1007
|
this.#collector?.removeAllListeners();
|
|
972
1008
|
this.#collector = null;
|