seyfert 1.1.0 → 1.1.1

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.
Files changed (48) hide show
  1. package/lib/cache/adapters/types.d.ts +23 -23
  2. package/lib/cache/resources/default/base.d.ts +9 -9
  3. package/lib/cache/resources/default/guild-based.d.ts +6 -6
  4. package/lib/cache/resources/default/guild-based.js +2 -1
  5. package/lib/cache/resources/default/guild-related.d.ts +8 -8
  6. package/lib/cache/resources/default/guild-related.js +2 -1
  7. package/lib/client/base.d.ts +15 -9
  8. package/lib/client/base.js +45 -7
  9. package/lib/client/client.d.ts +5 -3
  10. package/lib/client/client.js +19 -7
  11. package/lib/client/oninteractioncreate.js +7 -7
  12. package/lib/client/onmessagecreate.js +4 -1
  13. package/lib/client/workerclient.d.ts +8 -3
  14. package/lib/client/workerclient.js +14 -8
  15. package/lib/commands/applications/chat.d.ts +1 -1
  16. package/lib/commands/applications/chat.js +13 -6
  17. package/lib/commands/applications/chatcontext.d.ts +1 -1
  18. package/lib/commands/applications/menu.js +7 -5
  19. package/lib/commands/applications/menucontext.d.ts +1 -1
  20. package/lib/commands/applications/menucontext.js +1 -1
  21. package/lib/commands/applications/shared.d.ts +5 -4
  22. package/lib/commands/decorators.d.ts +1 -1
  23. package/lib/commands/decorators.js +1 -1
  24. package/lib/commands/handler.d.ts +6 -0
  25. package/lib/commands/handler.js +6 -1
  26. package/lib/common/it/utils.d.ts +1 -0
  27. package/lib/common/it/utils.js +2 -1
  28. package/lib/common/shorters/messages.d.ts +1 -1
  29. package/lib/common/shorters/messages.js +1 -1
  30. package/lib/common/shorters/users.d.ts +0 -6
  31. package/lib/common/shorters/users.js +0 -34
  32. package/lib/common/types/util.d.ts +3 -0
  33. package/lib/components/handler.d.ts +19 -3
  34. package/lib/components/handler.js +10 -8
  35. package/lib/events/handler.d.ts +10 -2
  36. package/lib/events/handler.js +6 -8
  37. package/lib/index.js +1 -1
  38. package/lib/langs/handler.d.ts +8 -0
  39. package/lib/langs/handler.js +1 -0
  40. package/lib/structures/GuildMember.d.ts +1 -0
  41. package/lib/structures/GuildMember.js +3 -0
  42. package/lib/structures/Interaction.d.ts +2 -2
  43. package/lib/structures/Interaction.js +1 -1
  44. package/lib/structures/Message.d.ts +1 -1
  45. package/lib/structures/User.d.ts +1 -0
  46. package/lib/structures/User.js +5 -0
  47. package/lib/structures/channels.d.ts +2 -2
  48. package/package.json +1 -1
@@ -6,7 +6,7 @@ class BaseCommand {
6
6
  middlewares = [];
7
7
  __filePath;
8
8
  __t;
9
- __d;
9
+ __autoload;
10
10
  __tGroups;
11
11
  guild_id;
12
12
  name;
@@ -76,19 +76,21 @@ class BaseCommand {
76
76
  running = false;
77
77
  return res({ pass: true });
78
78
  };
79
- const next = obj => {
79
+ function next(obj) {
80
80
  if (!running) {
81
81
  return;
82
82
  }
83
- context[global ? 'globalMetadata' : 'metadata'] ??= {};
84
- // @ts-expect-error
85
- context[global ? 'globalMetadata' : 'metadata'][middlewares[index]] = obj;
83
+ // biome-ignore lint/style/noArguments: yes
84
+ if (arguments.length) {
85
+ // @ts-expect-error
86
+ context[global ? 'globalMetadata' : 'metadata'][middlewares[index]] = obj;
87
+ }
86
88
  if (++index >= middlewares.length) {
87
89
  running = false;
88
90
  return res({});
89
91
  }
90
92
  context.client.middlewares[middlewares[index]]({ context, next, stop, pass });
91
- };
93
+ }
92
94
  const stop = err => {
93
95
  if (!running) {
94
96
  return;
@@ -126,6 +128,11 @@ class BaseCommand {
126
128
  delete require.cache[this.__filePath];
127
129
  const __tempCommand = await (0, common_1.magicImport)(this.__filePath).then(x => x.default ?? x);
128
130
  Object.setPrototypeOf(this, __tempCommand.prototype);
131
+ for (const i of this.options ?? []) {
132
+ if (i instanceof SubCommand && i.__filePath) {
133
+ await i.reload();
134
+ }
135
+ }
129
136
  }
130
137
  }
131
138
  class Command extends BaseCommand {
@@ -28,7 +28,7 @@ export declare class CommandContext<T extends OptionsRecord = {}, M extends keyo
28
28
  write<FR extends boolean = false>(body: InteractionCreateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessage | Message, void | WebhookMessage | Message>>;
29
29
  deferReply(ephemeral?: boolean): Promise<void | Message>;
30
30
  editResponse(body: InteractionMessageUpdateBodyRequest): Promise<Message>;
31
- deleteResponse(): Promise<void>;
31
+ deleteResponse(): Promise<void | undefined>;
32
32
  editOrReply<FR extends boolean = false>(body: InteractionCreateBodyRequest | InteractionMessageUpdateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessage | Message, void | WebhookMessage | Message>>;
33
33
  fetchResponse(): Promise<If<InferWithPrefix, WebhookMessage | Message | undefined, WebhookMessage | undefined>>;
34
34
  channel(mode?: 'rest' | 'flow'): Promise<If<InferWithPrefix, AllChannels | undefined, AllChannels>>;
@@ -33,19 +33,21 @@ class ContextMenuCommand {
33
33
  running = false;
34
34
  return res({ pass: true });
35
35
  };
36
- const next = obj => {
36
+ function next(obj) {
37
37
  if (!running) {
38
38
  return;
39
39
  }
40
- context[global ? 'globalMetadata' : 'metadata'] ??= {};
41
- // @ts-expect-error
42
- context[global ? 'globalMetadata' : 'metadata'][middlewares[index]] = obj;
40
+ // biome-ignore lint/style/noArguments: yes
41
+ if (arguments.length) {
42
+ // @ts-expect-error
43
+ context[global ? 'globalMetadata' : 'metadata'][middlewares[index]] = obj;
44
+ }
43
45
  if (++index >= middlewares.length) {
44
46
  running = false;
45
47
  return res({});
46
48
  }
47
49
  context.client.middlewares[middlewares[index]]({ context, next, stop, pass });
48
- };
50
+ }
49
51
  const stop = err => {
50
52
  if (!running) {
51
53
  return;
@@ -24,7 +24,7 @@ export declare class MenuCommandContext<T extends MessageCommandInteraction | Us
24
24
  get modal(): ((body: import("../../common").ModalCreateBodyRequest) => Promise<void>) | ((body: import("../../common").ModalCreateBodyRequest) => Promise<void>);
25
25
  deferReply(ephemeral?: boolean): Promise<void>;
26
26
  editResponse(body: InteractionMessageUpdateBodyRequest): Promise<Message>;
27
- deleteResponse(): Promise<void>;
27
+ deleteResponse(): Promise<void | undefined>;
28
28
  editOrReply<FR extends boolean = false>(body: InteractionCreateBodyRequest | InteractionMessageUpdateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessage | Message, void | WebhookMessage | Message>>;
29
29
  fetchResponse(): Promise<WebhookMessage | undefined>;
30
30
  channel(mode?: 'rest' | 'flow'): Promise<AllChannels>;
@@ -34,7 +34,7 @@ class MenuCommandContext {
34
34
  }
35
35
  }
36
36
  get t() {
37
- return this.client.langs.get(this.interaction.locale);
37
+ return this.client.langs.get(this.interaction.locale ?? this.client.langs.defaultLang ?? 'en-US');
38
38
  }
39
39
  get fullCommandName() {
40
40
  return this.command.name;
@@ -1,8 +1,9 @@
1
1
  import type { BaseClient } from '../../client/base';
2
+ import type { IsStrictlyUndefined } from '../../common';
2
3
  import type { RegisteredMiddlewares } from '../decorators';
3
4
  export type OKFunction<T> = (value: T) => void;
4
5
  export type StopFunction = (error: string) => void;
5
- export type NextFunction<T = unknown> = (data: T) => void;
6
+ export type NextFunction<T = unknown> = IsStrictlyUndefined<T> extends true ? () => void : (data: T) => void;
6
7
  export type PassFunction = () => void;
7
8
  export type InferWithPrefix = InternalOptions extends {
8
9
  withPrefix: infer P;
@@ -24,13 +25,13 @@ export type MiddlewareContext<T = any, C = any> = (context: {
24
25
  stop: StopFunction;
25
26
  pass: PassFunction;
26
27
  }) => any;
27
- export type MetadataMiddleware<T extends MiddlewareContext> = Parameters<Parameters<T>[0]['next']>[0];
28
+ export type MetadataMiddleware<T extends MiddlewareContext> = IsStrictlyUndefined<Parameters<Parameters<T>[0]['next']>[0]> extends true ? never : Parameters<Parameters<T>[0]['next']>[0];
28
29
  export type CommandMetadata<T extends readonly (keyof RegisteredMiddlewares)[]> = T extends readonly [
29
30
  infer first,
30
31
  ...infer rest
31
- ] ? first extends keyof RegisteredMiddlewares ? {
32
+ ] ? first extends keyof RegisteredMiddlewares ? (MetadataMiddleware<RegisteredMiddlewares[first]> extends never ? {} : {
32
33
  [key in first]: MetadataMiddleware<RegisteredMiddlewares[first]>;
33
- } & (rest extends readonly (keyof RegisteredMiddlewares)[] ? CommandMetadata<rest> : {}) : {} : {};
34
+ }) & (rest extends readonly (keyof RegisteredMiddlewares)[] ? CommandMetadata<rest> : {}) : {} : {};
34
35
  export type OnOptionsReturnObject = Record<string, {
35
36
  failed: false;
36
37
  value: unknown;
@@ -92,7 +92,7 @@ export declare function Options(options: (new () => SubCommand)[] | OptionsRecor
92
92
  } & T;
93
93
  export declare function AutoLoad(): <T extends new (...args: any[]) => {}>(target: T) => {
94
94
  new (...args: any[]): {
95
- __d: boolean;
95
+ __autoload: boolean;
96
96
  };
97
97
  } & T;
98
98
  export type ParseMiddlewares<T extends Record<string, MiddlewareContext>> = {
@@ -59,7 +59,7 @@ function Options(options) {
59
59
  exports.Options = Options;
60
60
  function AutoLoad() {
61
61
  return (target) => class extends target {
62
- __d = true;
62
+ __autoload = true;
63
63
  };
64
64
  }
65
65
  exports.AutoLoad = AutoLoad;
@@ -3,6 +3,12 @@ import { BaseHandler } from '../common';
3
3
  import { Command } from './applications/chat';
4
4
  import { ContextMenuCommand } from './applications/menu';
5
5
  import type { UsingClient } from './applications/shared';
6
+ export interface CommandHandlerLike {
7
+ values: CommandHandler['values'];
8
+ load: CommandHandler['load'];
9
+ reload: CommandHandler['reload'];
10
+ reloadAll: CommandHandler['reloadAll'];
11
+ }
6
12
  export declare class CommandHandler extends BaseHandler {
7
13
  protected logger: Logger;
8
14
  protected client: UsingClient;
@@ -39,6 +39,7 @@ class CommandHandler extends common_1.BaseHandler {
39
39
  for (const command of result) {
40
40
  let commandInstance;
41
41
  try {
42
+ //@ts-expect-error abstract class
42
43
  commandInstance = new command.file();
43
44
  }
44
45
  catch (e) {
@@ -55,6 +56,7 @@ class CommandHandler extends common_1.BaseHandler {
55
56
  if (commandInstance instanceof menu_1.ContextMenuCommand) {
56
57
  this.values.push(commandInstance);
57
58
  commandInstance.__filePath = command.path;
59
+ await this.__callback?.(commandInstance);
58
60
  continue;
59
61
  }
60
62
  if (!(commandInstance instanceof chat_1.Command)) {
@@ -62,7 +64,7 @@ class CommandHandler extends common_1.BaseHandler {
62
64
  }
63
65
  commandInstance.__filePath = command.path;
64
66
  commandInstance.options ??= [];
65
- if (commandInstance.__d) {
67
+ if (commandInstance.__autoload) {
66
68
  //@AutoLoad
67
69
  const options = await this.getFiles((0, node_path_1.dirname)(command.path));
68
70
  for (const option of options) {
@@ -70,8 +72,10 @@ class CommandHandler extends common_1.BaseHandler {
70
72
  continue;
71
73
  }
72
74
  try {
75
+ //@ts-expect-error abstract class
73
76
  const subCommand = new (result.find(x => x.path === option).file)();
74
77
  if (subCommand instanceof chat_1.SubCommand) {
78
+ subCommand.__filePath = option;
75
79
  commandInstance.options.push(subCommand);
76
80
  }
77
81
  }
@@ -102,6 +106,7 @@ class CommandHandler extends common_1.BaseHandler {
102
106
  this.__parseCommandLocales(i, client);
103
107
  }
104
108
  }
109
+ await this.__callback?.(commandInstance);
105
110
  }
106
111
  return this.values;
107
112
  }
@@ -40,6 +40,7 @@ export declare function filterSplit<Element, Predicate extends (value: Element)
40
40
  */
41
41
  export declare class BaseHandler {
42
42
  protected logger: Logger;
43
+ __callback?: (...args: any[]) => any;
43
44
  /**
44
45
  * Initializes a new instance of the BaseHandler class.
45
46
  * @param logger The logger instance.
@@ -95,6 +95,7 @@ exports.filterSplit = filterSplit;
95
95
  */
96
96
  class BaseHandler {
97
97
  logger;
98
+ __callback;
98
99
  /**
99
100
  * Initializes a new instance of the BaseHandler class.
100
101
  * @param logger The logger instance.
@@ -241,7 +242,7 @@ async function magicImport(path) {
241
242
  }
242
243
  catch {
243
244
  // biome-ignore lint/security/noGlobalEval: modules import broke
244
- return eval('((path) => import(`file:///${path}`))')(path.split('\\').join('\\\\'));
245
+ return eval('((path) => import(`file:///${path}?update=${Date.now()}`))')(path.split('\\').join('\\\\'));
245
246
  }
246
247
  }
247
248
  exports.magicImport = magicImport;
@@ -6,7 +6,7 @@ export declare class MessageShorter extends BaseShorter {
6
6
  write(channelId: string, { files, ...body }: MessageCreateBodyRequest): Promise<Message>;
7
7
  edit(messageId: string, channelId: string, { files, ...body }: MessageUpdateBodyRequest): Promise<Message>;
8
8
  crosspost(messageId: string, channelId: string, reason?: string): Promise<Message>;
9
- delete(messageId: string, channelId: string, reason?: string): Promise<void>;
9
+ delete(messageId: string, channelId: string, reason?: string): Promise<void | undefined>;
10
10
  fetch(messageId: string, channelId: string): Promise<Message>;
11
11
  purge(messages: string[], channelId: string, reason?: string): Promise<never>;
12
12
  thread(channelId: string, messageId: string, options: RESTPostAPIChannelMessagesThreadsJSONBody & {
@@ -44,7 +44,7 @@ class MessageShorter extends base_1.BaseShorter {
44
44
  .messages(messageId)
45
45
  .delete({ reason })
46
46
  .then(() => {
47
- return this.client.components.onMessageDelete(messageId);
47
+ return this.client.components?.onMessageDelete(messageId);
48
48
  });
49
49
  }
50
50
  fetch(messageId, channelId) {
@@ -6,10 +6,4 @@ export declare class UsersShorter extends BaseShorter {
6
6
  deleteDM(userId: string, reason?: string): Promise<DMChannel>;
7
7
  fetch(userId: string, force?: boolean): Promise<User>;
8
8
  write(userId: string, body: MessageCreateBodyRequest): Promise<import("../../structures").Message>;
9
- get users(): {
10
- createDM: (userId: string, force?: boolean) => Promise<DMChannel>;
11
- deleteDM: (userId: string, reason?: string) => Promise<DMChannel>;
12
- fetch: (userId: string, force?: boolean) => Promise<User>;
13
- write: (userId: string, body: MessageCreateBodyRequest) => Promise<import("../../structures").Message>;
14
- };
15
9
  }
@@ -34,39 +34,5 @@ class UsersShorter extends base_1.BaseShorter {
34
34
  async write(userId, body) {
35
35
  return (await this.client.users.createDM(userId)).messages.write(body);
36
36
  }
37
- get users() {
38
- return {
39
- createDM: async (userId, force = false) => {
40
- if (!force) {
41
- const dm = await this.client.cache.channels?.get(userId);
42
- if (dm)
43
- return dm;
44
- }
45
- const data = await this.client.proxy.users('@me').channels.post({
46
- body: { recipient_id: userId },
47
- });
48
- await this.client.cache.channels?.set(userId, '@me', data);
49
- return new structures_1.DMChannel(this.client, data);
50
- },
51
- deleteDM: async (userId, reason) => {
52
- const res = await this.client.proxy.channels(userId).delete({ reason });
53
- await this.client.cache.channels?.removeIfNI(structures_1.BaseChannel.__intent__('@me'), res.id, '@me');
54
- return new structures_1.DMChannel(this.client, res);
55
- },
56
- fetch: async (userId, force = false) => {
57
- if (!force) {
58
- const user = await this.client.cache.users?.get(userId);
59
- if (user)
60
- return user;
61
- }
62
- const data = await this.client.proxy.users(userId).get();
63
- await this.client.cache.users?.patch(userId, data);
64
- return new structures_1.User(this.client, data);
65
- },
66
- write: async (userId, body) => {
67
- return (await this.client.users.createDM(userId)).messages.write(body);
68
- },
69
- };
70
- }
71
37
  }
72
38
  exports.UsersShorter = UsersShorter;
@@ -34,6 +34,8 @@ export type Identify<T> = T extends infer U ? {
34
34
  } : never;
35
35
  export type TypeArray<T> = T | T[];
36
36
  export type When<T extends boolean, A, B = never> = T extends true ? A : B;
37
+ export type AuxIsStrictlyUndefined<T> = T extends undefined | null | never | void ? true : false;
38
+ export type IsStrictlyUndefined<T> = AuxIsStrictlyUndefined<T> extends true ? true : AuxIsStrictlyUndefined<T> extends false ? false : false;
37
39
  export type If<T extends boolean, A, B = null> = T extends true ? A : B extends null ? A | null : B;
38
40
  export type PickPartial<T, K extends keyof T> = {
39
41
  [P in keyof T]?: T[P] | undefined;
@@ -88,4 +90,5 @@ export type AtLeastOne<T, U = {
88
90
  [K in keyof T]: Pick<T, K>;
89
91
  }> = Partial<T> & U[keyof U];
90
92
  export type FlatObjectKeys<T extends Record<string, any>, Key = keyof T> = Key extends string ? T[Key] extends Record<string, unknown> ? `${Key}.${FlatObjectKeys<T[Key]>}` : T[Key] extends string ? `${Key}` : never : never;
93
+ export type Awaitable<V> = Promise<V> | V;
91
94
  export {};
@@ -16,21 +16,37 @@ type COMPONENTS = {
16
16
  timeout?: NodeJS.Timeout;
17
17
  __run: (customId: string | string[] | RegExp, callback: ComponentCallback) => any;
18
18
  };
19
+ export interface ComponentHandlerLike {
20
+ readonly values: Map<string, COMPONENTS>;
21
+ readonly commands: (ComponentCommand | ModalCommand)[];
22
+ readonly modals: Map<string, ModalSubmitCallback> | LimitedCollection<string, ModalSubmitCallback>;
23
+ onFail: ComponentHandler['onFail'];
24
+ createComponentCollector: ComponentHandler['createComponentCollector'];
25
+ hasModal: ComponentHandler['hasModal'];
26
+ onModalSubmit: ComponentHandler['onModalSubmit'];
27
+ executeModal: ComponentHandler['executeModal'];
28
+ hasComponent: ComponentHandler['hasComponent'];
29
+ executeComponent: ComponentHandler['executeComponent'];
30
+ onComponent: ComponentHandler['onComponent'];
31
+ load: ComponentHandler['load'];
32
+ reload: ComponentHandler['reload'];
33
+ reloadAll: ComponentHandler['reloadAll'];
34
+ onMessageDelete: ComponentHandler['onMessageDelete'];
35
+ }
19
36
  export declare class ComponentHandler extends BaseHandler {
20
37
  protected client: UsingClient;
21
- protected onFail?: OnFailCallback;
38
+ onFail: OnFailCallback;
22
39
  readonly values: Map<string, COMPONENTS>;
23
40
  readonly modals: LimitedCollection<string, ModalSubmitCallback>;
24
41
  readonly commands: (ComponentCommand | ModalCommand)[];
25
42
  protected filter: (path: string) => boolean;
26
43
  constructor(logger: Logger, client: UsingClient);
27
- set OnFail(cb: OnFailCallback);
28
44
  createComponentCollector(messageId: string, options?: ListenerOptions): {
29
45
  run: (customId: string | RegExp | string[], callback: ComponentCallback) => any;
30
46
  stop: (reason?: string) => void;
31
47
  };
32
48
  onComponent(id: string, interaction: ComponentInteraction): Promise<void>;
33
- hasComponent(id: string, customId: string): boolean | undefined;
49
+ hasComponent(id: string, customId: string): boolean;
34
50
  resetTimeouts(id: string): void;
35
51
  hasModal(interaction: ModalSubmitInteraction): boolean;
36
52
  onModalSubmit(interaction: ModalSubmitInteraction): any;
@@ -6,7 +6,7 @@ const common_1 = require("../common");
6
6
  const command_1 = require("./command");
7
7
  class ComponentHandler extends common_1.BaseHandler {
8
8
  client;
9
- onFail;
9
+ onFail = err => this.logger.warn('<Client>.components.onFail', err);
10
10
  values = new Map();
11
11
  // 10 minutes timeout, because discord dont send an event when the user cancel the modal
12
12
  modals = new collection_1.LimitedCollection({ expire: 60e3 * 10 });
@@ -16,9 +16,6 @@ class ComponentHandler extends common_1.BaseHandler {
16
16
  super(logger);
17
17
  this.client = client;
18
18
  }
19
- set OnFail(cb) {
20
- this.onFail = cb;
21
- }
22
19
  createComponentCollector(messageId, options = {}) {
23
20
  this.values.set(messageId, {
24
21
  components: [],
@@ -82,13 +79,13 @@ class ComponentHandler extends common_1.BaseHandler {
82
79
  });
83
80
  }
84
81
  hasComponent(id, customId) {
85
- return this.values.get(id)?.components?.some(x => {
82
+ return (this.values.get(id)?.components?.some(x => {
86
83
  if (typeof x.match === 'string')
87
84
  return x.match === customId;
88
85
  if (Array.isArray(x.match))
89
86
  return x.match.includes(customId);
90
87
  return customId.match(x.match);
91
- });
88
+ }) ?? false);
92
89
  }
93
90
  resetTimeouts(id) {
94
91
  const listener = this.values.get(id);
@@ -139,9 +136,12 @@ class ComponentHandler extends common_1.BaseHandler {
139
136
  continue;
140
137
  component.__filePath = paths[i].path;
141
138
  this.commands.push(component);
139
+ await this.__callback?.(component);
142
140
  }
143
141
  }
144
142
  async reload(path) {
143
+ if (!this.client.components)
144
+ return;
145
145
  const component = this.client.components.commands.find(x => x.__filePath?.endsWith(`${path}.js`) ||
146
146
  x.__filePath?.endsWith(`${path}.ts`) ||
147
147
  x.__filePath?.endsWith(path) ||
@@ -160,6 +160,8 @@ class ComponentHandler extends common_1.BaseHandler {
160
160
  return imported;
161
161
  }
162
162
  async reloadAll() {
163
+ if (!this.client.components)
164
+ return;
163
165
  for (const i of this.client.components.commands) {
164
166
  if (!i.__filePath)
165
167
  return this.logger.warn('Unknown command dont have __filePath property', i);
@@ -177,7 +179,7 @@ class ComponentHandler extends common_1.BaseHandler {
177
179
  }
178
180
  }
179
181
  catch (e) {
180
- await this.onFail?.(e);
182
+ await this.onFail(e);
181
183
  }
182
184
  }
183
185
  }
@@ -190,7 +192,7 @@ class ComponentHandler extends common_1.BaseHandler {
190
192
  }
191
193
  }
192
194
  catch (e) {
193
- await this.onFail?.(e);
195
+ await this.onFail(e);
194
196
  }
195
197
  }
196
198
  }
@@ -6,11 +6,19 @@ type EventValue = MakeRequired<ClientEvent, '__filePath'> & {
6
6
  fired?: boolean;
7
7
  };
8
8
  type GatewayEvents = Uppercase<SnakeCase<keyof ClientEvents>>;
9
+ export interface EventHandlerLike {
10
+ runEvent: EventHandler['runEvent'];
11
+ execute: EventHandler['execute'];
12
+ load: EventHandler['load'];
13
+ reload: EventHandler['reload'];
14
+ reloadAll: EventHandler['reloadAll'];
15
+ values: EventHandler['values'];
16
+ onFail: EventHandler['onFail'];
17
+ }
9
18
  export declare class EventHandler extends BaseHandler {
10
- protected onFail: OnFailCallback;
19
+ onFail: OnFailCallback;
11
20
  protected filter: (path: string) => boolean;
12
21
  values: Partial<Record<GatewayEvents, EventValue>>;
13
- set OnFail(cb: OnFailCallback);
14
22
  load(eventsDir: string): Promise<void>;
15
23
  execute(name: GatewayEvents, ...args: [GatewayDispatchPayload, Client<true> | WorkerClient<true>, number]): Promise<void>;
16
24
  runEvent(name: GatewayEvents, client: Client | WorkerClient, packet: any, shardId: number): Promise<void>;
@@ -27,12 +27,9 @@ exports.EventHandler = void 0;
27
27
  const common_1 = require("../common");
28
28
  const RawEvents = __importStar(require("../events/hooks"));
29
29
  class EventHandler extends common_1.BaseHandler {
30
- onFail = err => this.logger.warn('<Client>.events.OnFail', err);
30
+ onFail = err => this.logger.warn('<Client>.events.onFail', err);
31
31
  filter = (path) => path.endsWith('.js') || (!path.endsWith('.d.ts') && path.endsWith('.ts'));
32
32
  values = {};
33
- set OnFail(cb) {
34
- this.onFail = cb;
35
- }
36
33
  async load(eventsDir) {
37
34
  for (const i of await this.loadFilesK(await this.getFiles(eventsDir))) {
38
35
  const instance = i.file;
@@ -42,6 +39,7 @@ class EventHandler extends common_1.BaseHandler {
42
39
  }
43
40
  instance.__filePath = i.path;
44
41
  this.values[common_1.ReplaceRegex.snake(instance.data.name).toUpperCase()] = instance;
42
+ await this.__callback?.(instance);
45
43
  }
46
44
  }
47
45
  async execute(name, ...args) {
@@ -54,7 +52,7 @@ class EventHandler extends common_1.BaseHandler {
54
52
  case 'MESSAGE_CREATE':
55
53
  {
56
54
  const { d: data } = args[0];
57
- if (args[1].components.values.has(data.interaction?.id ?? data.id)) {
55
+ if (args[1].components?.values.has(data.interaction?.id ?? data.id)) {
58
56
  args[1].components.values.get(data.interaction?.id ?? data.id).messageId = data.id;
59
57
  }
60
58
  }
@@ -62,7 +60,7 @@ class EventHandler extends common_1.BaseHandler {
62
60
  case 'MESSAGE_DELETE':
63
61
  {
64
62
  const { d: data } = args[0];
65
- const value = [...args[1].components.values].find(x => x[1].messageId === data.id);
63
+ const value = [...(args[1].components?.values ?? [])].find(x => x[1].messageId === data.id);
66
64
  if (value) {
67
65
  args[1].components.onMessageDelete(value[0]);
68
66
  }
@@ -71,7 +69,7 @@ class EventHandler extends common_1.BaseHandler {
71
69
  case 'MESSAGE_DELETE_BULK':
72
70
  {
73
71
  const { d: data } = args[0];
74
- const values = [...args[1].components.values];
72
+ const values = [...(args[1].components?.values ?? [])];
75
73
  data.ids.forEach(id => {
76
74
  const value = values.find(x => x[1].messageId === id);
77
75
  if (value) {
@@ -97,7 +95,7 @@ class EventHandler extends common_1.BaseHandler {
97
95
  await Event.run(...[hook, client, shardId]);
98
96
  }
99
97
  catch (e) {
100
- await this.onFail?.(e);
98
+ await this.onFail(e);
101
99
  }
102
100
  }
103
101
  async reload(name) {
package/lib/index.js CHANGED
@@ -77,7 +77,7 @@ exports.config = {
77
77
  intents: 'intents' in data
78
78
  ? typeof data.intents === 'number'
79
79
  ? data.intents
80
- : data.intents?.reduce((pr, acc) => pr | common_1.GatewayIntentBits[acc], 0) ?? 0
80
+ : data.intents?.reduce((pr, acc) => pr | (typeof acc === 'number' ? acc : common_1.GatewayIntentBits[acc]), 0) ?? 0
81
81
  : 0,
82
82
  };
83
83
  },
@@ -1,4 +1,12 @@
1
1
  import { BaseHandler, type LocaleString } from '../common';
2
+ export interface LangsHandlerLike {
3
+ getKey: LangsHandler['getKey'];
4
+ load: LangsHandler['load'];
5
+ values: LangsHandler['values'];
6
+ aliases: LangsHandler['aliases'];
7
+ get: LangsHandler['get'];
8
+ defaultLang?: LangsHandler['defaultLang'];
9
+ }
2
10
  export declare class LangsHandler extends BaseHandler {
3
11
  values: Partial<Record<string, any>>;
4
12
  protected filter: (path: string) => boolean;
@@ -35,6 +35,7 @@ class LangsHandler extends common_1.BaseHandler {
35
35
  for (const i of files) {
36
36
  const locale = i.name.split('.').slice(0, -1).join('.');
37
37
  this.values[locale] = i.file;
38
+ await this.__callback?.(locale, i.file);
38
39
  }
39
40
  }
40
41
  }
@@ -81,6 +81,7 @@ export declare class GuildMember extends BaseGuildMember {
81
81
  write(body: MessageCreateBodyRequest): Promise<import("./Message").Message>;
82
82
  avatarURL(options?: ImageOptions): string;
83
83
  dynamicAvatarURL(options?: ImageOptions): string;
84
+ bannerURL(options?: ImageOptions): string | undefined;
84
85
  fetchPermissions(): Promise<PermissionsBitField>;
85
86
  }
86
87
  export interface UnavailableMember {
@@ -125,6 +125,9 @@ class GuildMember extends BaseGuildMember {
125
125
  }
126
126
  return this.rest.cdn.guildMemberAvatar(this.guildId, this.id, this.avatar, options);
127
127
  }
128
+ bannerURL(options) {
129
+ return this.user.bannerURL(options);
130
+ }
128
131
  async fetchPermissions() {
129
132
  if ('permissions' in this)
130
133
  return this.permissions;
@@ -57,8 +57,8 @@ export declare class Interaction<FromGuild extends boolean = boolean, Type exten
57
57
  editOrReply<FR extends boolean = false>(body: InteractionCreateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessage, void>>;
58
58
  editMessage(messageId: string, body: InteractionMessageUpdateBodyRequest): Promise<Message>;
59
59
  editResponse(body: InteractionMessageUpdateBodyRequest): Promise<Message>;
60
- deleteResponse(): Promise<void>;
61
- deleteMessage(messageId: string): Promise<void>;
60
+ deleteResponse(): Promise<void | undefined>;
61
+ deleteMessage(messageId: string): Promise<void | undefined>;
62
62
  createResponse({ files, ...body }: MessageWebhookCreateBodyRequest): Promise<Message>;
63
63
  }
64
64
  export declare class ApplicationCommandInteraction<FromGuild extends boolean = boolean, Type extends APIApplicationCommandInteraction = APIApplicationCommandInteraction> extends Interaction<FromGuild, Type> {
@@ -240,7 +240,7 @@ class Interaction extends BaseInteraction {
240
240
  .webhooks(this.applicationId)(this.token)
241
241
  .messages(messageId)
242
242
  .delete()
243
- .then(() => this.client.components.onMessageDelete(messageId === '@original' ? this.id : messageId));
243
+ .then(() => this.client.components?.onMessageDelete(messageId === '@original' ? this.id : messageId));
244
244
  }
245
245
  async createResponse({ files, ...body }) {
246
246
  files ??= files ? await (0, builders_1.resolveFiles)(files) : undefined;
@@ -43,7 +43,7 @@ export declare class Message extends BaseMessage {
43
43
  reply(body: Omit<MessageCreateBodyRequest, 'message_reference'>, fail?: boolean): Promise<Message>;
44
44
  edit(body: MessageUpdateBodyRequest): Promise<Message>;
45
45
  write(body: MessageCreateBodyRequest): Promise<Message>;
46
- delete(reason?: string): Promise<void>;
46
+ delete(reason?: string): Promise<void | undefined>;
47
47
  crosspost(reason?: string): Promise<Message>;
48
48
  }
49
49
  export type EditMessageWebhook = Omit<MessageWebhookMethodEditParams, 'messageId'>;
@@ -16,6 +16,7 @@ export declare class User extends DiscordBase<APIUser> {
16
16
  dm(force?: boolean): Promise<import("./channels").DMChannel>;
17
17
  write(body: MessageCreateBodyRequest): Promise<import("./Message").Message>;
18
18
  avatarURL(options?: ImageOptions): string;
19
+ bannerURL(options?: ImageOptions): string | undefined;
19
20
  presence(): import("..").ReturnCache<(Omit<import("discord-api-types/payloads/v10/gateway").GatewayPresenceUpdate, "user"> & {
20
21
  id: string;
21
22
  } & {
@@ -30,6 +30,11 @@ class User extends DiscordBase_1.DiscordBase {
30
30
  }
31
31
  return this.rest.cdn.avatar(this.id, this.avatar, options);
32
32
  }
33
+ bannerURL(options) {
34
+ if (!this.banner)
35
+ return;
36
+ return this.rest.cdn.banner(this.id, this.banner, options);
37
+ }
33
38
  presence() {
34
39
  return this.cache.presences?.get(this.id);
35
40
  }