seyfert 2.1.1-dev-11415196258.0 → 2.1.1-dev-11420062278.0

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.
@@ -4,7 +4,7 @@ import type { TextInput } from './Modal';
4
4
  import type { BuilderSelectMenus } from './SelectMenu';
5
5
  export type ComponentCallback<T extends ComponentInteraction | StringSelectMenuInteraction = ComponentInteraction | StringSelectMenuInteraction> = (interaction: T, stop: ComponentStopCallback, refresh: ComponentRefreshCallback) => any;
6
6
  export type ComponentFilterCallback<T = ComponentInteraction> = (interaction: T) => any;
7
- export type ComponentStopCallback = (reason: 'messageDelete' | 'channelDelete' | 'guildDelete' | (string & {}) | undefined, refresh: ComponentRefreshCallback) => any;
7
+ export type ComponentStopCallback = (reason: 'messageDelete' | 'channelDelete' | 'guildDelete' | 'idle' | 'timeout' | (string & {}) | undefined, refresh: ComponentRefreshCallback) => any;
8
8
  export type ComponentRefreshCallback = () => any;
9
9
  export type ModalSubmitCallback<T = ModalSubmitInteraction> = (interaction: T) => any;
10
10
  export type ButtonLink = Omit<Button, 'setCustomId'>;
@@ -8,9 +8,10 @@ import { ComponentCommand } from './componentcommand';
8
8
  import type { ComponentContext } from './componentcontext';
9
9
  import { ModalCommand } from './modalcommand';
10
10
  import type { ModalContext } from './modalcontext';
11
+ type UserMatches = string | string[] | RegExp;
11
12
  type COMPONENTS = {
12
13
  components: {
13
- match: string | string[] | RegExp;
14
+ match: MatchCallback;
14
15
  callback: ComponentCallback;
15
16
  }[];
16
17
  options?: ListenerOptions;
@@ -19,12 +20,13 @@ type COMPONENTS = {
19
20
  guildId: string | undefined;
20
21
  idle?: NodeJS.Timeout;
21
22
  timeout?: NodeJS.Timeout;
22
- __run: (customId: string | string[] | RegExp, callback: ComponentCallback) => any;
23
+ __run: (customId: UserMatches, callback: ComponentCallback) => any;
23
24
  };
25
+ export type MatchCallback = (str: string) => boolean;
24
26
  export type CollectorInteraction = ComponentInteraction | StringSelectMenuInteraction;
25
27
  export type ComponentCommands = ComponentCommand | ModalCommand;
26
28
  export interface CreateComponentCollectorResult {
27
- run<T extends CollectorInteraction = CollectorInteraction>(customId: string | string[] | RegExp, callback: ComponentCallback<T>): any;
29
+ run<T extends CollectorInteraction = CollectorInteraction>(customId: UserMatches, callback: ComponentCallback<T>): any;
28
30
  stop(reason?: string): any;
29
31
  }
30
32
  export declare class ComponentHandler extends BaseHandler {
@@ -35,9 +37,10 @@ export declare class ComponentHandler extends BaseHandler {
35
37
  readonly commands: ComponentCommands[];
36
38
  filter: (path: string) => boolean;
37
39
  constructor(logger: Logger, client: UsingClient);
40
+ private createMatchCallback;
38
41
  createComponentCollector(messageId: string, channelId: string, guildId: string | undefined, options?: ListenerOptions): CreateComponentCollectorResult;
39
42
  onComponent(id: string, interaction: ComponentInteraction): Promise<any>;
40
- hasComponent(id: string, customId: string): boolean;
43
+ hasComponent(id: string, customId: string): boolean | undefined;
41
44
  resetTimeouts(id: string): void;
42
45
  hasModal(interaction: ModalSubmitInteraction): boolean;
43
46
  onModalSubmit(interaction: ModalSubmitInteraction): any;
@@ -18,6 +18,13 @@ class ComponentHandler extends common_1.BaseHandler {
18
18
  super(logger);
19
19
  this.client = client;
20
20
  }
21
+ createMatchCallback(match) {
22
+ if (typeof match === 'string')
23
+ return str => str === match;
24
+ if (Array.isArray(match))
25
+ return str => match.includes(str);
26
+ return str => match.test(str);
27
+ }
21
28
  createComponentCollector(messageId, channelId, guildId, options = {}) {
22
29
  this.values.set(messageId, {
23
30
  messageId,
@@ -45,7 +52,7 @@ class ComponentHandler extends common_1.BaseHandler {
45
52
  if (this.values.has(messageId)) {
46
53
  this.values.get(messageId).components.push({
47
54
  callback,
48
- match: customId,
55
+ match: this.createMatchCallback(customId),
49
56
  });
50
57
  }
51
58
  },
@@ -63,13 +70,7 @@ class ComponentHandler extends common_1.BaseHandler {
63
70
  }
64
71
  async onComponent(id, interaction) {
65
72
  const row = this.values.get(id);
66
- const component = row?.components?.find(x => {
67
- if (typeof x.match === 'string')
68
- return x.match === interaction.customId;
69
- if (Array.isArray(x.match))
70
- return x.match.includes(interaction.customId);
71
- return interaction.customId.match(x.match);
72
- });
73
+ const component = row?.components?.find(x => x.match(interaction.customId));
73
74
  if (!component)
74
75
  return;
75
76
  if (row.options?.filter) {
@@ -87,13 +88,7 @@ class ComponentHandler extends common_1.BaseHandler {
87
88
  });
88
89
  }
89
90
  hasComponent(id, customId) {
90
- return (this.values.get(id)?.components?.some(x => {
91
- if (typeof x.match === 'string')
92
- return x.match === customId;
93
- if (Array.isArray(x.match))
94
- return x.match.includes(customId);
95
- return customId.match(x.match);
96
- }) ?? false);
91
+ return this.values.get(id)?.components?.some(x => x.match(customId));
97
92
  }
98
93
  resetTimeouts(id) {
99
94
  const listener = this.values.get(id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seyfert",
3
- "version": "2.1.1-dev-11415196258.0",
3
+ "version": "2.1.1-dev-11420062278.0",
4
4
  "description": "The most advanced framework for discord bots",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",