seyfert 1.2.3 → 1.3.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 (125) hide show
  1. package/lib/api/Routes/channels.d.ts +15 -1
  2. package/lib/api/api.js +5 -1
  3. package/lib/api/shared.d.ts +3 -1
  4. package/lib/api/utils/utils.d.ts +1 -1
  5. package/lib/api/utils/utils.js +2 -2
  6. package/lib/builders/Poll.d.ts +16 -0
  7. package/lib/builders/Poll.js +48 -0
  8. package/lib/builders/index.d.ts +1 -0
  9. package/lib/builders/index.js +1 -0
  10. package/lib/cache/adapters/index.d.ts +1 -0
  11. package/lib/cache/adapters/index.js +1 -0
  12. package/lib/cache/adapters/limited.d.ts +50 -0
  13. package/lib/cache/adapters/limited.js +188 -0
  14. package/lib/cache/index.d.ts +5 -2
  15. package/lib/cache/index.js +38 -7
  16. package/lib/cache/resources/channels.d.ts +2 -1
  17. package/lib/cache/resources/default/base.d.ts +3 -3
  18. package/lib/cache/resources/default/base.js +8 -3
  19. package/lib/cache/resources/default/guild-based.d.ts +2 -1
  20. package/lib/cache/resources/default/guild-based.js +7 -3
  21. package/lib/cache/resources/default/guild-related.d.ts +2 -1
  22. package/lib/cache/resources/default/guild-related.js +7 -3
  23. package/lib/cache/resources/emojis.d.ts +2 -0
  24. package/lib/cache/resources/emojis.js +4 -0
  25. package/lib/cache/resources/guilds.d.ts +2 -0
  26. package/lib/cache/resources/guilds.js +4 -0
  27. package/lib/cache/resources/members.d.ts +2 -0
  28. package/lib/cache/resources/members.js +5 -1
  29. package/lib/cache/resources/messages.d.ts +15 -0
  30. package/lib/cache/resources/messages.js +53 -0
  31. package/lib/cache/resources/overwrites.d.ts +2 -0
  32. package/lib/cache/resources/overwrites.js +4 -0
  33. package/lib/cache/resources/presence.d.ts +1 -0
  34. package/lib/cache/resources/presence.js +4 -0
  35. package/lib/cache/resources/roles.d.ts +2 -0
  36. package/lib/cache/resources/roles.js +4 -0
  37. package/lib/cache/resources/stage-instances.d.ts +1 -0
  38. package/lib/cache/resources/stage-instances.js +5 -1
  39. package/lib/cache/resources/stickers.d.ts +2 -0
  40. package/lib/cache/resources/stickers.js +4 -0
  41. package/lib/cache/resources/threads.d.ts +2 -0
  42. package/lib/cache/resources/threads.js +4 -0
  43. package/lib/cache/resources/users.d.ts +2 -0
  44. package/lib/cache/resources/users.js +4 -0
  45. package/lib/cache/resources/voice-states.d.ts +2 -1
  46. package/lib/cache/resources/voice-states.js +8 -4
  47. package/lib/client/base.d.ts +25 -13
  48. package/lib/client/base.js +33 -8
  49. package/lib/client/client.d.ts +6 -5
  50. package/lib/client/client.js +13 -1
  51. package/lib/client/oninteractioncreate.js +2 -2
  52. package/lib/client/onmessagecreate.js +2 -2
  53. package/lib/client/workerclient.d.ts +3 -3
  54. package/lib/client/workerclient.js +18 -3
  55. package/lib/collection.d.ts +8 -3
  56. package/lib/collection.js +22 -4
  57. package/lib/commands/applications/chat.d.ts +8 -14
  58. package/lib/commands/applications/chat.js +2 -20
  59. package/lib/commands/applications/chatcontext.d.ts +1 -1
  60. package/lib/commands/applications/menucontext.d.ts +1 -1
  61. package/lib/commands/handler.d.ts +11 -7
  62. package/lib/commands/handler.js +43 -14
  63. package/lib/common/index.d.ts +2 -0
  64. package/lib/common/index.js +2 -0
  65. package/lib/common/it/utils.d.ts +0 -1
  66. package/lib/common/it/utils.js +0 -1
  67. package/lib/common/shorters/channels.d.ts +5 -3
  68. package/lib/common/shorters/channels.js +24 -10
  69. package/lib/common/shorters/guilds.d.ts +7 -6
  70. package/lib/common/shorters/guilds.js +23 -4
  71. package/lib/common/shorters/interaction.d.ts +13 -0
  72. package/lib/common/shorters/interaction.js +61 -0
  73. package/lib/common/shorters/messages.d.ts +6 -3
  74. package/lib/common/shorters/messages.js +33 -15
  75. package/lib/common/shorters/roles.d.ts +3 -3
  76. package/lib/common/shorters/roles.js +12 -17
  77. package/lib/common/shorters/templates.d.ts +7 -6
  78. package/lib/common/shorters/templates.js +28 -6
  79. package/lib/common/shorters/threads.d.ts +39 -0
  80. package/lib/common/shorters/threads.js +76 -0
  81. package/lib/common/shorters/webhook.d.ts +1 -1
  82. package/lib/common/shorters/webhook.js +8 -2
  83. package/lib/common/types/util.d.ts +8 -2
  84. package/lib/common/types/write.d.ts +8 -5
  85. package/lib/components/ButtonComponent.js +1 -1
  86. package/lib/components/componentcontext.d.ts +1 -1
  87. package/lib/components/handler.d.ts +6 -17
  88. package/lib/components/handler.js +7 -2
  89. package/lib/events/handler.d.ts +8 -14
  90. package/lib/events/handler.js +9 -4
  91. package/lib/events/hooks/auto_moderation.d.ts +5 -1
  92. package/lib/events/hooks/guild.d.ts +692 -23
  93. package/lib/events/hooks/guild.js +2 -2
  94. package/lib/events/hooks/integration.d.ts +52 -47
  95. package/lib/events/hooks/interactions.d.ts +1 -1
  96. package/lib/events/hooks/invite.d.ts +67 -3
  97. package/lib/events/hooks/message.d.ts +96 -12
  98. package/lib/events/hooks/message.js +18 -7
  99. package/lib/events/hooks/presence.d.ts +48 -2
  100. package/lib/events/hooks/thread.d.ts +155 -18
  101. package/lib/events/hooks/typing.d.ts +13 -1
  102. package/lib/events/hooks/voice.d.ts +13 -1
  103. package/lib/langs/handler.d.ts +4 -8
  104. package/lib/langs/handler.js +7 -2
  105. package/lib/structures/AutoModerationRule.d.ts +7 -7
  106. package/lib/structures/AutoModerationRule.js +2 -1
  107. package/lib/structures/Guild.d.ts +15 -13
  108. package/lib/structures/GuildRole.d.ts +5 -5
  109. package/lib/structures/GuildTemplate.d.ts +10 -10
  110. package/lib/structures/Interaction.d.ts +4 -4
  111. package/lib/structures/Interaction.js +27 -48
  112. package/lib/structures/Message.d.ts +5 -3
  113. package/lib/structures/Message.js +5 -0
  114. package/lib/structures/Poll.d.ts +15 -0
  115. package/lib/structures/Poll.js +26 -0
  116. package/lib/structures/User.js +2 -2
  117. package/lib/structures/Webhook.d.ts +2 -2
  118. package/lib/structures/channels.d.ts +6 -3
  119. package/lib/structures/channels.js +16 -8
  120. package/lib/structures/extra/Permissions.d.ts +1 -0
  121. package/lib/structures/index.d.ts +1 -0
  122. package/lib/structures/index.js +1 -0
  123. package/lib/websocket/SharedTypes.d.ts +7 -2
  124. package/lib/websocket/discord/shard.js +1 -1
  125. package/package.json +8 -8
@@ -1,6 +1,7 @@
1
1
  import { type GatewayDispatchPayload, type GatewayPresenceUpdateData } from 'discord-api-types/v10';
2
- import type { ClientEvent, Command, CommandContext, EventHandlerLike, Message, SubCommand } from '..';
2
+ import type { Command, CommandContext, Message, SubCommand } from '..';
3
3
  import type { DeepPartial, If } from '../common';
4
+ import { EventHandler } from '../events';
4
5
  import { ClientUser } from '../structures';
5
6
  import { ShardManager, type ShardManagerOptions } from '../websocket';
6
7
  import { MemberUpdateHandler } from '../websocket/discord/events/memberUpdate';
@@ -10,7 +11,7 @@ import { BaseClient } from './base';
10
11
  export declare class Client<Ready extends boolean = boolean> extends BaseClient {
11
12
  private __handleGuilds?;
12
13
  gateway: ShardManager;
13
- events?: EventHandlerLike;
14
+ events?: EventHandler | undefined;
14
15
  me: If<Ready, ClientUser>;
15
16
  options: ClientOptions | undefined;
16
17
  memberUpdateHandler: MemberUpdateHandler;
@@ -19,7 +20,7 @@ export declare class Client<Ready extends boolean = boolean> extends BaseClient
19
20
  setServices({ gateway, ...rest }: ServicesOptions & {
20
21
  gateway?: ShardManager;
21
22
  handlers?: ServicesOptions['handlers'] & {
22
- events?: EventHandlerLike | ((event: ClientEvent) => any);
23
+ events?: EventHandler['callback'];
23
24
  };
24
25
  }): void;
25
26
  loadEvents(dir?: string): Promise<void>;
@@ -41,8 +42,8 @@ export interface ClientOptions extends BaseClientOptions {
41
42
  properties?: Partial<ShardManagerOptions['properties']>;
42
43
  compress?: ShardManagerOptions['compress'];
43
44
  };
44
- commands?: {
45
- prefix: (message: Message) => Promise<string[]> | string[];
45
+ commands?: BaseClientOptions['commands'] & {
46
+ prefix?: (message: Message) => Promise<string[]> | string[];
46
47
  deferReplyResponse?: (ctx: CommandContext) => Parameters<Message['write']>[0];
47
48
  reply?: (ctx: CommandContext) => boolean;
48
49
  argsParser?: (content: string, command: SubCommand | Command) => Record<string, string>;
@@ -38,7 +38,9 @@ class Client extends base_1.BaseClient {
38
38
  }
39
39
  else if (typeof rest.handlers.events === 'function') {
40
40
  this.events = new events_1.EventHandler(this.logger);
41
- this.events.__callback = rest.handlers.events;
41
+ this.events.setHandlers({
42
+ callback: rest.handlers.events,
43
+ });
42
44
  }
43
45
  else {
44
46
  this.events = rest.handlers.events;
@@ -121,6 +123,16 @@ class Client extends base_1.BaseClient {
121
123
  await this.events?.execute(packet.t, packet, this, shardId);
122
124
  await this.cache.onPacket(packet);
123
125
  break;
126
+ case 'MESSAGE_UPDATE':
127
+ case 'MESSAGE_DELETE_BULK':
128
+ case 'MESSAGE_DELETE':
129
+ await this.events?.execute(packet.t, packet, this, shardId);
130
+ await this.cache.onPacket(packet);
131
+ break;
132
+ case 'GUILD_DELETE':
133
+ case 'CHANNEL_UPDATE':
134
+ await this.events?.execute(packet.t, packet, this, shardId);
135
+ break;
124
136
  //rest of the events
125
137
  default: {
126
138
  await this.cache.onPacket(packet);
@@ -33,7 +33,7 @@ async function onInteractionCreate(self, body, shardId, __reply) {
33
33
  }
34
34
  catch (error) {
35
35
  try {
36
- await optionsResolver.getCommand()?.onInternalError?.(self, error);
36
+ await optionsResolver.getCommand()?.onInternalError?.(self, optionsResolver.getCommand(), error);
37
37
  }
38
38
  catch {
39
39
  // supress error
@@ -152,7 +152,7 @@ async function onInteractionCreate(self, body, shardId, __reply) {
152
152
  }
153
153
  catch (error) {
154
154
  try {
155
- await command.onInternalError?.(self, error);
155
+ await command.onInternalError?.(self, context.command, error);
156
156
  }
157
157
  catch {
158
158
  // supress error
@@ -40,7 +40,7 @@ function getCommandFromContent(commandRaw, self) {
40
40
  };
41
41
  }
42
42
  async function onMessageCreate(self, rawMessage, shardId) {
43
- if (!self.options?.commands)
43
+ if (!self.options?.commands?.prefix)
44
44
  return;
45
45
  const message = new structures_1.Message(self, rawMessage);
46
46
  const prefixes = (await self.options.commands.prefix(message)).sort((a, b) => b.length - a.length);
@@ -134,7 +134,7 @@ async function onMessageCreate(self, rawMessage, shardId) {
134
134
  }
135
135
  catch (error) {
136
136
  try {
137
- await command.onInternalError?.(self, error);
137
+ await command.onInternalError?.(self, context.command, error);
138
138
  }
139
139
  catch {
140
140
  // supress error
@@ -7,7 +7,7 @@ import { type GatewayDispatchPayload } from 'discord-api-types/v10';
7
7
  import { Logger } from '..';
8
8
  import type { Cache } from '../cache';
9
9
  import { type DeepPartial, type When } from '../common';
10
- import { type EventHandlerLike } from '../events';
10
+ import { EventHandler } from '../events';
11
11
  import { ClientUser } from '../structures';
12
12
  import { Shard, type ShardManagerOptions } from '../websocket';
13
13
  import type { WorkerShardInfo } from '../websocket/discord/worker';
@@ -18,7 +18,7 @@ import type { Client } from './client';
18
18
  export declare class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
19
19
  private __handleGuilds?;
20
20
  logger: Logger;
21
- events?: EventHandlerLike;
21
+ events?: EventHandler | undefined;
22
22
  me: When<Ready, ClientUser>;
23
23
  promises: Map<string, {
24
24
  resolve: (value: any) => void;
@@ -31,7 +31,7 @@ export declare class WorkerClient<Ready extends boolean = boolean> extends BaseC
31
31
  get latency(): number;
32
32
  setServices({ ...rest }: ServicesOptions & {
33
33
  handlers?: ServicesOptions['handlers'] & {
34
- events?: EventHandlerLike;
34
+ events?: EventHandler['callback'];
35
35
  };
36
36
  }): void;
37
37
  start(options?: Omit<DeepPartial<StartOptions>, 'httpConnection' | 'token' | 'connection'>): Promise<void>;
@@ -78,7 +78,18 @@ class WorkerClient extends base_1.BaseClient {
78
78
  setServices({ ...rest }) {
79
79
  super.setServices(rest);
80
80
  if (rest.handlers && 'events' in rest.handlers) {
81
- this.events = rest.handlers.events;
81
+ if (!rest.handlers.events) {
82
+ this.events = undefined;
83
+ }
84
+ else if (typeof rest.handlers.events === 'function') {
85
+ this.events = new events_1.EventHandler(this.logger);
86
+ this.events.setHandlers({
87
+ callback: rest.handlers.events,
88
+ });
89
+ }
90
+ else {
91
+ this.events = rest.handlers.events;
92
+ }
82
93
  }
83
94
  }
84
95
  async start(options = {}) {
@@ -274,12 +285,16 @@ class WorkerClient extends base_1.BaseClient {
274
285
  await this.events?.execute('RAW', packet, this, shardId);
275
286
  switch (packet.t) {
276
287
  case 'GUILD_MEMBER_UPDATE':
288
+ case 'PRESENCE_UPDATE':
289
+ case 'MESSAGE_UPDATE':
290
+ case 'MESSAGE_DELETE_BULK':
291
+ case 'MESSAGE_DELETE':
277
292
  await this.events?.execute(packet.t, packet, this, shardId);
278
293
  await this.cache.onPacket(packet);
279
294
  break;
280
- case 'PRESENCE_UPDATE':
295
+ case 'GUILD_DELETE':
296
+ case 'CHANNEL_UPDATE':
281
297
  await this.events?.execute(packet.t, packet, this, shardId);
282
- await this.cache.onPacket(packet);
283
298
  break;
284
299
  //rest of the events
285
300
  default:
@@ -119,9 +119,10 @@ type LimitedCollectionData<V> = {
119
119
  expireOn: number;
120
120
  value: V;
121
121
  };
122
- export interface LimitedCollectionOptions {
122
+ export interface LimitedCollectionOptions<K, V> {
123
123
  limit: number;
124
124
  expire: number;
125
+ onDelete?: (key: K, value: V) => void;
125
126
  resetOnDemand: boolean;
126
127
  }
127
128
  /**
@@ -138,11 +139,11 @@ export interface LimitedCollectionOptions {
138
139
  * console.log(mappedArray); // Output: ['1: one', '2: two', '3: three']
139
140
  */
140
141
  export declare class LimitedCollection<K, V> {
141
- static readonly default: LimitedCollectionOptions;
142
+ static readonly default: LimitedCollectionOptions<any, any>;
142
143
  private readonly data;
143
144
  private readonly options;
144
145
  private timeout;
145
- constructor(options?: Partial<LimitedCollectionOptions>);
146
+ constructor(options?: Partial<LimitedCollectionOptions<K, V>>);
146
147
  /**
147
148
  * Adds an element to the limited collection.
148
149
  * @param key The key of the element.
@@ -228,6 +229,10 @@ export declare class LimitedCollection<K, V> {
228
229
  private resetTimeout;
229
230
  private stopTimeout;
230
231
  private startTimeout;
232
+ keys(): () => IterableIterator<K>;
233
+ values(): () => IterableIterator<LimitedCollectionData<V>>;
234
+ entries(): IterableIterator<[K, LimitedCollectionData<V>]>;
235
+ clear(): void;
231
236
  private clearExpired;
232
237
  }
233
238
  export {};
package/lib/collection.js CHANGED
@@ -230,7 +230,8 @@ class LimitedCollection {
230
230
  if (this.size > this.options.limit) {
231
231
  const iter = this.data.keys();
232
232
  while (this.size > this.options.limit) {
233
- this.delete(iter.next().value);
233
+ const keyValue = iter.next().value;
234
+ this.delete(keyValue);
234
235
  }
235
236
  }
236
237
  if (this.closer?.expireOn === expireOn) {
@@ -265,7 +266,7 @@ class LimitedCollection {
265
266
  if (this.options.resetOnDemand && data && data.expire !== -1) {
266
267
  const oldExpireOn = data.expireOn;
267
268
  data.expireOn = Date.now() + data.expire;
268
- if (this.closer.expireOn === oldExpireOn) {
269
+ if (this.closer?.expireOn === oldExpireOn) {
269
270
  this.resetTimeout();
270
271
  }
271
272
  }
@@ -296,8 +297,11 @@ class LimitedCollection {
296
297
  */
297
298
  delete(key) {
298
299
  const value = this.raw(key);
299
- if (value && value.expireOn === this.closer.expireOn)
300
- setImmediate(() => this.resetTimeout());
300
+ if (value) {
301
+ if (value.expireOn === this.closer?.expireOn)
302
+ setImmediate(() => this.resetTimeout());
303
+ this.options.onDelete?.(key, value.value);
304
+ }
301
305
  return this.data.delete(key);
302
306
  }
303
307
  /**
@@ -360,12 +364,26 @@ class LimitedCollection {
360
364
  this.resetTimeout();
361
365
  }, expireOn - Date.now());
362
366
  }
367
+ keys() {
368
+ return this.data.keys;
369
+ }
370
+ values() {
371
+ return this.data.values;
372
+ }
373
+ entries() {
374
+ return this.data.entries();
375
+ }
376
+ clear() {
377
+ this.data.clear();
378
+ this.resetTimeout();
379
+ }
363
380
  clearExpired() {
364
381
  for (const [key, value] of this.data) {
365
382
  if (value.expireOn === -1) {
366
383
  continue;
367
384
  }
368
385
  if (Date.now() >= value.expireOn) {
386
+ this.options.onDelete?.(key, value.value);
369
387
  this.data.delete(key);
370
388
  }
371
389
  }
@@ -99,14 +99,14 @@ declare class BaseCommand {
99
99
  integration_types: BaseCommand['integrationTypes'];
100
100
  };
101
101
  reload(): Promise<void>;
102
- run?(context: CommandContext<any>): any;
103
- onAfterRun?(context: CommandContext<any>, error: unknown | undefined): any;
104
- onRunError?(context: CommandContext<any>, error: unknown): any;
105
- onOptionsError?(context: CommandContext<{}, never>, metadata: OnOptionsReturnObject): any;
106
- onMiddlewaresError?(context: CommandContext<{}, never>, error: string): any;
107
- onBotPermissionsFail?(context: CommandContext<{}, never>, permissions: PermissionStrings): any;
108
- onPermissionsFail?(context: CommandContext<{}, never>, permissions: PermissionStrings): any;
109
- onInternalError?(client: UsingClient, error?: unknown): any;
102
+ run?(context: CommandContext): any;
103
+ onAfterRun?(context: CommandContext, error: unknown | undefined): any;
104
+ onRunError?(context: CommandContext, error: unknown): any;
105
+ onOptionsError?(context: CommandContext, metadata: OnOptionsReturnObject): any;
106
+ onMiddlewaresError?(context: CommandContext, error: string): any;
107
+ onBotPermissionsFail?(context: CommandContext, permissions: PermissionStrings): any;
108
+ onPermissionsFail?(context: CommandContext, permissions: PermissionStrings): any;
109
+ onInternalError?(client: UsingClient, command: Command | SubCommand, error?: unknown): any;
110
110
  }
111
111
  export declare class Command extends BaseCommand {
112
112
  type: ApplicationCommandType;
@@ -130,12 +130,6 @@ export declare class Command extends BaseCommand {
130
130
  contexts: InteractionContextTypes[] | undefined;
131
131
  integration_types: IntegrationTypes[] | undefined;
132
132
  };
133
- onRunError(context: CommandContext<any>, error: unknown): any;
134
- onOptionsError(context: CommandContext<{}, never>, metadata: OnOptionsReturnObject): any;
135
- onMiddlewaresError(context: CommandContext<{}, never>, error: string): any;
136
- onBotPermissionsFail(context: CommandContext<{}, never>, permissions: PermissionStrings): any;
137
- onPermissionsFail(context: CommandContext<{}, never>, permissions: PermissionStrings): any;
138
- onInternalError(client: UsingClient, error?: unknown): any;
139
133
  }
140
134
  export declare abstract class SubCommand extends BaseCommand {
141
135
  type: ApplicationCommandOptionType;
@@ -128,13 +128,13 @@ class BaseCommand {
128
128
  }
129
129
  async reload() {
130
130
  delete require.cache[this.__filePath];
131
- const __tempCommand = await (0, common_1.magicImport)(this.__filePath).then(x => x.default ?? x);
132
- Object.setPrototypeOf(this, __tempCommand.prototype);
133
131
  for (const i of this.options ?? []) {
134
132
  if (i instanceof SubCommand && i.__filePath) {
135
133
  await i.reload();
136
134
  }
137
135
  }
136
+ const __tempCommand = await (0, common_1.magicImport)(this.__filePath).then(x => x.default ?? x);
137
+ Object.setPrototypeOf(this, __tempCommand.prototype);
138
138
  }
139
139
  }
140
140
  class Command extends BaseCommand {
@@ -171,24 +171,6 @@ class Command extends BaseCommand {
171
171
  options,
172
172
  };
173
173
  }
174
- onRunError(context, error) {
175
- context.client.logger.fatal(`${this.name}.<onRunError>`, context.author.id, error);
176
- }
177
- onOptionsError(context, metadata) {
178
- context.client.logger.fatal(`${this.name}.<onOptionsError>`, context.author.id, metadata);
179
- }
180
- onMiddlewaresError(context, error) {
181
- context.client.logger.fatal(`${this.name}.<onMiddlewaresError>`, context.author.id, error);
182
- }
183
- onBotPermissionsFail(context, permissions) {
184
- context.client.logger.fatal(`${this.name}.<onBotPermissionsFail>`, context.author.id, permissions);
185
- }
186
- onPermissionsFail(context, permissions) {
187
- context.client.logger.fatal(`${this.name}.<onPermissionsFail>`, context.author.id, permissions);
188
- }
189
- onInternalError(client, error) {
190
- client.logger.fatal(`${this.name}.<onInternalError>`, error);
191
- }
192
174
  }
193
175
  exports.Command = Command;
194
176
  class SubCommand extends BaseCommand {
@@ -28,7 +28,7 @@ export declare class CommandContext<T extends OptionsRecord = {}, M extends keyo
28
28
  get fullCommandName(): string;
29
29
  write<FR extends boolean = false>(body: InteractionCreateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessage | Message, void | WebhookMessage | Message>>;
30
30
  deferReply(ephemeral?: boolean): Promise<void | Message>;
31
- editResponse(body: InteractionMessageUpdateBodyRequest): Promise<Message>;
31
+ editResponse(body: InteractionMessageUpdateBodyRequest): Promise<Message | WebhookMessage>;
32
32
  deleteResponse(): Promise<void>;
33
33
  editOrReply<FR extends boolean = false>(body: InteractionCreateBodyRequest | InteractionMessageUpdateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessage | Message, void | WebhookMessage | Message>>;
34
34
  fetchResponse(): Promise<If<InferWithPrefix, WebhookMessage | Message | undefined, WebhookMessage | undefined>>;
@@ -23,7 +23,7 @@ export declare class MenuCommandContext<T extends MessageCommandInteraction | Us
23
23
  write<FR extends boolean = false>(body: InteractionCreateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessage, void | WebhookMessage>>;
24
24
  modal(body: ModalCreateBodyRequest): Promise<void>;
25
25
  deferReply(ephemeral?: boolean): Promise<void>;
26
- editResponse(body: InteractionMessageUpdateBodyRequest): Promise<Message>;
26
+ editResponse(body: InteractionMessageUpdateBodyRequest): Promise<WebhookMessage>;
27
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>;
@@ -1,14 +1,8 @@
1
1
  import type { Logger } from '../common';
2
2
  import { BaseHandler } from '../common';
3
- import { Command } from './applications/chat';
3
+ import { Command, SubCommand } 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
- }
12
6
  export declare class CommandHandler extends BaseHandler {
13
7
  protected logger: Logger;
14
8
  protected client: UsingClient;
@@ -19,4 +13,14 @@ export declare class CommandHandler extends BaseHandler {
19
13
  reloadAll(stopIfFail?: boolean): Promise<void>;
20
14
  load(commandsDir: string, client: UsingClient): Promise<(Command | ContextMenuCommand)[]>;
21
15
  private __parseCommandLocales;
16
+ setHandlers({ onCommand, onSubCommand, }: {
17
+ onCommand?: CommandHandler['onCommand'];
18
+ onSubCommand?: CommandHandler['onSubCommand'];
19
+ }): void;
20
+ onCommand: (file: {
21
+ new (): Command | SubCommand | ContextMenuCommand;
22
+ }) => Command | SubCommand | ContextMenuCommand | false;
23
+ onSubCommand: (file: {
24
+ new (): SubCommand;
25
+ }) => SubCommand | false;
22
26
  }
@@ -40,8 +40,9 @@ class CommandHandler extends common_1.BaseHandler {
40
40
  for (const command of result) {
41
41
  let commandInstance;
42
42
  try {
43
- //@ts-expect-error abstract class
44
- commandInstance = new command.file();
43
+ commandInstance = this.onCommand(command.file);
44
+ if (!commandInstance)
45
+ continue;
45
46
  }
46
47
  catch (e) {
47
48
  if (e instanceof Error && e.message === 'command.file is not a constructor') {
@@ -57,12 +58,18 @@ class CommandHandler extends common_1.BaseHandler {
57
58
  if (commandInstance instanceof menu_1.ContextMenuCommand) {
58
59
  this.values.push(commandInstance);
59
60
  commandInstance.__filePath = command.path;
60
- await this.__callback?.(commandInstance);
61
61
  continue;
62
62
  }
63
63
  if (!(commandInstance instanceof chat_1.Command)) {
64
64
  continue;
65
65
  }
66
+ commandInstance.onAfterRun ??= client.options?.commands?.defaults?.onAfterRun;
67
+ commandInstance.onBotPermissionsFail ??= client.options?.commands?.defaults?.onBotPermissionsFail;
68
+ commandInstance.onInternalError ??= client.options?.commands?.defaults?.onInternalError;
69
+ commandInstance.onMiddlewaresError ??= client.options?.commands?.defaults?.onMiddlewaresError;
70
+ commandInstance.onOptionsError ??= client.options?.commands?.defaults?.onOptionsError;
71
+ commandInstance.onPermissionsFail ??= client.options?.commands?.defaults?.onPermissionsFail;
72
+ commandInstance.onRunError ??= client.options?.commands?.defaults?.onRunError;
66
73
  commandInstance.__filePath = command.path;
67
74
  commandInstance.options ??= [];
68
75
  if (commandInstance.__autoload) {
@@ -73,9 +80,8 @@ class CommandHandler extends common_1.BaseHandler {
73
80
  continue;
74
81
  }
75
82
  try {
76
- //@ts-expect-error abstract class
77
- const subCommand = new (result.find(x => x.path === option).file)();
78
- if (subCommand instanceof chat_1.SubCommand) {
83
+ const subCommand = this.onSubCommand(result.find(x => x.path === option).file);
84
+ if (subCommand && subCommand instanceof chat_1.SubCommand) {
79
85
  subCommand.__filePath = option;
80
86
  commandInstance.options.push(subCommand);
81
87
  }
@@ -89,17 +95,33 @@ class CommandHandler extends common_1.BaseHandler {
89
95
  if (option instanceof chat_1.SubCommand) {
90
96
  option.middlewares = (commandInstance.middlewares ?? []).concat(option.middlewares ?? []);
91
97
  option.onMiddlewaresError =
92
- option.onMiddlewaresError?.bind(option) ?? commandInstance.onMiddlewaresError?.bind(commandInstance);
93
- option.onRunError = option.onRunError?.bind(option) ?? commandInstance.onRunError?.bind(commandInstance);
98
+ option.onMiddlewaresError?.bind(option) ??
99
+ commandInstance.onMiddlewaresError?.bind(commandInstance) ??
100
+ this.client.options?.commands?.defaults?.onMiddlewaresError;
101
+ option.onRunError =
102
+ option.onRunError?.bind(option) ??
103
+ commandInstance.onRunError?.bind(commandInstance) ??
104
+ this.client.options?.commands?.defaults?.onRunError;
94
105
  option.onOptionsError =
95
- option.onOptionsError?.bind(option) ?? commandInstance.onOptionsError?.bind(commandInstance);
106
+ option.onOptionsError?.bind(option) ??
107
+ commandInstance.onOptionsError?.bind(commandInstance) ??
108
+ this.client.options?.commands?.defaults?.onOptionsError;
96
109
  option.onInternalError =
97
- option.onInternalError?.bind(option) ?? commandInstance.onInternalError?.bind(commandInstance);
98
- option.onAfterRun = option.onAfterRun?.bind(option) ?? commandInstance.onAfterRun?.bind(commandInstance);
110
+ option.onInternalError?.bind(option) ??
111
+ commandInstance.onInternalError?.bind(commandInstance) ??
112
+ this.client.options?.commands?.defaults?.onInternalError;
113
+ option.onAfterRun =
114
+ option.onAfterRun?.bind(option) ??
115
+ commandInstance.onAfterRun?.bind(commandInstance) ??
116
+ this.client.options?.commands?.defaults?.onAfterRun;
99
117
  option.onBotPermissionsFail =
100
- option.onBotPermissionsFail?.bind(option) ?? commandInstance.onBotPermissionsFail?.bind(commandInstance);
118
+ option.onBotPermissionsFail?.bind(option) ??
119
+ commandInstance.onBotPermissionsFail?.bind(commandInstance) ??
120
+ this.client.options?.commands?.defaults?.onBotPermissionsFail;
101
121
  option.onPermissionsFail =
102
- option.onPermissionsFail?.bind(option) ?? commandInstance.onPermissionsFail?.bind(commandInstance);
122
+ option.onPermissionsFail?.bind(option) ??
123
+ commandInstance.onPermissionsFail?.bind(commandInstance) ??
124
+ this.client.options?.commands?.defaults?.onPermissionsFail;
103
125
  }
104
126
  }
105
127
  this.values.push(commandInstance);
@@ -109,7 +131,6 @@ class CommandHandler extends common_1.BaseHandler {
109
131
  this.__parseCommandLocales(i, client);
110
132
  }
111
133
  }
112
- await this.__callback?.(commandInstance);
113
134
  }
114
135
  return this.values;
115
136
  }
@@ -194,5 +215,13 @@ class CommandHandler extends common_1.BaseHandler {
194
215
  }
195
216
  }
196
217
  }
218
+ setHandlers({ onCommand, onSubCommand, }) {
219
+ if (onCommand)
220
+ this.onCommand = onCommand;
221
+ if (onSubCommand)
222
+ this.onSubCommand = onSubCommand;
223
+ }
224
+ onCommand = (file) => new file();
225
+ onSubCommand = (file) => new file();
197
226
  }
198
227
  exports.CommandHandler = CommandHandler;
@@ -11,7 +11,9 @@ export * from './shorters/reactions';
11
11
  export * from './shorters/roles';
12
12
  export * from './shorters/templates';
13
13
  export * from './shorters/users';
14
+ export * from './shorters/threads';
14
15
  export * from './shorters/webhook';
16
+ export * from './shorters/interaction';
15
17
  export * from './types/options';
16
18
  export * from './types/resolvables';
17
19
  export * from './types/util';
@@ -28,7 +28,9 @@ __exportStar(require("./shorters/reactions"), exports);
28
28
  __exportStar(require("./shorters/roles"), exports);
29
29
  __exportStar(require("./shorters/templates"), exports);
30
30
  __exportStar(require("./shorters/users"), exports);
31
+ __exportStar(require("./shorters/threads"), exports);
31
32
  __exportStar(require("./shorters/webhook"), exports);
33
+ __exportStar(require("./shorters/interaction"), exports);
32
34
  __exportStar(require("./types/options"), exports);
33
35
  __exportStar(require("./types/resolvables"), exports);
34
36
  __exportStar(require("./types/util"), exports);
@@ -40,7 +40,6 @@ 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;
44
43
  /**
45
44
  * Initializes a new instance of the BaseHandler class.
46
45
  * @param logger The logger instance.
@@ -95,7 +95,6 @@ exports.filterSplit = filterSplit;
95
95
  */
96
96
  class BaseHandler {
97
97
  logger;
98
- __callback;
99
98
  /**
100
99
  * Initializes a new instance of the BaseHandler class.
101
100
  * @param logger The logger instance.
@@ -1,6 +1,6 @@
1
- import { type RESTPatchAPIChannelJSONBody, type RESTPostAPIChannelThreadsJSONBody, type RESTPostAPIGuildForumThreadsJSONBody } from 'discord-api-types/v10';
1
+ import { type RESTGetAPIChannelMessagesQuery, type RESTPatchAPIChannelJSONBody, type RESTPostAPIChannelThreadsJSONBody, type RESTPostAPIGuildForumThreadsJSONBody } from 'discord-api-types/v10';
2
2
  import { Message, type GuildMember, type GuildRole } from '../../structures';
3
- import { type AllChannels, type ThreadChannel } from '../../structures/channels';
3
+ import { type AllChannels } from '../../structures/channels';
4
4
  import { PermissionsBitField } from '../../structures/extra/Permissions';
5
5
  import { BaseShorter } from './base';
6
6
  export declare class ChannelShorter extends BaseShorter {
@@ -55,7 +55,7 @@ export declare class ChannelShorter extends BaseShorter {
55
55
  * @param reason The reason for unpinning the message.
56
56
  * @returns A promise that resolves when the thread is succesfully created.
57
57
  */
58
- thread(channelId: string, body: RESTPostAPIChannelThreadsJSONBody | RESTPostAPIGuildForumThreadsJSONBody, reason?: string): Promise<ThreadChannel>;
58
+ thread(channelId: string, body: RESTPostAPIChannelThreadsJSONBody | RESTPostAPIGuildForumThreadsJSONBody, reason?: string): Promise<import("../../structures").ThreadChannel>;
59
59
  memberPermissions(channelId: string, member: GuildMember, checkAdmin?: boolean): Promise<PermissionsBitField>;
60
60
  overwritesFor(channelId: string, member: GuildMember): Promise<{
61
61
  everyone: {
@@ -81,6 +81,8 @@ export declare class ChannelShorter extends BaseShorter {
81
81
  } | undefined;
82
82
  }>;
83
83
  rolePermissions(channelId: string, role: GuildRole, checkAdmin?: boolean): Promise<PermissionsBitField>;
84
+ fetchMessages(channelId: string, query?: RESTGetAPIChannelMessagesQuery): Promise<Message[]>;
85
+ setVoiceStatus(channelId: string, status?: string | null): Promise<never>;
84
86
  }
85
87
  export type ChannelShorterOptionalParams = Partial<{
86
88
  guildId: string;
@@ -9,6 +9,7 @@ const structures_1 = require("../../structures");
9
9
  const channels_1 = __importDefault(require("../../structures/channels"));
10
10
  const Permissions_1 = require("../../structures/extra/Permissions");
11
11
  const base_1 = require("./base");
12
+ const utils_1 = require("../it/utils");
12
13
  class ChannelShorter extends base_1.BaseShorter {
13
14
  /**
14
15
  * Fetches a channel by its ID.
@@ -34,8 +35,9 @@ class ChannelShorter extends base_1.BaseShorter {
34
35
  * @returns A Promise that resolves to the deleted channel.
35
36
  */
36
37
  async delete(id, optional = { guildId: '@me' }) {
37
- const res = await this.client.proxy.channels(id).delete({ reason: optional.reason });
38
- await this.client.cache.channels?.removeIfNI(structures_1.BaseChannel.__intent__(optional.guildId), res.id, optional.guildId);
38
+ const options = (0, utils_1.MergeOptions)({ guildId: '@me' }, optional);
39
+ const res = await this.client.proxy.channels(id).delete({ reason: options.reason });
40
+ await this.client.cache.channels?.removeIfNI(structures_1.BaseChannel.__intent__(options.guildId), res.id, options.guildId);
39
41
  return (0, channels_1.default)(res, this.client);
40
42
  }
41
43
  /**
@@ -46,10 +48,11 @@ class ChannelShorter extends base_1.BaseShorter {
46
48
  * @returns A Promise that resolves to the edited channel.
47
49
  */
48
50
  async edit(id, body, optional = { guildId: '@me' }) {
49
- const res = await this.client.proxy.channels(id).patch({ body, reason: optional.reason });
50
- await this.client.cache.channels?.setIfNI(structures_1.BaseChannel.__intent__(optional.guildId), res.id, optional.guildId, res);
51
+ const options = (0, utils_1.MergeOptions)({ guildId: '@me' }, optional);
52
+ const res = await this.client.proxy.channels(id).patch({ body, reason: options.reason });
53
+ await this.client.cache.channels?.setIfNI(structures_1.BaseChannel.__intent__(options.guildId), res.id, options.guildId, res);
51
54
  if (body.permission_overwrites && 'permission_overwrites' in res)
52
- await this.client.cache.overwrites?.setIfNI(structures_1.BaseChannel.__intent__(optional.guildId), res.id, optional.guildId, res.permission_overwrites);
55
+ await this.client.cache.overwrites?.setIfNI(structures_1.BaseChannel.__intent__(options.guildId), res.id, options.guildId, res.permission_overwrites);
53
56
  return (0, channels_1.default)(res, this.client);
54
57
  }
55
58
  /**
@@ -62,6 +65,9 @@ class ChannelShorter extends base_1.BaseShorter {
62
65
  }
63
66
  async pins(channelId) {
64
67
  const messages = await this.client.proxy.channels(channelId).pins.get();
68
+ await this.client.cache.messages?.patch(messages.map(x => {
69
+ return [x.id, x];
70
+ }), channelId);
65
71
  return messages.map(message => new structures_1.Message(this.client, message));
66
72
  }
67
73
  /**
@@ -91,11 +97,7 @@ class ChannelShorter extends base_1.BaseShorter {
91
97
  * @returns A promise that resolves when the thread is succesfully created.
92
98
  */
93
99
  async thread(channelId, body, reason) {
94
- return (this.client.proxy
95
- .channels(channelId)
96
- .threads.post({ body, reason })
97
- // When testing this, discord returns the thread object, but in discord api types it does not.
98
- .then(thread => (0, channels_1.default)(thread, this.client)));
100
+ return this.client.threads.create(channelId, body, reason);
99
101
  }
100
102
  async memberPermissions(channelId, member, checkAdmin = true) {
101
103
  const memberPermissions = await member.fetchPermissions();
@@ -148,5 +150,17 @@ class ChannelShorter extends base_1.BaseShorter {
148
150
  permissions.add(roleOverwrites?.allow.bits ?? 0n);
149
151
  return permissions;
150
152
  }
153
+ async fetchMessages(channelId, query) {
154
+ const result = await this.client.proxy.channels(channelId).messages.get({
155
+ query,
156
+ });
157
+ await this.client.cache.messages?.patch(result.map(x => {
158
+ return [x.id, x];
159
+ }), channelId);
160
+ return result.map(message => new structures_1.Message(this.client, message));
161
+ }
162
+ setVoiceStatus(channelId, status = null) {
163
+ return this.client.proxy.channels(channelId)['voice-status'].put({ body: { status } });
164
+ }
151
165
  }
152
166
  exports.ChannelShorter = ChannelShorter;