seyfert 2.1.1-dev-12247418720.0 → 2.1.1-dev-12309212345.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.
Files changed (42) hide show
  1. package/lib/cache/index.d.ts +1 -1
  2. package/lib/cache/index.js +6 -4
  3. package/lib/client/base.d.ts +3 -4
  4. package/lib/client/base.js +6 -9
  5. package/lib/client/client.d.ts +1 -2
  6. package/lib/client/client.js +17 -36
  7. package/lib/client/workerclient.d.ts +1 -4
  8. package/lib/client/workerclient.js +32 -81
  9. package/lib/commands/applications/chatcontext.js +1 -1
  10. package/lib/commands/applications/entrycontext.d.ts +1 -1
  11. package/lib/commands/applications/menucontext.d.ts +1 -1
  12. package/lib/commands/handle.js +5 -5
  13. package/lib/common/it/utils.d.ts +1 -0
  14. package/lib/common/it/utils.js +6 -0
  15. package/lib/common/shorters/bans.js +2 -2
  16. package/lib/common/shorters/guilds.d.ts +2 -2
  17. package/lib/common/shorters/interaction.d.ts +2 -2
  18. package/lib/common/shorters/interaction.js +1 -1
  19. package/lib/common/shorters/members.js +1 -1
  20. package/lib/common/shorters/messages.d.ts +1 -1
  21. package/lib/common/shorters/messages.js +7 -2
  22. package/lib/components/componentcontext.d.ts +1 -1
  23. package/lib/components/modalcontext.d.ts +1 -1
  24. package/lib/components/modalcontext.js +1 -1
  25. package/lib/events/handler.js +5 -5
  26. package/lib/events/hooks/custom.d.ts +5 -1
  27. package/lib/events/hooks/custom.js +14 -1
  28. package/lib/structures/Guild.d.ts +1 -2
  29. package/lib/structures/Interaction.d.ts +2 -2
  30. package/lib/structures/Interaction.js +1 -1
  31. package/lib/structures/Message.d.ts +1 -1
  32. package/lib/structures/Message.js +2 -2
  33. package/lib/structures/channels.d.ts +3 -3
  34. package/lib/structures/channels.js +1 -1
  35. package/lib/types/gateway.d.ts +12 -1
  36. package/lib/types/utils/index.d.ts +6 -5
  37. package/lib/types/utils/index.js +5 -4
  38. package/lib/websocket/discord/shard.d.ts +7 -5
  39. package/lib/websocket/discord/shard.js +60 -30
  40. package/lib/websocket/discord/sharder.d.ts +1 -1
  41. package/lib/websocket/discord/workermanager.js +3 -3
  42. package/package.json +1 -1
@@ -7,7 +7,7 @@ export declare class MessageShorter extends BaseShorter {
7
7
  edit(messageId: string, channelId: string, { files, ...body }: MessageUpdateBodyRequest): Promise<import("../../structures").Message>;
8
8
  crosspost(messageId: string, channelId: string, reason?: string): Promise<import("../../structures").Message>;
9
9
  delete(messageId: string, channelId: string, reason?: string): Promise<void>;
10
- fetch(messageId: string, channelId: string): Promise<import("../../structures").Message>;
10
+ fetch(messageId: string, channelId: string, force?: boolean): Promise<import("../../structures").Message>;
11
11
  purge(messages: string[], channelId: string, reason?: string): Promise<void | undefined>;
12
12
  thread(channelId: string, messageId: string, options: RESTPostAPIChannelMessagesThreadsJSONBody & {
13
13
  reason?: string;
@@ -51,10 +51,15 @@ class MessageShorter extends base_1.BaseShorter {
51
51
  .delete({ reason })
52
52
  .then(async () => {
53
53
  await this.client.cache.messages?.removeIfNI('GuildMessages', messageId, channelId);
54
- this.client.components?.deleteValue(messageId, 'messageDelete');
54
+ this.client.components.deleteValue(messageId, 'messageDelete');
55
55
  });
56
56
  }
57
- fetch(messageId, channelId) {
57
+ async fetch(messageId, channelId, force = false) {
58
+ if (!force) {
59
+ const message = await this.client.cache.messages?.get(messageId);
60
+ if (message)
61
+ return message;
62
+ }
58
63
  return this.client.proxy
59
64
  .channels(channelId)
60
65
  .messages(messageId)
@@ -70,7 +70,7 @@ export declare class ComponentContext<Type extends keyof ContextComponentCommand
70
70
  * Deletes the response of the interaction.
71
71
  * @returns A promise that resolves when the response is deleted.
72
72
  */
73
- deleteResponse(): Promise<void | undefined>;
73
+ deleteResponse(): Promise<void>;
74
74
  modal(body: ModalCreateBodyRequest): Promise<undefined>;
75
75
  /**
76
76
  * Gets the channel of the interaction.
@@ -67,7 +67,7 @@ export declare class ModalContext<M extends keyof RegisteredMiddlewares = never>
67
67
  * Deletes the response of the interaction.
68
68
  * @returns A promise that resolves when the response is deleted.
69
69
  */
70
- deleteResponse(): Promise<void | undefined>;
70
+ deleteResponse(): Promise<void>;
71
71
  modal(body: ModalCreateBodyRequest): ReturnType<Interaction['modal']>;
72
72
  /**
73
73
  * Gets the channel of the interaction.
@@ -33,7 +33,7 @@ class ModalContext extends basecontext_1.BaseContext {
33
33
  * Gets the language object for the interaction's locale.
34
34
  */
35
35
  get t() {
36
- return this.client.t(this.interaction?.locale ?? this.client.langs?.defaultLang ?? 'en-US');
36
+ return this.client.t(this.interaction?.locale ?? this.client.langs.defaultLang ?? 'en-US');
37
37
  }
38
38
  /**
39
39
  * Writes a response to the interaction.
@@ -85,7 +85,7 @@ class EventHandler extends common_1.BaseHandler {
85
85
  switch (raw.t) {
86
86
  case 'MESSAGE_DELETE':
87
87
  {
88
- if (!client.components?.values.size)
88
+ if (!client.components.values.size)
89
89
  break;
90
90
  const value = client.components.values.get(raw.d.id);
91
91
  if (value) {
@@ -95,7 +95,7 @@ class EventHandler extends common_1.BaseHandler {
95
95
  break;
96
96
  case 'MESSAGE_DELETE_BULK':
97
97
  {
98
- if (!client.components?.values.size)
98
+ if (!client.components.values.size)
99
99
  break;
100
100
  for (const id of raw.d.ids) {
101
101
  const value = client.components.values.get(id);
@@ -107,7 +107,7 @@ class EventHandler extends common_1.BaseHandler {
107
107
  break;
108
108
  case 'GUILD_DELETE':
109
109
  {
110
- if (!client.components?.values.size)
110
+ if (!client.components.values.size)
111
111
  break;
112
112
  // ignore unavailable guilds?
113
113
  if (raw.d.unavailable)
@@ -120,7 +120,7 @@ class EventHandler extends common_1.BaseHandler {
120
120
  break;
121
121
  case 'CHANNEL_DELETE':
122
122
  {
123
- if (!client.components?.values.size)
123
+ if (!client.components.values.size)
124
124
  break;
125
125
  if (raw.d.type === types_1.ChannelType.DM || raw.d.type === types_1.ChannelType.GroupDM) {
126
126
  for (const value of client.components.values) {
@@ -147,7 +147,7 @@ class EventHandler extends common_1.BaseHandler {
147
147
  break;
148
148
  case 'THREAD_DELETE':
149
149
  {
150
- if (!client.components?.values.size)
150
+ if (!client.components.values.size)
151
151
  break;
152
152
  for (const value of client.components.values) {
153
153
  if (value[1].channelId === raw.d.id) {
@@ -1,5 +1,9 @@
1
- import type { ClientUserStructure } from '../../client/transformers';
1
+ import { type ClientUserStructure } from '../../client/transformers';
2
2
  import type { UsingClient } from '../../commands';
3
+ import type { GatewayRawGuildCreateDispatch, GatewayRawGuildDeleteDispatch } from '../../types';
3
4
  export declare const BOT_READY: (_self: UsingClient, me: ClientUserStructure) => import("../..").ClientUser;
4
5
  export declare const WORKER_READY: (_self: UsingClient, me: ClientUserStructure) => import("../..").ClientUser;
5
6
  export declare const WORKER_SHARDS_CONNECTED: (_self: UsingClient, me: ClientUserStructure) => import("../..").ClientUser;
7
+ export declare const RAW_GUILD_CREATE: (self: UsingClient, data: GatewayRawGuildCreateDispatch["d"]) => import("../..").Guild<"create">;
8
+ export declare const RAW_GUILD_DELETE: (self: UsingClient, data: GatewayRawGuildDeleteDispatch["d"]) => Promise<import("../../types").APIUnavailableGuild | import("../..").Guild<"cached">>;
9
+ export declare const GUILDS_READY: () => void;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WORKER_SHARDS_CONNECTED = exports.WORKER_READY = exports.BOT_READY = void 0;
3
+ exports.GUILDS_READY = exports.RAW_GUILD_DELETE = exports.RAW_GUILD_CREATE = exports.WORKER_SHARDS_CONNECTED = exports.WORKER_READY = exports.BOT_READY = void 0;
4
+ const transformers_1 = require("../../client/transformers");
4
5
  const BOT_READY = (_self, me) => {
5
6
  return me;
6
7
  };
@@ -13,3 +14,15 @@ const WORKER_SHARDS_CONNECTED = (_self, me) => {
13
14
  return me;
14
15
  };
15
16
  exports.WORKER_SHARDS_CONNECTED = WORKER_SHARDS_CONNECTED;
17
+ const RAW_GUILD_CREATE = (self, data) => {
18
+ return transformers_1.Transformers.Guild(self, data);
19
+ };
20
+ exports.RAW_GUILD_CREATE = RAW_GUILD_CREATE;
21
+ const RAW_GUILD_DELETE = async (self, data) => {
22
+ return (await self.cache.guilds?.get(data.id)) ?? data;
23
+ };
24
+ exports.RAW_GUILD_DELETE = RAW_GUILD_DELETE;
25
+ const GUILDS_READY = () => {
26
+ return;
27
+ };
28
+ exports.GUILDS_READY = GUILDS_READY;
@@ -8,7 +8,6 @@ import { GuildMember } from './GuildMember';
8
8
  import { GuildRole } from './GuildRole';
9
9
  import { GuildTemplate } from './GuildTemplate';
10
10
  import { Sticker } from './Sticker';
11
- import { BaseChannel } from './channels';
12
11
  import { BaseGuild } from './extra/BaseGuild';
13
12
  import type { DiscordBase } from './extra/DiscordBase';
14
13
  export interface Guild extends ObjectToLower<Omit<APIGuild, 'stickers' | 'emojis' | 'roles'>>, DiscordBase {
@@ -70,7 +69,7 @@ export declare class Guild<State extends StructStates = 'api'> extends Guild_bas
70
69
  };
71
70
  channels: {
72
71
  list: (force?: boolean) => Promise<import("./channels").AllChannels[]>;
73
- fetch: (id: string, force?: boolean) => Promise<import("../types").APIGuildCategoryChannel | import("../types").APIGuildStageVoiceChannel | import("../types").APIGuildVoiceChannel | import("../types").APINewsChannel | import("../types").APITextChannel | BaseChannel<import("../types").ChannelType> | import("./channels").DMChannel | import("./channels").CategoryChannel>;
72
+ fetch: (id: string, force?: boolean) => Promise<import("./channels").AllChannels>;
74
73
  create: (body: import("../types").RESTPostAPIGuildChannelJSONBody) => Promise<import("./channels").AllChannels>;
75
74
  delete: (id: string, reason?: string) => Promise<import("./channels").AllChannels>;
76
75
  edit: (id: string, body: import("../types").RESTPatchAPIChannelJSONBody, reason?: string) => Promise<import("./channels").AllChannels>;
@@ -76,8 +76,8 @@ export declare class Interaction<FromGuild extends boolean = boolean, Type exten
76
76
  editOrReply<FR extends boolean = false>(body: InteractionCreateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessageStructure, void>>;
77
77
  editMessage(messageId: string, body: InteractionMessageUpdateBodyRequest): Promise<import("./Message").WebhookMessage>;
78
78
  editResponse(body: InteractionMessageUpdateBodyRequest): Promise<import("./Message").WebhookMessage>;
79
- deleteResponse(): Promise<void | undefined>;
80
- deleteMessage(messageId: string): Promise<void | undefined>;
79
+ deleteResponse(): Promise<void>;
80
+ deleteMessage(messageId: string): Promise<void>;
81
81
  followup(body: MessageWebhookCreateBodyRequest): Promise<import("./Message").WebhookMessage>;
82
82
  }
83
83
  export declare class ApplicationCommandInteraction<FromGuild extends boolean = boolean, Type extends APIApplicationCommandInteraction = APIApplicationCommandInteraction> extends Interaction<FromGuild, Type> {
@@ -129,7 +129,7 @@ class BaseInteraction extends DiscordBase_1.DiscordBase {
129
129
  // @ts-expect-error
130
130
  if (body.data.__exec)
131
131
  this.client.components.modals.set(this.user.id, body.data.__exec);
132
- else if (this.client.components?.modals.has(this.user.id))
132
+ else if (this.client.components.modals.has(this.user.id))
133
133
  this.client.components.modals.delete(this.user.id);
134
134
  }
135
135
  return result;
@@ -39,7 +39,7 @@ export interface Message extends BaseMessage, ObjectToLower<Omit<MessageData, 't
39
39
  }
40
40
  export declare class Message extends BaseMessage {
41
41
  constructor(client: UsingClient, data: MessageData);
42
- fetch(): Promise<Message>;
42
+ fetch(force?: boolean): Promise<Message>;
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>;
@@ -68,8 +68,8 @@ class Message extends BaseMessage {
68
68
  constructor(client, data) {
69
69
  super(client, data);
70
70
  }
71
- fetch() {
72
- return this.client.messages.fetch(this.id, this.channelId);
71
+ fetch(force = false) {
72
+ return this.client.messages.fetch(this.id, this.channelId, force);
73
73
  }
74
74
  reply(body, fail = true) {
75
75
  return this.write({
@@ -35,7 +35,7 @@ export declare class BaseNoEditableChannel<T extends ChannelType> extends Discor
35
35
  guildId: string;
36
36
  }>): {
37
37
  list: (force?: boolean) => Promise<AllChannels[]>;
38
- fetch: (id: string, force?: boolean) => Promise<APIGuildCategoryChannel | APIGuildStageVoiceChannel | APIGuildVoiceChannel | APINewsChannel | APITextChannel | BaseChannel<ChannelType> | DMChannel | CategoryChannel>;
38
+ fetch: (id: string, force?: boolean) => Promise<AllChannels>;
39
39
  create: (body: RESTPostAPIGuildChannelJSONBody) => Promise<AllChannels>;
40
40
  delete: (id: string, reason?: string) => Promise<AllChannels>;
41
41
  edit: (id: string, body: RESTPatchAPIChannelJSONBody, reason?: string) => Promise<AllChannels>;
@@ -109,7 +109,7 @@ export declare class MessagesMethods extends DiscordBase {
109
109
  edit: (messageId: string, body: MessageUpdateBodyRequest) => Promise<import("./Message").Message>;
110
110
  crosspost: (messageId: string, reason?: string) => Promise<import("./Message").Message>;
111
111
  delete: (messageId: string, reason?: string) => Promise<void>;
112
- fetch: (messageId: string) => Promise<import("./Message").Message>;
112
+ fetch: (messageId: string, force?: boolean) => Promise<import("./Message").Message>;
113
113
  purge: (messages: string[], reason?: string) => Promise<void | undefined>;
114
114
  list: (fetchOptions: RESTGetAPIChannelMessagesQuery) => Promise<import("./Message").Message[]>;
115
115
  };
@@ -131,7 +131,7 @@ export declare class MessagesMethods extends DiscordBase {
131
131
  edit: (messageId: string, body: MessageUpdateBodyRequest) => Promise<import("./Message").Message>;
132
132
  crosspost: (messageId: string, reason?: string) => Promise<import("./Message").Message>;
133
133
  delete: (messageId: string, reason?: string) => Promise<void>;
134
- fetch: (messageId: string) => Promise<import("./Message").Message>;
134
+ fetch: (messageId: string, force?: boolean) => Promise<import("./Message").Message>;
135
135
  purge: (messages: string[], reason?: string) => Promise<void | undefined>;
136
136
  list: (fetchOptions: RESTGetAPIChannelMessagesQuery) => Promise<import("./Message").Message[]>;
137
137
  };
@@ -164,7 +164,7 @@ class MessagesMethods extends DiscordBase_1.DiscordBase {
164
164
  edit: (messageId, body) => ctx.client.messages.edit(messageId, ctx.channelId, body),
165
165
  crosspost: (messageId, reason) => ctx.client.messages.crosspost(messageId, ctx.channelId, reason),
166
166
  delete: (messageId, reason) => ctx.client.messages.delete(messageId, ctx.channelId, reason),
167
- fetch: (messageId) => ctx.client.messages.fetch(messageId, ctx.channelId),
167
+ fetch: (messageId, force = false) => ctx.client.messages.fetch(messageId, ctx.channelId, force),
168
168
  purge: (messages, reason) => ctx.client.messages.purge(messages, ctx.channelId, reason),
169
169
  list: (fetchOptions) => ctx.client.messages.list(ctx.channelId, fetchOptions),
170
170
  };
@@ -1,3 +1,4 @@
1
+ import type { OmitInsert } from '../common';
1
2
  import type { ChannelType, GatewayDispatchEvents, GatewayOpcodes, Snowflake } from './index';
2
3
  import type { GatewayPresenceUpdate } from './payloads/gateway';
3
4
  import type { APIApplication, APIApplicationCommandPermission, APIAuditLogEntry, APIAutoModerationAction, APIAutoModerationRule, APIChannel, APIEmoji, APIEntitlement, APIGuild, APIGuildIntegration, APIGuildMember, APIGuildScheduledEvent, APIInteraction, APIMessage, APIPartialEmoji, APIRole, APIStageInstance, APISticker, APISubscription, APIThreadChannel, APIThreadMember, APIUnavailableGuild, APIUser, APIVoiceState, AutoModerationRuleTriggerType, GatewayActivity, InviteTargetType, PresenceUpdateStatus, GatewayPresenceUpdate as RawGatewayPresenceUpdate, GatewayThreadListSync as RawGatewayThreadListSync, GatewayThreadMembersUpdate as RawGatewayThreadMembersUpdate } from './payloads/index';
@@ -17,7 +18,7 @@ export interface GatewayURLQuery {
17
18
  */
18
19
  export type GatewaySendPayload = GatewayHeartbeat | GatewayIdentify | GatewayRequestGuildMembers | GatewayResume | GatewayUpdatePresence | GatewayVoiceStateUpdate | GatewayRequestSoundboardSounds;
19
20
  export type GatewayReceivePayload = GatewayDispatchPayload | GatewayHeartbeatAck | GatewayHeartbeatRequest | GatewayHello | GatewayInvalidSession | GatewayReconnect;
20
- export type GatewayDispatchPayload = GatewayApplicationCommandPermissionsUpdateDispatch | GatewayAutoModerationActionExecutionDispatch | GatewayAutoModerationRuleCreateDispatch | GatewayAutoModerationRuleDeleteDispatch | GatewayAutoModerationRuleModifyDispatch | GatewayChannelModifyDispatch | GatewayChannelPinsUpdateDispatch | GatewayEntitlementModifyDispatch | GatewayGuildAuditLogEntryCreateDispatch | GatewayGuildBanModifyDispatch | GatewayGuildCreateDispatch | GatewayGuildDeleteDispatch | GatewayGuildEmojisUpdateDispatch | GatewayGuildIntegrationsUpdateDispatch | GatewayGuildMemberAddDispatch | GatewayGuildMemberRemoveDispatch | GatewayGuildMembersChunkDispatch | GatewayGuildMemberUpdateDispatch | GatewayGuildModifyDispatch | GatewayGuildRoleDeleteDispatch | GatewayGuildRoleModifyDispatch | GatewayGuildScheduledEventCreateDispatch | GatewayGuildScheduledEventDeleteDispatch | GatewayGuildScheduledEventUpdateDispatch | GatewayGuildScheduledEventUserAddDispatch | GatewayGuildScheduledEventUserRemoveDispatch | GatewayGuildStickersUpdateDispatch | GatewayIntegrationCreateDispatch | GatewayIntegrationDeleteDispatch | GatewayIntegrationUpdateDispatch | GatewayInteractionCreateDispatch | GatewayInviteCreateDispatch | GatewayInviteDeleteDispatch | GatewayMessageCreateDispatch | GatewayMessageDeleteBulkDispatch | GatewayMessageDeleteDispatch | GatewayMessagePollVoteAddDispatch | GatewayMessagePollVoteRemoveDispatch | GatewayMessageReactionAddDispatch | GatewayMessageReactionRemoveAllDispatch | GatewayMessageReactionRemoveDispatch | GatewayMessageReactionRemoveEmojiDispatch | GatewayMessageUpdateDispatch | GatewayPresenceUpdateDispatch | GatewayReadyDispatch | GatewayResumedDispatch | GatewayStageInstanceCreateDispatch | GatewayStageInstanceDeleteDispatch | GatewayStageInstanceUpdateDispatch | GatewayThreadCreateDispatch | GatewayThreadDeleteDispatch | GatewayThreadListSyncDispatch | GatewayThreadMembersUpdateDispatch | GatewayThreadMemberUpdateDispatch | GatewayThreadUpdateDispatch | GatewayTypingStartDispatch | GatewayUserUpdateDispatch | GatewayVoiceServerUpdateDispatch | GatewayVoiceStateUpdateDispatch | GatewayWebhooksUpdateDispatch | GatewayGuildSoundboardSoundCreateDispatch | GatewayGuildSoundboardSoundDeleteDispatch | GatewayGuildSoundboardSoundUpdateDispatch | GatewayGuildSoundboardSoundsUpdateDispatch | GatewaySoundboardSoundsDispatch;
21
+ export type GatewayDispatchPayload = GatewayApplicationCommandPermissionsUpdateDispatch | GatewayAutoModerationActionExecutionDispatch | GatewayAutoModerationRuleCreateDispatch | GatewayAutoModerationRuleDeleteDispatch | GatewayAutoModerationRuleModifyDispatch | GatewayChannelModifyDispatch | GatewayChannelPinsUpdateDispatch | GatewayEntitlementModifyDispatch | GatewayGuildAuditLogEntryCreateDispatch | GatewayGuildBanModifyDispatch | GatewayGuildCreateDispatch | GatewayRawGuildCreateDispatch | GatewayGuildDeleteDispatch | GatewayRawGuildDeleteDispatch | GatewayGuildsReadyDispatch | GatewayGuildEmojisUpdateDispatch | GatewayGuildIntegrationsUpdateDispatch | GatewayGuildMemberAddDispatch | GatewayGuildMemberRemoveDispatch | GatewayGuildMembersChunkDispatch | GatewayGuildMemberUpdateDispatch | GatewayGuildModifyDispatch | GatewayGuildRoleDeleteDispatch | GatewayGuildRoleModifyDispatch | GatewayGuildScheduledEventCreateDispatch | GatewayGuildScheduledEventDeleteDispatch | GatewayGuildScheduledEventUpdateDispatch | GatewayGuildScheduledEventUserAddDispatch | GatewayGuildScheduledEventUserRemoveDispatch | GatewayGuildStickersUpdateDispatch | GatewayIntegrationCreateDispatch | GatewayIntegrationDeleteDispatch | GatewayIntegrationUpdateDispatch | GatewayInteractionCreateDispatch | GatewayInviteCreateDispatch | GatewayInviteDeleteDispatch | GatewayMessageCreateDispatch | GatewayMessageDeleteBulkDispatch | GatewayMessageDeleteDispatch | GatewayMessagePollVoteAddDispatch | GatewayMessagePollVoteRemoveDispatch | GatewayMessageReactionAddDispatch | GatewayMessageReactionRemoveAllDispatch | GatewayMessageReactionRemoveDispatch | GatewayMessageReactionRemoveEmojiDispatch | GatewayMessageUpdateDispatch | GatewayPresenceUpdateDispatch | GatewayReadyDispatch | GatewayResumedDispatch | GatewayStageInstanceCreateDispatch | GatewayStageInstanceDeleteDispatch | GatewayStageInstanceUpdateDispatch | GatewayThreadCreateDispatch | GatewayThreadDeleteDispatch | GatewayThreadListSyncDispatch | GatewayThreadMembersUpdateDispatch | GatewayThreadMemberUpdateDispatch | GatewayThreadUpdateDispatch | GatewayTypingStartDispatch | GatewayUserUpdateDispatch | GatewayVoiceServerUpdateDispatch | GatewayVoiceStateUpdateDispatch | GatewayWebhooksUpdateDispatch | GatewayGuildSoundboardSoundCreateDispatch | GatewayGuildSoundboardSoundDeleteDispatch | GatewayGuildSoundboardSoundUpdateDispatch | GatewayGuildSoundboardSoundsUpdateDispatch | GatewaySoundboardSoundsDispatch;
21
22
  /**
22
23
  * https://discord.com/developers/docs/topics/gateway-events#hello
23
24
  */
@@ -346,6 +347,9 @@ export type GatewayGuildModifyDispatchData = APIGuild;
346
347
  * https://discord.com/developers/docs/topics/gateway-events#guild-create
347
348
  */
348
349
  export type GatewayGuildCreateDispatch = DataPayload<GatewayDispatchEvents.GuildCreate, GatewayGuildCreateDispatchData>;
350
+ export type GatewayRawGuildCreateDispatch = OmitInsert<GatewayGuildCreateDispatch, 't', {
351
+ t: GatewayDispatchEvents.RawGuildCreate;
352
+ }>;
349
353
  /**
350
354
  * https://discord.com/developers/docs/topics/gateway-events#guild-create
351
355
  * https://discord.com/developers/docs/topics/gateway-events#guild-create-guild-create-extra-fields
@@ -450,6 +454,13 @@ export type GatewayGuildUpdateDispatchData = GatewayGuildModifyDispatchData;
450
454
  * https://discord.com/developers/docs/topics/gateway-events#guild-delete
451
455
  */
452
456
  export type GatewayGuildDeleteDispatch = DataPayload<GatewayDispatchEvents.GuildDelete, GatewayGuildDeleteDispatchData>;
457
+ export type GatewayRawGuildDeleteDispatch = OmitInsert<GatewayGuildDeleteDispatch, 't', {
458
+ t: GatewayDispatchEvents.RawGuildDelete;
459
+ }>;
460
+ export type GatewayGuildsReadyDispatch = OmitInsert<GatewayReadyDispatch, 't' | 'd', {
461
+ t: GatewayDispatchEvents.GuildsReady;
462
+ d?: never;
463
+ }>;
453
464
  /**
454
465
  * https://discord.com/developers/docs/topics/gateway-events#guild-delete
455
466
  */
@@ -262,10 +262,6 @@ export declare enum GatewayIntentBits {
262
262
  Guilds = 1,
263
263
  GuildMembers = 2,
264
264
  GuildModeration = 4,
265
- /**
266
- * @deprecated This is the old name for {@apilink GatewayIntentBits#GuildModeration}
267
- */
268
- GuildBans = 4,
269
265
  GuildExpressions = 8,
270
266
  GuildIntegrations = 16,
271
267
  GuildWebhooks = 32,
@@ -283,7 +279,9 @@ export declare enum GatewayIntentBits {
283
279
  AutoModerationConfiguration = 1048576,
284
280
  AutoModerationExecution = 2097152,
285
281
  GuildMessagePolls = 16777216,
286
- DirectMessagePolls = 33554432
282
+ DirectMessagePolls = 33554432,
283
+ NonPrivilaged = 53575421,
284
+ OnlyPrivilaged = 33026
287
285
  }
288
286
  /**
289
287
  * https://discord.com/developers/docs/topics/gateway-events#receive-events
@@ -297,7 +295,10 @@ export declare enum GatewayDispatchEvents {
297
295
  GuildBanAdd = "GUILD_BAN_ADD",
298
296
  GuildBanRemove = "GUILD_BAN_REMOVE",
299
297
  GuildCreate = "GUILD_CREATE",
298
+ RawGuildCreate = "RAW_GUILD_CREATE",
300
299
  GuildDelete = "GUILD_DELETE",
300
+ RawGuildDelete = "RAW_GUILD_DELETE",
301
+ GuildsReady = "GUILDS_READY",
301
302
  GuildEmojisUpdate = "GUILD_EMOJIS_UPDATE",
302
303
  GuildIntegrationsUpdate = "GUILD_INTEGRATIONS_UPDATE",
303
304
  GuildMemberAdd = "GUILD_MEMBER_ADD",
@@ -246,10 +246,6 @@ var GatewayIntentBits;
246
246
  GatewayIntentBits[GatewayIntentBits["Guilds"] = 1] = "Guilds";
247
247
  GatewayIntentBits[GatewayIntentBits["GuildMembers"] = 2] = "GuildMembers";
248
248
  GatewayIntentBits[GatewayIntentBits["GuildModeration"] = 4] = "GuildModeration";
249
- /**
250
- * @deprecated This is the old name for {@apilink GatewayIntentBits#GuildModeration}
251
- */
252
- GatewayIntentBits[GatewayIntentBits["GuildBans"] = 4] = "GuildBans";
253
249
  GatewayIntentBits[GatewayIntentBits["GuildExpressions"] = 8] = "GuildExpressions";
254
250
  GatewayIntentBits[GatewayIntentBits["GuildIntegrations"] = 16] = "GuildIntegrations";
255
251
  GatewayIntentBits[GatewayIntentBits["GuildWebhooks"] = 32] = "GuildWebhooks";
@@ -268,6 +264,8 @@ var GatewayIntentBits;
268
264
  GatewayIntentBits[GatewayIntentBits["AutoModerationExecution"] = 2097152] = "AutoModerationExecution";
269
265
  GatewayIntentBits[GatewayIntentBits["GuildMessagePolls"] = 16777216] = "GuildMessagePolls";
270
266
  GatewayIntentBits[GatewayIntentBits["DirectMessagePolls"] = 33554432] = "DirectMessagePolls";
267
+ GatewayIntentBits[GatewayIntentBits["NonPrivilaged"] = 53575421] = "NonPrivilaged";
268
+ GatewayIntentBits[GatewayIntentBits["OnlyPrivilaged"] = 33026] = "OnlyPrivilaged";
271
269
  })(GatewayIntentBits || (exports.GatewayIntentBits = GatewayIntentBits = {}));
272
270
  /**
273
271
  * https://discord.com/developers/docs/topics/gateway-events#receive-events
@@ -282,7 +280,10 @@ var GatewayDispatchEvents;
282
280
  GatewayDispatchEvents["GuildBanAdd"] = "GUILD_BAN_ADD";
283
281
  GatewayDispatchEvents["GuildBanRemove"] = "GUILD_BAN_REMOVE";
284
282
  GatewayDispatchEvents["GuildCreate"] = "GUILD_CREATE";
283
+ GatewayDispatchEvents["RawGuildCreate"] = "RAW_GUILD_CREATE";
285
284
  GatewayDispatchEvents["GuildDelete"] = "GUILD_DELETE";
285
+ GatewayDispatchEvents["RawGuildDelete"] = "RAW_GUILD_DELETE";
286
+ GatewayDispatchEvents["GuildsReady"] = "GUILDS_READY";
286
287
  GatewayDispatchEvents["GuildEmojisUpdate"] = "GUILD_EMOJIS_UPDATE";
287
288
  GatewayDispatchEvents["GuildIntegrationsUpdate"] = "GUILD_INTEGRATIONS_UPDATE";
288
289
  GatewayDispatchEvents["GuildMemberAdd"] = "GUILD_MEMBER_ADD";
@@ -21,7 +21,9 @@ export declare class Shard {
21
21
  heart: ShardHeart;
22
22
  bucket: DynamicBucket;
23
23
  offlineSendQueue: ((_?: unknown) => void)[];
24
+ pendingGuilds: Set<string>;
24
25
  options: MakeRequired<ShardOptions, 'properties' | 'ratelimitOptions'>;
26
+ isReady: boolean;
25
27
  constructor(id: number, options: ShardOptions);
26
28
  get latency(): number;
27
29
  get isOpen(): boolean;
@@ -34,16 +36,16 @@ export declare class Shard {
34
36
  identify(): Promise<void>;
35
37
  get resumable(): boolean;
36
38
  resume(): Promise<void>;
37
- heartbeat(requested: boolean): Promise<void>;
38
- disconnect(): Promise<void>;
39
+ heartbeat(requested: boolean): void;
40
+ disconnect(): void;
39
41
  reconnect(): Promise<void>;
40
- onpacket(packet: GatewayReceivePayload): Promise<void>;
42
+ onpacket(packet: GatewayReceivePayload): void | Promise<void>;
41
43
  protected handleClosed(close: {
42
44
  code: number;
43
45
  reason: string;
44
46
  }): Promise<void>;
45
- close(code: number, reason: string): Promise<void>;
46
- protected handleMessage(data: string | Buffer): Promise<void> | undefined;
47
+ close(code: number, reason: string): void;
48
+ protected handleMessage(data: string | Buffer): void | Promise<void>;
47
49
  checkOffline(force: boolean): Promise<unknown>;
48
50
  calculateSafeRequests(): number;
49
51
  }
@@ -24,7 +24,9 @@ class Shard {
24
24
  };
25
25
  bucket;
26
26
  offlineSendQueue = [];
27
+ pendingGuilds = new Set();
27
28
  options;
29
+ isReady = false;
28
30
  constructor(id, options) {
29
31
  this.id = id;
30
32
  this.options = (0, common_1.MergeOptions)({
@@ -127,11 +129,11 @@ class Shard {
127
129
  },
128
130
  });
129
131
  }
130
- async heartbeat(requested) {
132
+ heartbeat(requested) {
131
133
  this.debugger?.debug(`[Shard #${this.id}] Sending ${requested ? '' : 'un'}requested heartbeat (Ack=${this.heart.ack})`);
132
134
  if (!requested) {
133
135
  if (!this.heart.ack) {
134
- await this.close(shared_1.ShardSocketCloseCodes.ZombiedConnection, 'Zombied connection');
136
+ this.close(shared_1.ShardSocketCloseCodes.ZombiedConnection, 'Zombied connection');
135
137
  return;
136
138
  }
137
139
  this.heart.ack = false;
@@ -142,33 +144,31 @@ class Shard {
142
144
  d: this.data.resume_seq ?? null,
143
145
  }));
144
146
  }
145
- async disconnect() {
147
+ disconnect() {
146
148
  this.debugger?.info(`[Shard #${this.id}] Disconnecting`);
147
- await this.close(shared_1.ShardSocketCloseCodes.Shutdown, 'Shard down request');
149
+ this.close(shared_1.ShardSocketCloseCodes.Shutdown, 'Shard down request');
148
150
  }
149
151
  async reconnect() {
150
152
  this.debugger?.info(`[Shard #${this.id}] Reconnecting`);
151
- await this.disconnect();
153
+ this.disconnect();
152
154
  await this.connect();
153
155
  }
154
- async onpacket(packet) {
156
+ onpacket(packet) {
155
157
  if (packet.s !== null) {
156
158
  this.data.resume_seq = packet.s;
157
159
  }
158
160
  this.debugger?.debug(`[Shard #${this.id}]`, packet.t ? packet.t : types_1.GatewayOpcodes[packet.op], this.data.resume_seq);
159
161
  switch (packet.op) {
160
- case types_1.GatewayOpcodes.Hello:
161
- {
162
- clearInterval(this.heart.nodeInterval);
163
- this.heart.interval = packet.d.heartbeat_interval;
164
- await this.heartbeat(false);
165
- this.heart.nodeInterval = setInterval(() => this.heartbeat(false), this.heart.interval);
166
- if (this.resumable) {
167
- return this.resume();
168
- }
169
- await this.identify();
162
+ case types_1.GatewayOpcodes.Hello: {
163
+ clearInterval(this.heart.nodeInterval);
164
+ this.heart.interval = packet.d.heartbeat_interval;
165
+ this.heartbeat(false);
166
+ this.heart.nodeInterval = setInterval(() => this.heartbeat(false), this.heart.interval);
167
+ if (this.resumable) {
168
+ return this.resume();
170
169
  }
171
- break;
170
+ return this.identify();
171
+ }
172
172
  case types_1.GatewayOpcodes.HeartbeatAck:
173
173
  {
174
174
  this.heart.ack = true;
@@ -179,37 +179,66 @@ class Shard {
179
179
  this.heartbeat(true);
180
180
  break;
181
181
  case types_1.GatewayOpcodes.Reconnect:
182
- await this.reconnect();
183
- break;
184
- case types_1.GatewayOpcodes.InvalidSession:
182
+ return this.reconnect();
183
+ case types_1.GatewayOpcodes.InvalidSession: {
185
184
  if (packet.d) {
186
185
  if (!this.resumable) {
187
186
  return this.logger.fatal('This is a completely unexpected error message.');
188
187
  }
189
- await this.resume();
188
+ return this.resume();
190
189
  }
191
- else {
192
- this.data.resume_seq = 0;
193
- this.data.session_id = undefined;
194
- await this.identify();
195
- }
196
- break;
190
+ this.data.resume_seq = 0;
191
+ this.data.session_id = undefined;
192
+ return this.identify();
193
+ }
197
194
  case types_1.GatewayOpcodes.Dispatch:
198
195
  {
199
196
  switch (packet.t) {
200
197
  case types_1.GatewayDispatchEvents.Resumed:
201
198
  {
202
- this.offlineSendQueue.map((resolve) => resolve());
199
+ this.isReady = true;
200
+ this.offlineSendQueue.map(resolve => resolve());
203
201
  this.options.handlePayload(this.id, packet);
204
202
  }
205
203
  break;
206
204
  case types_1.GatewayDispatchEvents.Ready: {
205
+ if ((0, common_1.hasIntent)(this.options.intents, 'Guilds')) {
206
+ for (let i = 0; i < packet.d.guilds.length; i++) {
207
+ this.pendingGuilds.add(packet.d.guilds.at(i).id);
208
+ }
209
+ }
207
210
  this.data.resume_gateway_url = packet.d.resume_gateway_url;
208
211
  this.data.session_id = packet.d.session_id;
209
- this.offlineSendQueue.map((resolve) => resolve());
212
+ this.offlineSendQueue.map(resolve => resolve());
210
213
  this.options.handlePayload(this.id, packet);
214
+ if (this.pendingGuilds.size === 0) {
215
+ this.isReady = true;
216
+ this.options.handlePayload(this.id, {
217
+ t: types_1.GatewayDispatchEvents.GuildsReady,
218
+ op: packet.op,
219
+ s: packet.s,
220
+ });
221
+ }
211
222
  break;
212
223
  }
224
+ case types_1.GatewayDispatchEvents.GuildCreate:
225
+ case types_1.GatewayDispatchEvents.GuildDelete:
226
+ if (this.pendingGuilds.delete(packet.d.id)) {
227
+ packet.t = `RAW_${packet.t}`;
228
+ this.options.handlePayload(this.id, packet);
229
+ if (this.pendingGuilds.size === 0) {
230
+ this.isReady = true;
231
+ this.options.handlePayload(this.id, {
232
+ t: types_1.GatewayDispatchEvents.GuildsReady,
233
+ op: packet.op,
234
+ s: packet.s,
235
+ });
236
+ }
237
+ }
238
+ else {
239
+ this.options.handlePayload(this.id, packet);
240
+ }
241
+ break;
213
242
  default:
214
243
  this.options.handlePayload(this.id, packet);
215
244
  break;
@@ -219,6 +248,7 @@ class Shard {
219
248
  }
220
249
  }
221
250
  async handleClosed(close) {
251
+ this.isReady = false;
222
252
  clearInterval(this.heart.nodeInterval);
223
253
  this.logger.warn(`${shared_1.ShardSocketCloseCodes[close.code] ?? types_1.GatewayCloseCodes[close.code] ?? close.code} (${close.code})`, close.reason);
224
254
  switch (close.code) {
@@ -265,7 +295,7 @@ class Shard {
265
295
  break;
266
296
  }
267
297
  }
268
- async close(code, reason) {
298
+ close(code, reason) {
269
299
  clearInterval(this.heart.nodeInterval);
270
300
  if (!this.isOpen) {
271
301
  return this.debugger?.warn(`[Shard #${this.id}] Is not open, reason:`, reason);
@@ -22,7 +22,7 @@ export declare class ShardManager extends Map<number, Shard> {
22
22
  startResharder(): Promise<void>;
23
23
  spawnBuckets(): Shard[][];
24
24
  forceIdentify(shardId: number): Promise<void>;
25
- disconnect(shardId: number): Promise<void> | undefined;
25
+ disconnect(shardId: number): void | undefined;
26
26
  disconnectAll(): void;
27
27
  setShardPresence(shardId: number, payload: GatewayUpdatePresence['d']): void;
28
28
  setPresence(payload: GatewayUpdatePresence['d']): void;
@@ -15,7 +15,7 @@ const structures_1 = require("../structures");
15
15
  const timeout_1 = require("../structures/timeout");
16
16
  class WorkerManager extends Map {
17
17
  static prepareSpaces(options, logger) {
18
- logger?.info('Preparing buckets', options);
18
+ logger?.info('Preparing buckets');
19
19
  const chunks = structures_1.DynamicBucket.chunk(new Array(options.shardEnd - options.shardStart), options.shardsPerWorker);
20
20
  chunks.forEach((shards, index) => {
21
21
  for (let i = 0; i < shards.length; i++) {
@@ -342,7 +342,7 @@ class WorkerManager extends Map {
342
342
  case 'WORKER_READY':
343
343
  {
344
344
  this.get(message.workerId).ready = true;
345
- if ([...this.values()].every(w => w.ready)) {
345
+ if (this.size === this.totalWorkers && [...this.values()].every(w => w.ready)) {
346
346
  this.postMessage(this.keys().next().value, {
347
347
  type: 'BOT_READY',
348
348
  });
@@ -529,7 +529,7 @@ class WorkerManager extends Map {
529
529
  const percentage = (info.shards / ((this.totalShards * 2500) / 1000)) * 100;
530
530
  if (percentage < this.options.resharding.percentage)
531
531
  return this.debugger?.debug(`Percentage is not enough to reshard ${percentage}/${this.options.resharding.percentage}`);
532
- this.debugger?.info('Starting resharding process');
532
+ this.debugger?.info(`Starting resharding process to ${info.shards}`);
533
533
  this._info = info;
534
534
  this.connectQueue.concurrency = info.session_start_limit.max_concurrency;
535
535
  this.options.info.session_start_limit.max_concurrency = info.session_start_limit.max_concurrency;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seyfert",
3
- "version": "2.1.1-dev-12247418720.0",
3
+ "version": "2.1.1-dev-12309212345.0",
4
4
  "description": "The most advanced framework for discord bots",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",