commandkit 0.1.6-dev.20231005105852 → 0.1.6-dev.20231026074421

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.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { CommandInteraction, Client, ChatInputCommandInteraction, ContextMenuCommandInteraction, PermissionResolvable, APIApplicationCommandOption } from 'discord.js';
1
+ import { CommandInteraction, Client, ChatInputCommandInteraction, ContextMenuCommandInteraction, PermissionResolvable, APIApplicationCommandOption, ButtonInteraction, Awaitable, Message, InteractionCollectorOptions, ButtonBuilder } from 'discord.js';
2
2
 
3
3
  interface CommandProps {
4
4
  interaction: CommandInteraction;
@@ -34,7 +34,7 @@ declare enum CommandType {
34
34
  'Message' = 3,
35
35
  'User' = 2
36
36
  }
37
- type LocaleString = 'id' | 'en-US' | 'en-GB' | 'bg' | 'zh-CN' | 'zh-TW' | 'hr' | 'cs' | 'da' | 'nl' | 'fi' | 'fr' | 'de' | 'el' | 'hi' | 'hu' | 'it' | 'ja' | 'ko' | 'lt' | 'no' | 'pl' | 'pt-BR' | 'ro' | 'ru' | 'es-ES' | 'sv-SE' | 'th' | 'tr' | 'uk' | 'vi';
37
+ type LocaleString = 'id' | `en-${'GB' | 'US'}` | 'bg' | `zh-${'CN' | 'TW'}` | 'hr' | 'cs' | 'da' | 'nl' | 'fi' | 'fr' | 'de' | 'el' | 'hi' | 'hu' | 'it' | 'ja' | 'ko' | 'lt' | 'no' | 'pl' | 'pt-BR' | 'ro' | 'ru' | 'es-ES' | 'sv-SE' | 'th' | 'tr' | 'uk' | 'vi';
38
38
  type BaseCommandData = {
39
39
  name: string;
40
40
  type?: CommandType;
@@ -61,8 +61,8 @@ type CommandObject = {
61
61
  [key: string]: any;
62
62
  };
63
63
  declare enum ReloadType {
64
- 'Developer' = "dev",
65
- 'Global' = "global"
64
+ Developer = "dev",
65
+ Global = "global"
66
66
  }
67
67
 
68
68
  interface CommandKitOptions {
@@ -150,4 +150,55 @@ declare class CommandKit {
150
150
  get devRoleIds(): string[];
151
151
  }
152
152
 
153
- export { CommandData, CommandKit, CommandObject, CommandOptions, CommandProps, CommandType, ContextMenuCommandProps, ReloadType, SlashCommandProps, ValidationFunctionProps };
153
+ type CommandKitButtonBuilderInteractionCollectorDispatch = (interaction: ButtonInteraction) => Awaitable<void>;
154
+ type CommandKitButtonBuilderInteractionCollectorDispatchContextData = {
155
+ /**
156
+ * The message to listen for button interactions on.
157
+ */
158
+ message: Message;
159
+ /**
160
+ * If the collector should automatically reset the timer when a button is clicked.
161
+ */
162
+ autoReset?: boolean;
163
+ } & Omit<InteractionCollectorOptions<ButtonInteraction>, 'filter' | 'componentType'>;
164
+ declare class ButtonKit extends ButtonBuilder {
165
+ #private;
166
+ /**
167
+ * Sets up an inline interaction collector for this button. This collector by default allows as many interactions as possible if it is actively used.
168
+ * If unused, this expires after 24 hours or custom time if specified.
169
+ * @param handler The handler to run when the button is clicked
170
+ * @param data The context data to use for the interaction collector
171
+ * @returns This button
172
+ * @example
173
+ * ```ts
174
+ * const button = new ButtonKit()
175
+ * .setLabel('Click me')
176
+ * .setStyle(ButtonStyle.Primary)
177
+ * .setCustomId('click_me');
178
+ *
179
+ * const message = await channel.send({ content: 'Click the button', components: [new MessageActionRow().addComponents(button)] });
180
+ *
181
+ * button.onClick(async (interaction) => {
182
+ * await interaction.reply('You clicked me!');
183
+ * }, { message });
184
+ *
185
+ * // remove onClick handler and destroy the interaction collector
186
+ * button.onClick(null);
187
+ * ```
188
+ */
189
+ onClick(handler: null): this;
190
+ onClick(handler: CommandKitButtonBuilderInteractionCollectorDispatch, data: CommandKitButtonBuilderInteractionCollectorDispatchContextData): this;
191
+ }
192
+
193
+ type CommandKitEffectCallback = () => void;
194
+ type CommandKitSignalInitializer<T> = T | (() => T);
195
+ type CommandKitSignalUpdater<T> = T | ((prev: T) => T);
196
+ type CommandKitSignal<T> = readonly [
197
+ () => T,
198
+ (value: CommandKitSignalUpdater<T>) => void,
199
+ () => void
200
+ ];
201
+ declare function createSignal<T = unknown>(value?: CommandKitSignalInitializer<T>): CommandKitSignal<T>;
202
+ declare function createEffect(callback: CommandKitEffectCallback): void;
203
+
204
+ export { ButtonKit, CommandData, CommandKit, CommandKitButtonBuilderInteractionCollectorDispatch, CommandKitButtonBuilderInteractionCollectorDispatchContextData, CommandKitEffectCallback, CommandKitSignal, CommandKitSignalInitializer, CommandKitSignalUpdater, CommandObject, CommandOptions, CommandProps, CommandType, ContextMenuCommandProps, ReloadType, SlashCommandProps, ValidationFunctionProps, createEffect, createSignal };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CommandInteraction, Client, ChatInputCommandInteraction, ContextMenuCommandInteraction, PermissionResolvable, APIApplicationCommandOption } from 'discord.js';
1
+ import { CommandInteraction, Client, ChatInputCommandInteraction, ContextMenuCommandInteraction, PermissionResolvable, APIApplicationCommandOption, ButtonInteraction, Awaitable, Message, InteractionCollectorOptions, ButtonBuilder } from 'discord.js';
2
2
 
3
3
  interface CommandProps {
4
4
  interaction: CommandInteraction;
@@ -34,7 +34,7 @@ declare enum CommandType {
34
34
  'Message' = 3,
35
35
  'User' = 2
36
36
  }
37
- type LocaleString = 'id' | 'en-US' | 'en-GB' | 'bg' | 'zh-CN' | 'zh-TW' | 'hr' | 'cs' | 'da' | 'nl' | 'fi' | 'fr' | 'de' | 'el' | 'hi' | 'hu' | 'it' | 'ja' | 'ko' | 'lt' | 'no' | 'pl' | 'pt-BR' | 'ro' | 'ru' | 'es-ES' | 'sv-SE' | 'th' | 'tr' | 'uk' | 'vi';
37
+ type LocaleString = 'id' | `en-${'GB' | 'US'}` | 'bg' | `zh-${'CN' | 'TW'}` | 'hr' | 'cs' | 'da' | 'nl' | 'fi' | 'fr' | 'de' | 'el' | 'hi' | 'hu' | 'it' | 'ja' | 'ko' | 'lt' | 'no' | 'pl' | 'pt-BR' | 'ro' | 'ru' | 'es-ES' | 'sv-SE' | 'th' | 'tr' | 'uk' | 'vi';
38
38
  type BaseCommandData = {
39
39
  name: string;
40
40
  type?: CommandType;
@@ -61,8 +61,8 @@ type CommandObject = {
61
61
  [key: string]: any;
62
62
  };
63
63
  declare enum ReloadType {
64
- 'Developer' = "dev",
65
- 'Global' = "global"
64
+ Developer = "dev",
65
+ Global = "global"
66
66
  }
67
67
 
68
68
  interface CommandKitOptions {
@@ -150,4 +150,55 @@ declare class CommandKit {
150
150
  get devRoleIds(): string[];
151
151
  }
152
152
 
153
- export { CommandData, CommandKit, CommandObject, CommandOptions, CommandProps, CommandType, ContextMenuCommandProps, ReloadType, SlashCommandProps, ValidationFunctionProps };
153
+ type CommandKitButtonBuilderInteractionCollectorDispatch = (interaction: ButtonInteraction) => Awaitable<void>;
154
+ type CommandKitButtonBuilderInteractionCollectorDispatchContextData = {
155
+ /**
156
+ * The message to listen for button interactions on.
157
+ */
158
+ message: Message;
159
+ /**
160
+ * If the collector should automatically reset the timer when a button is clicked.
161
+ */
162
+ autoReset?: boolean;
163
+ } & Omit<InteractionCollectorOptions<ButtonInteraction>, 'filter' | 'componentType'>;
164
+ declare class ButtonKit extends ButtonBuilder {
165
+ #private;
166
+ /**
167
+ * Sets up an inline interaction collector for this button. This collector by default allows as many interactions as possible if it is actively used.
168
+ * If unused, this expires after 24 hours or custom time if specified.
169
+ * @param handler The handler to run when the button is clicked
170
+ * @param data The context data to use for the interaction collector
171
+ * @returns This button
172
+ * @example
173
+ * ```ts
174
+ * const button = new ButtonKit()
175
+ * .setLabel('Click me')
176
+ * .setStyle(ButtonStyle.Primary)
177
+ * .setCustomId('click_me');
178
+ *
179
+ * const message = await channel.send({ content: 'Click the button', components: [new MessageActionRow().addComponents(button)] });
180
+ *
181
+ * button.onClick(async (interaction) => {
182
+ * await interaction.reply('You clicked me!');
183
+ * }, { message });
184
+ *
185
+ * // remove onClick handler and destroy the interaction collector
186
+ * button.onClick(null);
187
+ * ```
188
+ */
189
+ onClick(handler: null): this;
190
+ onClick(handler: CommandKitButtonBuilderInteractionCollectorDispatch, data: CommandKitButtonBuilderInteractionCollectorDispatchContextData): this;
191
+ }
192
+
193
+ type CommandKitEffectCallback = () => void;
194
+ type CommandKitSignalInitializer<T> = T | (() => T);
195
+ type CommandKitSignalUpdater<T> = T | ((prev: T) => T);
196
+ type CommandKitSignal<T> = readonly [
197
+ () => T,
198
+ (value: CommandKitSignalUpdater<T>) => void,
199
+ () => void
200
+ ];
201
+ declare function createSignal<T = unknown>(value?: CommandKitSignalInitializer<T>): CommandKitSignal<T>;
202
+ declare function createEffect(callback: CommandKitEffectCallback): void;
203
+
204
+ export { ButtonKit, CommandData, CommandKit, CommandKitButtonBuilderInteractionCollectorDispatch, CommandKitButtonBuilderInteractionCollectorDispatchContextData, CommandKitEffectCallback, CommandKitSignal, CommandKitSignalInitializer, CommandKitSignalUpdater, CommandObject, CommandOptions, CommandProps, CommandType, ContextMenuCommandProps, ReloadType, SlashCommandProps, ValidationFunctionProps, createEffect, createSignal };
package/dist/index.js CHANGED
@@ -30,42 +30,45 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
+ ButtonKit: () => ButtonKit,
33
34
  CommandKit: () => CommandKit,
34
35
  CommandType: () => CommandType,
35
- ReloadType: () => ReloadType
36
+ ReloadType: () => ReloadType,
37
+ createEffect: () => createEffect,
38
+ createSignal: () => createSignal
36
39
  });
37
40
  module.exports = __toCommonJS(src_exports);
38
41
 
39
42
  // src/utils/get-paths.ts
40
43
  var import_path = __toESM(require("path"));
41
- var import_fs = __toESM(require("fs"));
42
- function getFilePaths(directory, nesting) {
44
+ var import_promises = __toESM(require("fs/promises"));
45
+ async function getFilePaths(directory, nesting) {
43
46
  let filePaths = [];
44
47
  if (!directory)
45
48
  return filePaths;
46
- const files = import_fs.default.readdirSync(directory, { withFileTypes: true });
49
+ const files = await import_promises.default.readdir(directory, { withFileTypes: true });
47
50
  for (const file of files) {
48
51
  const filePath = import_path.default.join(directory, file.name);
49
52
  if (file.isFile()) {
50
53
  filePaths.push(filePath);
51
54
  }
52
55
  if (nesting && file.isDirectory()) {
53
- filePaths = [...filePaths, ...getFilePaths(filePath, true)];
56
+ filePaths = [...filePaths, ...await getFilePaths(filePath, true)];
54
57
  }
55
58
  }
56
59
  return filePaths;
57
60
  }
58
- function getFolderPaths(directory, nesting) {
61
+ async function getFolderPaths(directory, nesting) {
59
62
  let folderPaths = [];
60
63
  if (!directory)
61
64
  return folderPaths;
62
- const folders = import_fs.default.readdirSync(directory, { withFileTypes: true });
65
+ const folders = await import_promises.default.readdir(directory, { withFileTypes: true });
63
66
  for (const folder of folders) {
64
67
  const folderPath = import_path.default.join(directory, folder.name);
65
68
  if (folder.isDirectory()) {
66
69
  folderPaths.push(folderPath);
67
70
  if (nesting) {
68
- folderPaths = [...folderPaths, ...getFolderPaths(folderPath, true)];
71
+ folderPaths = [...folderPaths, ...await getFolderPaths(folderPath, true)];
69
72
  }
70
73
  }
71
74
  }
@@ -505,9 +508,8 @@ var CommandHandler = class {
505
508
  }
506
509
  async #buildCommands() {
507
510
  const allowedExtensions = /\.(js|mjs|cjs|ts)$/i;
508
- const commandFilePaths = getFilePaths(this.#data.commandsPath, true).filter(
509
- (path3) => allowedExtensions.test(path3)
510
- );
511
+ const paths = await getFilePaths(this.#data.commandsPath, true);
512
+ const commandFilePaths = paths.filter((path3) => allowedExtensions.test(path3));
511
513
  for (const commandFilePath of commandFilePaths) {
512
514
  const modulePath = toFileURL(commandFilePath);
513
515
  let importedObj = await import(`${modulePath}?t=${Date.now()}`);
@@ -669,13 +671,12 @@ var EventHandler = class {
669
671
  this.#registerEvents();
670
672
  }
671
673
  async #buildEvents() {
672
- const eventFolderPaths = getFolderPaths(this.#data.eventsPath);
674
+ const eventFolderPaths = await getFolderPaths(this.#data.eventsPath);
673
675
  for (const eventFolderPath of eventFolderPaths) {
674
676
  const eventName = eventFolderPath.replace(/\\\\|\\/g, "/").split("/").pop();
675
677
  const allowedExtensions = /\.(js|mjs|cjs|ts)$/i;
676
- const eventFilePaths = getFilePaths(eventFolderPath, true).filter(
677
- (path3) => allowedExtensions.test(path3)
678
- );
678
+ const eventPaths = await getFilePaths(eventFolderPath, true);
679
+ const eventFilePaths = eventPaths.filter((path3) => allowedExtensions.test(path3));
679
680
  const eventObj = {
680
681
  name: eventName,
681
682
  functions: []
@@ -746,9 +747,8 @@ var ValidationHandler = class {
746
747
  }
747
748
  async #buildValidations() {
748
749
  const allowedExtensions = /\.(js|mjs|cjs|ts)$/i;
749
- const validationFilePaths = getFilePaths(this.#data.validationsPath, true).filter(
750
- (path3) => allowedExtensions.test(path3)
751
- );
750
+ const validationPaths = await getFilePaths(this.#data.validationsPath, true);
751
+ const validationFilePaths = validationPaths.filter((path3) => allowedExtensions.test(path3));
752
752
  for (const validationFilePath of validationFilePaths) {
753
753
  const modulePath = toFileURL(validationFilePath);
754
754
  let importedFunction = (await import(`${modulePath}?t=${Date.now()}`)).default;
@@ -903,6 +903,113 @@ var CommandKit = class {
903
903
  }
904
904
  };
905
905
 
906
+ // src/components/Button.ts
907
+ var import_discord = require("discord.js");
908
+ var ButtonKit = class extends import_discord.ButtonBuilder {
909
+ #onClickHandler = null;
910
+ #contextData = null;
911
+ #collector = null;
912
+ onClick(handler, data) {
913
+ if (this.data.style === import_discord.ButtonStyle.Link) {
914
+ throw new TypeError('Cannot setup "onClick" handler for link buttons');
915
+ }
916
+ this.#destroyCollector();
917
+ this.#onClickHandler = handler;
918
+ if (handler && data)
919
+ this.#contextData = data;
920
+ this.#setupInteractionCollector();
921
+ return this;
922
+ }
923
+ #setupInteractionCollector() {
924
+ if (!this.#contextData || !this.#onClickHandler)
925
+ return;
926
+ const message = this.#contextData?.message;
927
+ if (!message) {
928
+ throw new TypeError(
929
+ 'Cannot setup "onClick" handler without a message in the context data'
930
+ );
931
+ }
932
+ if ("customId" in this.data && !this.data.customId) {
933
+ throw new TypeError('Cannot setup "onClick" handler without a custom id');
934
+ }
935
+ const data = {
936
+ time: 864e5,
937
+ autoReset: true,
938
+ ...this.#contextData
939
+ };
940
+ const collector = this.#collector = message.createMessageComponentCollector({
941
+ filter: (interaction) => interaction.customId === this.data.custom_id && interaction.message.id === message.id,
942
+ componentType: import_discord.ComponentType.Button,
943
+ ...data
944
+ });
945
+ this.#collector.on("collect", (interaction) => {
946
+ const handler = this.#onClickHandler;
947
+ if (!handler)
948
+ return this.#destroyCollector();
949
+ if (!this.#collector) {
950
+ return collector.stop("destroyed");
951
+ }
952
+ if (data.autoReset) {
953
+ this.#collector?.resetTimer();
954
+ }
955
+ return handler(interaction);
956
+ });
957
+ this.#collector.on("end", () => {
958
+ this.#destroyCollector();
959
+ });
960
+ }
961
+ #destroyCollector() {
962
+ this.#collector?.stop("end");
963
+ this.#collector?.removeAllListeners();
964
+ this.#collector = null;
965
+ this.#contextData = null;
966
+ this.#onClickHandler = null;
967
+ }
968
+ };
969
+
970
+ // src/utils/signal.ts
971
+ var context = [];
972
+ function createSignal(value) {
973
+ const subscribers = /* @__PURE__ */ new Set();
974
+ let disposed = false;
975
+ let val = value instanceof Function ? value() : value;
976
+ const getter = () => {
977
+ if (!disposed) {
978
+ const running = getCurrentObserver();
979
+ if (running)
980
+ subscribers.add(running);
981
+ }
982
+ return val;
983
+ };
984
+ const setter = (newValue) => {
985
+ if (disposed)
986
+ return;
987
+ val = newValue instanceof Function ? newValue(val) : newValue;
988
+ for (const subscriber of subscribers) {
989
+ subscriber();
990
+ }
991
+ };
992
+ const dispose = () => {
993
+ subscribers.clear();
994
+ disposed = true;
995
+ };
996
+ return [getter, setter, dispose];
997
+ }
998
+ function createEffect(callback) {
999
+ const execute = () => {
1000
+ context.push(execute);
1001
+ try {
1002
+ callback();
1003
+ } finally {
1004
+ context.pop();
1005
+ }
1006
+ };
1007
+ execute();
1008
+ }
1009
+ function getCurrentObserver() {
1010
+ return context[context.length - 1];
1011
+ }
1012
+
906
1013
  // src/types/index.ts
907
1014
  var CommandType = /* @__PURE__ */ ((CommandType2) => {
908
1015
  CommandType2[CommandType2["ChatInput"] = 1] = "ChatInput";
@@ -917,7 +1024,10 @@ var ReloadType = /* @__PURE__ */ ((ReloadType2) => {
917
1024
  })(ReloadType || {});
918
1025
  // Annotate the CommonJS export names for ESM import in node:
919
1026
  0 && (module.exports = {
1027
+ ButtonKit,
920
1028
  CommandKit,
921
1029
  CommandType,
922
- ReloadType
1030
+ ReloadType,
1031
+ createEffect,
1032
+ createSignal
923
1033
  });
package/dist/index.mjs CHANGED
@@ -8,34 +8,34 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
8
8
 
9
9
  // src/utils/get-paths.ts
10
10
  import path from "path";
11
- import fs from "fs";
12
- function getFilePaths(directory, nesting) {
11
+ import fs from "fs/promises";
12
+ async function getFilePaths(directory, nesting) {
13
13
  let filePaths = [];
14
14
  if (!directory)
15
15
  return filePaths;
16
- const files = fs.readdirSync(directory, { withFileTypes: true });
16
+ const files = await fs.readdir(directory, { withFileTypes: true });
17
17
  for (const file of files) {
18
18
  const filePath = path.join(directory, file.name);
19
19
  if (file.isFile()) {
20
20
  filePaths.push(filePath);
21
21
  }
22
22
  if (nesting && file.isDirectory()) {
23
- filePaths = [...filePaths, ...getFilePaths(filePath, true)];
23
+ filePaths = [...filePaths, ...await getFilePaths(filePath, true)];
24
24
  }
25
25
  }
26
26
  return filePaths;
27
27
  }
28
- function getFolderPaths(directory, nesting) {
28
+ async function getFolderPaths(directory, nesting) {
29
29
  let folderPaths = [];
30
30
  if (!directory)
31
31
  return folderPaths;
32
- const folders = fs.readdirSync(directory, { withFileTypes: true });
32
+ const folders = await fs.readdir(directory, { withFileTypes: true });
33
33
  for (const folder of folders) {
34
34
  const folderPath = path.join(directory, folder.name);
35
35
  if (folder.isDirectory()) {
36
36
  folderPaths.push(folderPath);
37
37
  if (nesting) {
38
- folderPaths = [...folderPaths, ...getFolderPaths(folderPath, true)];
38
+ folderPaths = [...folderPaths, ...await getFolderPaths(folderPath, true)];
39
39
  }
40
40
  }
41
41
  }
@@ -475,9 +475,8 @@ var CommandHandler = class {
475
475
  }
476
476
  async #buildCommands() {
477
477
  const allowedExtensions = /\.(js|mjs|cjs|ts)$/i;
478
- const commandFilePaths = getFilePaths(this.#data.commandsPath, true).filter(
479
- (path3) => allowedExtensions.test(path3)
480
- );
478
+ const paths = await getFilePaths(this.#data.commandsPath, true);
479
+ const commandFilePaths = paths.filter((path3) => allowedExtensions.test(path3));
481
480
  for (const commandFilePath of commandFilePaths) {
482
481
  const modulePath = toFileURL(commandFilePath);
483
482
  let importedObj = await import(`${modulePath}?t=${Date.now()}`);
@@ -639,13 +638,12 @@ var EventHandler = class {
639
638
  this.#registerEvents();
640
639
  }
641
640
  async #buildEvents() {
642
- const eventFolderPaths = getFolderPaths(this.#data.eventsPath);
641
+ const eventFolderPaths = await getFolderPaths(this.#data.eventsPath);
643
642
  for (const eventFolderPath of eventFolderPaths) {
644
643
  const eventName = eventFolderPath.replace(/\\\\|\\/g, "/").split("/").pop();
645
644
  const allowedExtensions = /\.(js|mjs|cjs|ts)$/i;
646
- const eventFilePaths = getFilePaths(eventFolderPath, true).filter(
647
- (path3) => allowedExtensions.test(path3)
648
- );
645
+ const eventPaths = await getFilePaths(eventFolderPath, true);
646
+ const eventFilePaths = eventPaths.filter((path3) => allowedExtensions.test(path3));
649
647
  const eventObj = {
650
648
  name: eventName,
651
649
  functions: []
@@ -716,9 +714,8 @@ var ValidationHandler = class {
716
714
  }
717
715
  async #buildValidations() {
718
716
  const allowedExtensions = /\.(js|mjs|cjs|ts)$/i;
719
- const validationFilePaths = getFilePaths(this.#data.validationsPath, true).filter(
720
- (path3) => allowedExtensions.test(path3)
721
- );
717
+ const validationPaths = await getFilePaths(this.#data.validationsPath, true);
718
+ const validationFilePaths = validationPaths.filter((path3) => allowedExtensions.test(path3));
722
719
  for (const validationFilePath of validationFilePaths) {
723
720
  const modulePath = toFileURL(validationFilePath);
724
721
  let importedFunction = (await import(`${modulePath}?t=${Date.now()}`)).default;
@@ -873,6 +870,113 @@ var CommandKit = class {
873
870
  }
874
871
  };
875
872
 
873
+ // src/components/Button.ts
874
+ import { ButtonBuilder, ButtonStyle, ComponentType } from "discord.js";
875
+ var ButtonKit = class extends ButtonBuilder {
876
+ #onClickHandler = null;
877
+ #contextData = null;
878
+ #collector = null;
879
+ onClick(handler, data) {
880
+ if (this.data.style === ButtonStyle.Link) {
881
+ throw new TypeError('Cannot setup "onClick" handler for link buttons');
882
+ }
883
+ this.#destroyCollector();
884
+ this.#onClickHandler = handler;
885
+ if (handler && data)
886
+ this.#contextData = data;
887
+ this.#setupInteractionCollector();
888
+ return this;
889
+ }
890
+ #setupInteractionCollector() {
891
+ if (!this.#contextData || !this.#onClickHandler)
892
+ return;
893
+ const message = this.#contextData?.message;
894
+ if (!message) {
895
+ throw new TypeError(
896
+ 'Cannot setup "onClick" handler without a message in the context data'
897
+ );
898
+ }
899
+ if ("customId" in this.data && !this.data.customId) {
900
+ throw new TypeError('Cannot setup "onClick" handler without a custom id');
901
+ }
902
+ const data = {
903
+ time: 864e5,
904
+ autoReset: true,
905
+ ...this.#contextData
906
+ };
907
+ const collector = this.#collector = message.createMessageComponentCollector({
908
+ filter: (interaction) => interaction.customId === this.data.custom_id && interaction.message.id === message.id,
909
+ componentType: ComponentType.Button,
910
+ ...data
911
+ });
912
+ this.#collector.on("collect", (interaction) => {
913
+ const handler = this.#onClickHandler;
914
+ if (!handler)
915
+ return this.#destroyCollector();
916
+ if (!this.#collector) {
917
+ return collector.stop("destroyed");
918
+ }
919
+ if (data.autoReset) {
920
+ this.#collector?.resetTimer();
921
+ }
922
+ return handler(interaction);
923
+ });
924
+ this.#collector.on("end", () => {
925
+ this.#destroyCollector();
926
+ });
927
+ }
928
+ #destroyCollector() {
929
+ this.#collector?.stop("end");
930
+ this.#collector?.removeAllListeners();
931
+ this.#collector = null;
932
+ this.#contextData = null;
933
+ this.#onClickHandler = null;
934
+ }
935
+ };
936
+
937
+ // src/utils/signal.ts
938
+ var context = [];
939
+ function createSignal(value) {
940
+ const subscribers = /* @__PURE__ */ new Set();
941
+ let disposed = false;
942
+ let val = value instanceof Function ? value() : value;
943
+ const getter = () => {
944
+ if (!disposed) {
945
+ const running = getCurrentObserver();
946
+ if (running)
947
+ subscribers.add(running);
948
+ }
949
+ return val;
950
+ };
951
+ const setter = (newValue) => {
952
+ if (disposed)
953
+ return;
954
+ val = newValue instanceof Function ? newValue(val) : newValue;
955
+ for (const subscriber of subscribers) {
956
+ subscriber();
957
+ }
958
+ };
959
+ const dispose = () => {
960
+ subscribers.clear();
961
+ disposed = true;
962
+ };
963
+ return [getter, setter, dispose];
964
+ }
965
+ function createEffect(callback) {
966
+ const execute = () => {
967
+ context.push(execute);
968
+ try {
969
+ callback();
970
+ } finally {
971
+ context.pop();
972
+ }
973
+ };
974
+ execute();
975
+ }
976
+ function getCurrentObserver() {
977
+ return context[context.length - 1];
978
+ }
979
+
876
980
  // src/types/index.ts
877
981
  var CommandType = /* @__PURE__ */ ((CommandType2) => {
878
982
  CommandType2[CommandType2["ChatInput"] = 1] = "ChatInput";
@@ -886,7 +990,10 @@ var ReloadType = /* @__PURE__ */ ((ReloadType2) => {
886
990
  return ReloadType2;
887
991
  })(ReloadType || {});
888
992
  export {
993
+ ButtonKit,
889
994
  CommandKit,
890
995
  CommandType,
891
- ReloadType
996
+ ReloadType,
997
+ createEffect,
998
+ createSignal
892
999
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "commandkit",
3
3
  "description": "Beginner friendly command & event handler for Discord.js",
4
- "version": "0.1.6-dev.20231005105852",
4
+ "version": "0.1.6-dev.20231026074421",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",