seyfert 0.1.0 → 1.0.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.
- package/README.md +19 -30
- package/lib/api/CDN.d.ts +0 -8
- package/lib/api/CDN.js +7 -13
- package/lib/api/Router.d.ts +2 -2
- package/lib/api/Router.js +1 -1
- package/lib/api/Routes/applications.d.ts +1 -1
- package/lib/api/Routes/channels.d.ts +1 -1
- package/lib/api/Routes/gateway.d.ts +1 -1
- package/lib/api/Routes/guilds.d.ts +1 -1
- package/lib/api/Routes/interactions.d.ts +1 -1
- package/lib/api/Routes/invites.d.ts +1 -1
- package/lib/api/Routes/stage-instances.d.ts +1 -1
- package/lib/api/Routes/stickers.d.ts +1 -1
- package/lib/api/Routes/users.d.ts +1 -1
- package/lib/api/Routes/voice.d.ts +1 -1
- package/lib/api/Routes/webhooks.d.ts +1 -1
- package/lib/api/api.d.ts +44 -0
- package/lib/api/api.js +354 -0
- package/lib/api/bucket.d.ts +19 -0
- package/lib/api/bucket.js +71 -0
- package/lib/api/index.d.ts +1 -1
- package/lib/api/index.js +1 -1
- package/lib/api/shared.d.ts +33 -5
- package/lib/api/shared.js +2 -7
- package/lib/api/utils/constants.d.ts +1 -30
- package/lib/api/utils/constants.js +2 -41
- package/lib/api/utils/types.d.ts +1 -320
- package/lib/api/utils/utils.d.ts +0 -38
- package/lib/api/utils/utils.js +1 -139
- package/lib/builders/ActionRow.js +1 -1
- package/lib/builders/Attachment.d.ts +14 -6
- package/lib/builders/Attachment.js +30 -7
- package/lib/builders/Button.d.ts +5 -14
- package/lib/builders/Button.js +0 -11
- package/lib/builders/{MessageEmbed.d.ts → Embed.d.ts} +15 -15
- package/lib/builders/{MessageEmbed.js → Embed.js} +16 -16
- package/lib/builders/Modal.js +1 -1
- package/lib/builders/SelectMenu.d.ts +14 -15
- package/lib/builders/SelectMenu.js +19 -18
- package/lib/builders/index.d.ts +1 -1
- package/lib/builders/index.js +1 -1
- package/lib/builders/types.d.ts +2 -2
- package/lib/cache/adapters/default.d.ts +1 -0
- package/lib/cache/adapters/default.js +3 -2
- package/lib/cache/adapters/redis.d.ts +3 -3
- package/lib/cache/adapters/redis.js +14 -5
- package/lib/cache/adapters/types.d.ts +1 -0
- package/lib/cache/adapters/workeradapter.d.ts +10 -1
- package/lib/cache/adapters/workeradapter.js +8 -3
- package/lib/cache/index.d.ts +18 -5
- package/lib/cache/index.js +23 -9
- package/lib/cache/resources/channels.d.ts +6 -2
- package/lib/cache/resources/channels.js +12 -6
- package/lib/cache/resources/default/base.d.ts +17 -16
- package/lib/cache/resources/default/base.js +25 -24
- package/lib/cache/resources/default/guild-based.d.ts +22 -19
- package/lib/cache/resources/default/guild-based.js +32 -31
- package/lib/cache/resources/default/guild-related.d.ts +22 -19
- package/lib/cache/resources/default/guild-related.js +37 -43
- package/lib/cache/resources/emojis.d.ts +4 -2
- package/lib/cache/resources/emojis.js +8 -6
- package/lib/cache/resources/guilds.d.ts +4 -2
- package/lib/cache/resources/guilds.js +15 -8
- package/lib/cache/resources/members.d.ts +4 -2
- package/lib/cache/resources/members.js +16 -13
- package/lib/cache/resources/overwrites.d.ts +25 -0
- package/lib/cache/resources/overwrites.js +39 -0
- package/lib/cache/resources/presence.js +3 -4
- package/lib/cache/resources/roles.d.ts +4 -2
- package/lib/cache/resources/roles.js +8 -6
- package/lib/cache/resources/stickers.d.ts +4 -2
- package/lib/cache/resources/stickers.js +8 -6
- package/lib/cache/resources/threads.d.ts +4 -2
- package/lib/cache/resources/threads.js +8 -6
- package/lib/cache/resources/users.d.ts +4 -2
- package/lib/cache/resources/users.js +8 -6
- package/lib/cache/resources/voice-states.d.ts +3 -3
- package/lib/cache/resources/voice-states.js +6 -7
- package/lib/client/base.d.ts +48 -16
- package/lib/client/base.js +19 -15
- package/lib/client/client.d.ts +15 -4
- package/lib/client/client.js +26 -28
- package/lib/client/httpclient.d.ts +3 -5
- package/lib/client/httpclient.js +29 -16
- package/lib/client/{oninteraction.d.ts → oninteractioncreate.d.ts} +1 -1
- package/lib/client/{oninteraction.js → oninteractioncreate.js} +34 -23
- package/lib/client/onmessagecreate.d.ts +3 -0
- package/lib/client/onmessagecreate.js +337 -0
- package/lib/client/workerclient.d.ts +19 -2
- package/lib/client/workerclient.js +156 -46
- package/lib/collection.d.ts +1 -1
- package/lib/collection.js +9 -6
- package/lib/commands/applications/chat.d.ts +32 -25
- package/lib/commands/applications/chat.js +51 -34
- package/lib/commands/applications/chatcontext.d.ts +34 -16
- package/lib/commands/applications/chatcontext.js +99 -20
- package/lib/commands/applications/menu.d.ts +9 -8
- package/lib/commands/applications/menu.js +14 -5
- package/lib/commands/applications/menucontext.d.ts +27 -10
- package/lib/commands/applications/menucontext.js +51 -7
- package/lib/commands/applications/options.d.ts +13 -13
- package/lib/commands/applications/shared.d.ts +7 -2
- package/lib/commands/decorators.d.ts +14 -14
- package/lib/commands/decorators.js +9 -5
- package/lib/commands/handler.d.ts +2 -1
- package/lib/commands/handler.js +60 -14
- package/lib/commands/index.d.ts +1 -1
- package/lib/commands/index.js +2 -1
- package/lib/commands/optionresolver.d.ts +6 -5
- package/lib/commands/optionresolver.js +10 -6
- package/lib/common/bot/watcher.d.ts +3 -3
- package/lib/common/bot/watcher.js +3 -1
- package/lib/common/index.d.ts +1 -1
- package/lib/common/index.js +2 -1
- package/lib/common/it/logger.d.ts +11 -0
- package/lib/common/it/logger.js +51 -2
- package/lib/common/it/utils.d.ts +3 -13
- package/lib/common/it/utils.js +9 -30
- package/lib/common/shorters/channels.d.ts +55 -5
- package/lib/common/shorters/channels.js +59 -0
- package/lib/common/shorters/guilds.d.ts +5 -2
- package/lib/common/shorters/guilds.js +18 -0
- package/lib/common/shorters/messages.js +0 -2
- package/lib/common/shorters/overwrites.d.ts +29 -0
- package/lib/common/shorters/overwrites.js +63 -0
- package/lib/common/shorters/roles.js +3 -3
- package/lib/common/shorters/webhook.d.ts +2 -2
- package/lib/common/types/util.d.ts +3 -2
- package/lib/common/types/write.d.ts +3 -7
- package/lib/components/handler.d.ts +11 -17
- package/lib/components/handler.js +45 -93
- package/lib/components/index.d.ts +0 -1
- package/lib/components/index.js +0 -1
- package/lib/components/listener.d.ts +2 -2
- package/lib/components/listener.js +2 -3
- package/lib/events/event.d.ts +2 -2
- package/lib/events/handler.d.ts +3 -2
- package/lib/events/handler.js +14 -6
- package/lib/events/hooks/dispatch.d.ts +2 -1
- package/lib/events/hooks/dispatch.js +5 -1
- package/lib/events/hooks/thread.d.ts +63 -63
- package/lib/index.d.ts +8 -5
- package/lib/index.js +20 -10
- package/lib/langs/handler.d.ts +6 -4
- package/lib/langs/handler.js +10 -8
- package/lib/langs/router.d.ts +8 -9
- package/lib/langs/router.js +5 -5
- package/lib/structures/ClientUser.d.ts +1 -16
- package/lib/structures/ClientUser.js +0 -31
- package/lib/structures/Guild.d.ts +1 -1
- package/lib/structures/GuildMember.d.ts +12 -0
- package/lib/structures/GuildMember.js +14 -0
- package/lib/structures/GuildRole.d.ts +4 -2
- package/lib/structures/GuildRole.js +4 -1
- package/lib/structures/GuildTemplate.js +1 -1
- package/lib/structures/Interaction.d.ts +2 -0
- package/lib/structures/Interaction.js +12 -13
- package/lib/structures/Message.d.ts +7 -2
- package/lib/structures/Message.js +6 -3
- package/lib/structures/Sticker.d.ts +1 -1
- package/lib/structures/Sticker.js +1 -1
- package/lib/structures/User.d.ts +5 -0
- package/lib/structures/User.js +3 -0
- package/lib/structures/Webhook.d.ts +1 -1
- package/lib/structures/Webhook.js +1 -1
- package/lib/structures/channels.d.ts +45 -6
- package/lib/structures/channels.js +23 -7
- package/lib/structures/extra/BitField.d.ts +9 -6
- package/lib/structures/extra/BitField.js +27 -3
- package/lib/structures/extra/Permissions.d.ts +6 -1
- package/lib/structures/extra/Permissions.js +7 -0
- package/lib/websocket/constants/index.js +1 -3
- package/lib/websocket/discord/basesocket.js +0 -1
- package/lib/websocket/discord/shared.d.ts +2 -0
- package/lib/websocket/discord/worker.d.ts +23 -7
- package/lib/websocket/discord/workermanager.d.ts +32 -5
- package/lib/websocket/discord/workermanager.js +98 -29
- package/package.json +23 -21
- package/lib/api/REST.d.ts +0 -127
- package/lib/api/REST.js +0 -424
- package/lib/api/errors/DiscordAPIError.d.ts +0 -51
- package/lib/api/errors/DiscordAPIError.js +0 -81
- package/lib/api/errors/HTTPError.d.ts +0 -20
- package/lib/api/errors/HTTPError.js +0 -28
- package/lib/api/errors/RateLimitError.d.ts +0 -19
- package/lib/api/errors/RateLimitError.js +0 -37
- package/lib/api/handlers/BurstHandler.d.ts +0 -51
- package/lib/api/handlers/BurstHandler.js +0 -124
- package/lib/api/handlers/SequentialHandler.d.ts +0 -81
- package/lib/api/handlers/SequentialHandler.js +0 -365
- package/lib/api/handlers/Shared.d.ts +0 -14
- package/lib/api/handlers/Shared.js +0 -125
- package/lib/api/interfaces/Handler.d.ts +0 -21
- package/lib/api/interfaces/Handler.js +0 -2
- package/lib/websocket/discord/handlemessage.d.ts +0 -0
- package/lib/websocket/discord/handlemessage.js +0 -1
- package/lib/websocket/discord/memberUpdate.d.ts +0 -16
- package/lib/websocket/discord/memberUpdate.js +0 -47
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ChannelType, VideoQualityMode, type APIDMChannel, type APIGuildCategoryChannel, type APIGuildForumChannel, type APIGuildMediaChannel, type APIGuildStageVoiceChannel, type APIGuildVoiceChannel, type APINewsChannel, type APITextChannel, type APIThreadChannel, type ThreadAutoArchiveDuration } from 'discord-api-types/v10';
|
|
2
2
|
import type { BaseClient } from '../client/base';
|
|
3
3
|
import type { APIChannelBase, APIGuildChannel, APIGuildForumDefaultReactionEmoji, APIGuildForumTag, EmojiResolvable, MessageCreateBodyRequest, MessageUpdateBodyRequest, MethodContext, ObjectToLower, RESTGetAPIChannelMessageReactionUsersQuery, RESTPatchAPIChannelJSONBody, RESTPatchAPIGuildChannelPositionsJSONBody, RESTPostAPIChannelWebhookJSONBody, RESTPostAPIGuildChannelJSONBody, SortOrderType, StringToNumber, ToClass } from '../common';
|
|
4
|
+
import type { GuildMember } from './GuildMember';
|
|
5
|
+
import type { GuildRole } from './GuildRole';
|
|
4
6
|
import { Webhook } from './Webhook';
|
|
5
7
|
import { DiscordBase } from './extra/DiscordBase';
|
|
6
8
|
export declare class BaseChannel<T extends ChannelType> extends DiscordBase<APIChannelBase<ChannelType>> {
|
|
@@ -53,9 +55,46 @@ interface IChannelTypes {
|
|
|
53
55
|
GuildCategory: CategoryChannel;
|
|
54
56
|
GuildAnnouncement: NewsChannel;
|
|
55
57
|
}
|
|
56
|
-
export interface BaseGuildChannel extends ObjectToLower<APIGuildChannel<ChannelType>> {
|
|
58
|
+
export interface BaseGuildChannel extends ObjectToLower<Omit<APIGuildChannel<ChannelType>, 'permission_overwrites'>> {
|
|
57
59
|
}
|
|
58
60
|
export declare class BaseGuildChannel extends BaseChannel<ChannelType> {
|
|
61
|
+
constructor(client: BaseClient, data: APIGuildChannel<ChannelType>);
|
|
62
|
+
permissionOverwrites: {
|
|
63
|
+
fetch: () => import("..").ReturnCache<{
|
|
64
|
+
type: number;
|
|
65
|
+
id: string;
|
|
66
|
+
deny: import("./extra/Permissions").PermissionsBitField;
|
|
67
|
+
allow: import("./extra/Permissions").PermissionsBitField;
|
|
68
|
+
}[] | undefined>;
|
|
69
|
+
values: () => {
|
|
70
|
+
type: number;
|
|
71
|
+
id: string;
|
|
72
|
+
deny: import("./extra/Permissions").PermissionsBitField;
|
|
73
|
+
allow: import("./extra/Permissions").PermissionsBitField;
|
|
74
|
+
}[][];
|
|
75
|
+
};
|
|
76
|
+
memberPermissions(member: GuildMember, checkAdmin?: boolean): Promise<import("./extra/Permissions").PermissionsBitField>;
|
|
77
|
+
rolePermissions(role: GuildRole, checkAdmin?: boolean): Promise<import("./extra/Permissions").PermissionsBitField>;
|
|
78
|
+
overwritesFor(member: GuildMember): Promise<{
|
|
79
|
+
everyone: {
|
|
80
|
+
type: number;
|
|
81
|
+
id: string;
|
|
82
|
+
deny: import("./extra/Permissions").PermissionsBitField;
|
|
83
|
+
allow: import("./extra/Permissions").PermissionsBitField;
|
|
84
|
+
} | undefined;
|
|
85
|
+
roles: {
|
|
86
|
+
type: number;
|
|
87
|
+
id: string;
|
|
88
|
+
deny: import("./extra/Permissions").PermissionsBitField;
|
|
89
|
+
allow: import("./extra/Permissions").PermissionsBitField;
|
|
90
|
+
}[];
|
|
91
|
+
member: {
|
|
92
|
+
type: number;
|
|
93
|
+
id: string;
|
|
94
|
+
deny: import("./extra/Permissions").PermissionsBitField;
|
|
95
|
+
allow: import("./extra/Permissions").PermissionsBitField;
|
|
96
|
+
} | undefined;
|
|
97
|
+
}>;
|
|
59
98
|
guild(force?: boolean): Promise<import("./Guild").Guild<"cached"> | import("./Guild").Guild<"api">>;
|
|
60
99
|
get url(): string;
|
|
61
100
|
setPosition(position: number, reason?: string): Promise<AllChannels>;
|
|
@@ -112,7 +151,7 @@ export declare class MessagesMethods extends DiscordBase {
|
|
|
112
151
|
};
|
|
113
152
|
static transformMessageBody<T>(body: MessageCreateBodyRequest | MessageUpdateBodyRequest): T;
|
|
114
153
|
}
|
|
115
|
-
export interface TextBaseGuildChannel extends ObjectToLower<Omit<APITextChannel, 'type'>>, MessagesMethods {
|
|
154
|
+
export interface TextBaseGuildChannel extends ObjectToLower<Omit<APITextChannel, 'type' | 'permission_overwrites'>>, MessagesMethods {
|
|
116
155
|
}
|
|
117
156
|
export declare class TextBaseGuildChannel extends BaseGuildChannel {
|
|
118
157
|
}
|
|
@@ -161,7 +200,7 @@ export declare class WebhookChannelMethods extends DiscordBase {
|
|
|
161
200
|
create: (body: RESTPostAPIChannelWebhookJSONBody) => Promise<Webhook>;
|
|
162
201
|
};
|
|
163
202
|
}
|
|
164
|
-
export interface TextGuildChannel extends ObjectToLower<Omit<APITextChannel, 'type'>>, BaseGuildChannel, TextBaseGuildChannel, WebhookChannelMethods {
|
|
203
|
+
export interface TextGuildChannel extends ObjectToLower<Omit<APITextChannel, 'type' | 'permission_overwrites'>>, BaseGuildChannel, TextBaseGuildChannel, WebhookChannelMethods {
|
|
165
204
|
}
|
|
166
205
|
export declare class TextGuildChannel extends BaseGuildChannel {
|
|
167
206
|
type: ChannelType.GuildText;
|
|
@@ -174,7 +213,7 @@ declare const DMChannel_base: ToClass<Omit<BaseChannel<ChannelType.DM>, "edit">,
|
|
|
174
213
|
export declare class DMChannel extends DMChannel_base {
|
|
175
214
|
type: ChannelType.DM;
|
|
176
215
|
}
|
|
177
|
-
export interface VoiceChannel extends ObjectToLower<APIGuildVoiceChannel
|
|
216
|
+
export interface VoiceChannel extends ObjectToLower<Omit<APIGuildVoiceChannel, 'permission_overwrites'>>, Omit<TextGuildChannel, 'type'>, VoiceChannelMethods, WebhookChannelMethods {
|
|
178
217
|
}
|
|
179
218
|
export declare class VoiceChannel extends BaseChannel<ChannelType.GuildVoice> {
|
|
180
219
|
type: ChannelType.GuildVoice;
|
|
@@ -194,7 +233,7 @@ export interface ForumChannel extends ObjectToLower<APIGuildForumChannel>, Omit<
|
|
|
194
233
|
export declare class ForumChannel extends BaseChannel<ChannelType.GuildForum> {
|
|
195
234
|
type: ChannelType.GuildForum;
|
|
196
235
|
}
|
|
197
|
-
export interface ThreadChannel extends ObjectToLower<APIThreadChannel
|
|
236
|
+
export interface ThreadChannel extends ObjectToLower<Omit<APIThreadChannel, 'permission_overwrites'>>, TextBaseGuildChannel {
|
|
198
237
|
}
|
|
199
238
|
export declare class ThreadChannel extends BaseChannel<ChannelType.PublicThread | ChannelType.AnnouncementThread | ChannelType.PrivateThread> {
|
|
200
239
|
type: ChannelType.PublicThread | ChannelType.AnnouncementThread | ChannelType.PrivateThread;
|
|
@@ -211,7 +250,7 @@ export declare class ThreadChannel extends BaseChannel<ChannelType.PublicThread
|
|
|
211
250
|
setInvitable(invitable?: boolean, reason?: string): Promise<AllChannels>;
|
|
212
251
|
setLocked(locked?: boolean, reason?: string): Promise<AllChannels>;
|
|
213
252
|
}
|
|
214
|
-
export interface CategoryChannel extends ObjectToLower<APIGuildCategoryChannel
|
|
253
|
+
export interface CategoryChannel extends ObjectToLower<Omit<APIGuildCategoryChannel, 'permission_overwrites'>> {
|
|
215
254
|
}
|
|
216
255
|
declare const CategoryChannel_base: ToClass<Omit<BaseGuildChannel, "type" | "setParent">, CategoryChannel>;
|
|
217
256
|
export declare class CategoryChannel extends CategoryChannel_base {
|
|
@@ -10,7 +10,6 @@ exports.DirectoryChannel = exports.NewsChannel = exports.CategoryChannel = expor
|
|
|
10
10
|
const v10_1 = require("discord-api-types/v10");
|
|
11
11
|
const ts_mixer_1 = require("ts-mixer");
|
|
12
12
|
const builders_1 = require("../builders");
|
|
13
|
-
const components_1 = require("../components");
|
|
14
13
|
const Webhook_1 = require("./Webhook");
|
|
15
14
|
const DiscordBase_1 = require("./extra/DiscordBase");
|
|
16
15
|
const functions_1 = require("./extra/functions");
|
|
@@ -32,7 +31,10 @@ class BaseChannel extends DiscordBase_1.DiscordBase {
|
|
|
32
31
|
return this.client.channels.delete(this.id, { reason });
|
|
33
32
|
}
|
|
34
33
|
edit(body, reason) {
|
|
35
|
-
return this.client.channels.edit(this.id, body, {
|
|
34
|
+
return this.client.channels.edit(this.id, body, {
|
|
35
|
+
reason,
|
|
36
|
+
guildId: 'guildId' in this ? this.guildId : '@me',
|
|
37
|
+
});
|
|
36
38
|
}
|
|
37
39
|
toString() {
|
|
38
40
|
return `<#${this.id}>`;
|
|
@@ -92,7 +94,24 @@ class BaseChannel extends DiscordBase_1.DiscordBase {
|
|
|
92
94
|
}
|
|
93
95
|
exports.BaseChannel = BaseChannel;
|
|
94
96
|
class BaseGuildChannel extends BaseChannel {
|
|
95
|
-
|
|
97
|
+
constructor(client, data) {
|
|
98
|
+
const { permission_overwrites, ...rest } = data;
|
|
99
|
+
super(client, rest);
|
|
100
|
+
}
|
|
101
|
+
permissionOverwrites = {
|
|
102
|
+
fetch: () => this.client.cache.overwrites?.get(this.id),
|
|
103
|
+
values: () => (this.guildId ? this.client.cache.overwrites?.values(this.guildId) ?? [] : []),
|
|
104
|
+
};
|
|
105
|
+
memberPermissions(member, checkAdmin = true) {
|
|
106
|
+
return this.client.channels.overwrites.memberPermissions(this.id, member, checkAdmin);
|
|
107
|
+
}
|
|
108
|
+
rolePermissions(role, checkAdmin = true) {
|
|
109
|
+
return this.client.channels.overwrites.rolePermissions(this.id, role, checkAdmin);
|
|
110
|
+
}
|
|
111
|
+
overwritesFor(member) {
|
|
112
|
+
return this.client.channels.overwrites.overwritesFor(this.id, member);
|
|
113
|
+
}
|
|
114
|
+
guild(force = false) {
|
|
96
115
|
return this.client.guilds.fetch(this.guildId, force);
|
|
97
116
|
}
|
|
98
117
|
get url() {
|
|
@@ -144,11 +163,8 @@ class MessagesMethods extends DiscordBase_1.DiscordBase {
|
|
|
144
163
|
static transformMessageBody(body) {
|
|
145
164
|
return {
|
|
146
165
|
...body,
|
|
147
|
-
components: body.components
|
|
148
|
-
? (body?.components instanceof components_1.ComponentsListener ? body.components.components : body.components).map(x => 'toJSON' in x ? x.toJSON() : x)
|
|
149
|
-
: undefined,
|
|
166
|
+
components: body.components?.map(x => ('toJSON' in x ? x.toJSON() : x)) ?? undefined,
|
|
150
167
|
embeds: body.embeds?.map(x => (x instanceof builders_1.Embed ? x.toJSON() : x)) ?? undefined,
|
|
151
|
-
//?
|
|
152
168
|
attachments: body.attachments?.map((x, i) => ({ id: i, ...(0, builders_1.resolveAttachment)(x) })) ?? undefined,
|
|
153
169
|
};
|
|
154
170
|
}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
export type BitFieldResolvable<T extends object> = keyof T | number | bigint | (keyof T | number | bigint)[];
|
|
2
2
|
export declare class BitField<T extends object> {
|
|
3
|
-
static None:
|
|
4
|
-
Flags:
|
|
3
|
+
static None: bigint;
|
|
4
|
+
Flags: Record<string, bigint>;
|
|
5
5
|
private bit;
|
|
6
6
|
constructor(bitfields?: BitFieldResolvable<T>);
|
|
7
7
|
set bits(bits: BitFieldResolvable<T>);
|
|
8
|
-
get bits():
|
|
9
|
-
add(...bits: BitFieldResolvable<T>[]):
|
|
10
|
-
remove(...bits: BitFieldResolvable<T>[]):
|
|
8
|
+
get bits(): bigint;
|
|
9
|
+
add(...bits: BitFieldResolvable<T>[]): bigint;
|
|
10
|
+
remove(...bits: BitFieldResolvable<T>[]): bigint;
|
|
11
11
|
has(...bits: BitFieldResolvable<T>[]): boolean;
|
|
12
|
+
missings(...bits: BitFieldResolvable<T>[]): bigint[];
|
|
12
13
|
equals(other: BitFieldResolvable<T>): boolean;
|
|
13
|
-
resolve(bits?: BitFieldResolvable<T>):
|
|
14
|
+
resolve(bits?: BitFieldResolvable<T>): bigint;
|
|
15
|
+
keys(...bits: BitFieldResolvable<T>[]): string[];
|
|
16
|
+
values(...bits: BitFieldResolvable<T>[]): bigint[];
|
|
14
17
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BitField = void 0;
|
|
4
4
|
class BitField {
|
|
5
|
-
static None =
|
|
5
|
+
static None = 0n;
|
|
6
6
|
Flags = {};
|
|
7
7
|
bit;
|
|
8
8
|
constructor(bitfields) {
|
|
@@ -32,17 +32,21 @@ class BitField {
|
|
|
32
32
|
const bitsResolved = bits.map(bit => this.resolve(bit));
|
|
33
33
|
return bitsResolved.every(bit => (this.bits & bit) === bit);
|
|
34
34
|
}
|
|
35
|
+
missings(...bits) {
|
|
36
|
+
const bitsResolved = bits.map(bit => this.resolve(bit));
|
|
37
|
+
return bitsResolved.filter(bit => (this.bits & bit) !== bit);
|
|
38
|
+
}
|
|
35
39
|
equals(other) {
|
|
36
40
|
return this.bits === this.resolve(other);
|
|
37
41
|
}
|
|
38
42
|
resolve(bits) {
|
|
39
43
|
switch (typeof bits) {
|
|
40
44
|
case 'number':
|
|
41
|
-
return bits;
|
|
45
|
+
return BigInt(bits);
|
|
42
46
|
case 'string':
|
|
43
47
|
return this.resolve(this.Flags[bits]);
|
|
44
48
|
case 'bigint':
|
|
45
|
-
return
|
|
49
|
+
return bits;
|
|
46
50
|
case 'object':
|
|
47
51
|
if (!Array.isArray(bits)) {
|
|
48
52
|
throw new TypeError(`Cannot resolve permission: ${bits}`);
|
|
@@ -52,5 +56,25 @@ class BitField {
|
|
|
52
56
|
throw new TypeError(`Cannot resolve permission: ${typeof bits === 'symbol' ? String(bits) : bits}`);
|
|
53
57
|
}
|
|
54
58
|
}
|
|
59
|
+
keys(...bits) {
|
|
60
|
+
const bitsResolved = bits.map(bit => BigInt(this.resolve(bit)));
|
|
61
|
+
return Object.entries(this.Flags).reduce((acc, value) => {
|
|
62
|
+
if (bitsResolved.some(bit => (bit & value[1]) === value[1])) {
|
|
63
|
+
acc.push(value[0]);
|
|
64
|
+
return acc;
|
|
65
|
+
}
|
|
66
|
+
return acc;
|
|
67
|
+
}, []);
|
|
68
|
+
}
|
|
69
|
+
values(...bits) {
|
|
70
|
+
const bitsResolved = bits.map(bit => BigInt(this.resolve(bit)));
|
|
71
|
+
return Object.entries(this.Flags).reduce((acc, value) => {
|
|
72
|
+
if (bitsResolved.some(bit => (bit & value[1]) === value[1])) {
|
|
73
|
+
acc.push(value[1]);
|
|
74
|
+
return acc;
|
|
75
|
+
}
|
|
76
|
+
return acc;
|
|
77
|
+
}, []);
|
|
78
|
+
}
|
|
55
79
|
}
|
|
56
80
|
exports.BitField = BitField;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PermissionFlagsBits } from 'discord-api-types/v10';
|
|
2
|
-
import {
|
|
2
|
+
import type { PermissionStrings } from '../../common';
|
|
3
|
+
import { BitField, type BitFieldResolvable } from './BitField';
|
|
3
4
|
export declare class PermissionsBitField extends BitField<typeof PermissionFlagsBits> {
|
|
4
5
|
Flags: {
|
|
5
6
|
readonly CreateInstantInvite: bigint;
|
|
@@ -51,4 +52,8 @@ export declare class PermissionsBitField extends BitField<typeof PermissionFlags
|
|
|
51
52
|
readonly UseExternalSounds: bigint;
|
|
52
53
|
readonly SendVoiceMessages: bigint;
|
|
53
54
|
};
|
|
55
|
+
static All: bigint;
|
|
56
|
+
keys: (...bits: BitFieldResolvable<typeof PermissionFlagsBits>[]) => PermissionStrings;
|
|
57
|
+
has(...bits: BitFieldResolvable<typeof PermissionFlagsBits>[]): boolean;
|
|
58
|
+
strictHas(...bits: BitFieldResolvable<typeof PermissionFlagsBits>[]): boolean;
|
|
54
59
|
}
|
|
@@ -5,5 +5,12 @@ const v10_1 = require("discord-api-types/v10");
|
|
|
5
5
|
const BitField_1 = require("./BitField");
|
|
6
6
|
class PermissionsBitField extends BitField_1.BitField {
|
|
7
7
|
Flags = v10_1.PermissionFlagsBits;
|
|
8
|
+
static All = Object.values(v10_1.PermissionFlagsBits).reduce((acc, value) => acc | value, 0n);
|
|
9
|
+
has(...bits) {
|
|
10
|
+
return super.has(...bits) || super.has('Administrator');
|
|
11
|
+
}
|
|
12
|
+
strictHas(...bits) {
|
|
13
|
+
return super.has(...bits);
|
|
14
|
+
}
|
|
8
15
|
}
|
|
9
16
|
exports.PermissionsBitField = PermissionsBitField;
|
|
@@ -24,8 +24,6 @@ exports.ShardManagerDefaults = ShardManagerDefaults;
|
|
|
24
24
|
const WorkerManagerDefaults = {
|
|
25
25
|
...ShardManagerDefaults,
|
|
26
26
|
shardsPerWorker: 32,
|
|
27
|
-
handlePayload: (
|
|
28
|
-
console.info(`Packet ${packet.t} on shard ${shardId} worker ${workerId}`);
|
|
29
|
-
},
|
|
27
|
+
handlePayload: (_shardId, _workerId, _packet) => { },
|
|
30
28
|
};
|
|
31
29
|
exports.WorkerManagerDefaults = WorkerManagerDefaults;
|
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.BaseSocket = void 0;
|
|
7
7
|
const ws_1 = __importDefault(require("ws"));
|
|
8
|
-
// import UWebSocket from 'uWebSockets.js';
|
|
9
8
|
class BaseSocket {
|
|
10
9
|
internal;
|
|
11
10
|
constructor(kind, url) {
|
|
@@ -35,6 +35,7 @@ export interface WorkerManagerOptions extends Omit<ShardManagerOptions, 'handleP
|
|
|
35
35
|
* @default 32
|
|
36
36
|
*/
|
|
37
37
|
shardsPerWorker?: number;
|
|
38
|
+
workerProxy?: boolean;
|
|
38
39
|
path: string;
|
|
39
40
|
handlePayload(shardId: number, workerId: number, packet: GatewayDispatchPayload): unknown;
|
|
40
41
|
}
|
|
@@ -96,4 +97,5 @@ export interface WorkerData {
|
|
|
96
97
|
shards: number[];
|
|
97
98
|
workerId: number;
|
|
98
99
|
debug: boolean;
|
|
100
|
+
workerProxy: boolean;
|
|
99
101
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ApiRequestOptions, HttpMethods } from '../..';
|
|
1
2
|
import type { GatewayDispatchPayload } from '../../common';
|
|
2
3
|
export interface WorkerShardInfo {
|
|
3
4
|
open: boolean;
|
|
@@ -7,18 +8,16 @@ export interface WorkerShardInfo {
|
|
|
7
8
|
}
|
|
8
9
|
export type WorkerInfo = {
|
|
9
10
|
shards: WorkerShardInfo[];
|
|
10
|
-
workerId: number;
|
|
11
11
|
};
|
|
12
12
|
type CreateWorkerMessage<T extends string, D extends object = {}> = {
|
|
13
13
|
type: T;
|
|
14
|
+
workerId: number;
|
|
14
15
|
} & D;
|
|
15
16
|
export type WorkerRequestConnect = CreateWorkerMessage<'CONNECT_QUEUE', {
|
|
16
17
|
shardId: number;
|
|
17
|
-
workerId: number;
|
|
18
18
|
}>;
|
|
19
19
|
export type WorkerReceivePayload = CreateWorkerMessage<'RECEIVE_PAYLOAD', {
|
|
20
20
|
shardId: number;
|
|
21
|
-
workerId: number;
|
|
22
21
|
payload: GatewayDispatchPayload;
|
|
23
22
|
}>;
|
|
24
23
|
export type WorkerSendResultPayload = CreateWorkerMessage<'RESULT_PAYLOAD', {
|
|
@@ -28,7 +27,6 @@ export type WorkerSendCacheRequest = CreateWorkerMessage<'CACHE_REQUEST', {
|
|
|
28
27
|
nonce: string;
|
|
29
28
|
method: 'scan' | 'get' | 'set' | 'patch' | 'values' | 'keys' | 'count' | 'remove' | 'contains' | 'getToRelationship' | 'bulkAddToRelationShip' | 'addToRelationship' | 'removeRelationship' | 'removeToRelationship';
|
|
30
29
|
args: any[];
|
|
31
|
-
workerId: number;
|
|
32
30
|
}>;
|
|
33
31
|
export type WorkerSendShardInfo = CreateWorkerMessage<'SHARD_INFO', WorkerShardInfo & {
|
|
34
32
|
nonce: string;
|
|
@@ -36,8 +34,26 @@ export type WorkerSendShardInfo = CreateWorkerMessage<'SHARD_INFO', WorkerShardI
|
|
|
36
34
|
export type WorkerSendInfo = CreateWorkerMessage<'WORKER_INFO', WorkerInfo & {
|
|
37
35
|
nonce: string;
|
|
38
36
|
}>;
|
|
39
|
-
export type WorkerReady = CreateWorkerMessage<'WORKER_READY'
|
|
40
|
-
|
|
37
|
+
export type WorkerReady = CreateWorkerMessage<'WORKER_READY'>;
|
|
38
|
+
export type WorkerSendApiRequest = CreateWorkerMessage<'WORKER_API_REQUEST', {
|
|
39
|
+
method: HttpMethods;
|
|
40
|
+
url: `/${string}`;
|
|
41
|
+
requestOptions: ApiRequestOptions;
|
|
42
|
+
nonce: string;
|
|
43
|
+
}>;
|
|
44
|
+
export type WorkerExecuteEval = CreateWorkerMessage<'EXECUTE_EVAL', {
|
|
45
|
+
func: string;
|
|
46
|
+
nonce: string;
|
|
47
|
+
toWorkerId: number;
|
|
48
|
+
}>;
|
|
49
|
+
export type WorkerSendEvalResponse = CreateWorkerMessage<'EVAL_RESPONSE', {
|
|
50
|
+
response: any;
|
|
51
|
+
nonce: string;
|
|
52
|
+
}>;
|
|
53
|
+
export type WorkerSendEval = CreateWorkerMessage<'EVAL', {
|
|
54
|
+
func: string;
|
|
55
|
+
nonce: string;
|
|
56
|
+
toWorkerId: number;
|
|
41
57
|
}>;
|
|
42
|
-
export type WorkerMessage = WorkerRequestConnect | WorkerReceivePayload | WorkerSendResultPayload | WorkerSendCacheRequest | WorkerSendShardInfo | WorkerSendInfo | WorkerReady;
|
|
58
|
+
export type WorkerMessage = WorkerRequestConnect | WorkerReceivePayload | WorkerSendResultPayload | WorkerSendCacheRequest | WorkerSendShardInfo | WorkerSendInfo | WorkerReady | WorkerSendApiRequest | WorkerExecuteEval | WorkerSendEvalResponse | WorkerSendEval;
|
|
43
59
|
export {};
|
|
@@ -1,22 +1,35 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
/// <reference types="node" />
|
|
5
|
+
/// <reference types="node" />
|
|
6
|
+
/// <reference types="node" />
|
|
2
7
|
import { Worker } from 'node:worker_threads';
|
|
8
|
+
import { ApiHandler } from '../..';
|
|
3
9
|
import { type Adapter } from '../../cache';
|
|
4
|
-
import { Logger, type GatewayPresenceUpdateData, type GatewaySendPayload } from '../../common';
|
|
10
|
+
import { Logger, type GatewayPresenceUpdateData, type GatewaySendPayload, type MakePartial } from '../../common';
|
|
5
11
|
import { ConnectQueue } from '../structures/timeout';
|
|
6
12
|
import { MemberUpdateHandler } from './events/memberUpdate';
|
|
7
13
|
import { PresenceUpdateHandler } from './events/presenceUpdate';
|
|
8
14
|
import type { ShardOptions, WorkerData, WorkerManagerOptions } from './shared';
|
|
9
15
|
import type { WorkerInfo, WorkerMessage, WorkerShardInfo } from './worker';
|
|
10
|
-
export declare class WorkerManager extends Map<number, Worker
|
|
16
|
+
export declare class WorkerManager extends Map<number, Worker & {
|
|
17
|
+
ready?: boolean;
|
|
18
|
+
}> {
|
|
11
19
|
options: Required<WorkerManagerOptions>;
|
|
12
20
|
debugger?: Logger;
|
|
13
21
|
connectQueue: ConnectQueue;
|
|
14
22
|
cacheAdapter: Adapter;
|
|
15
|
-
promises: Map<string,
|
|
23
|
+
promises: Map<string, {
|
|
24
|
+
resolve: (value: any) => void;
|
|
25
|
+
timeout: NodeJS.Timeout;
|
|
26
|
+
}>;
|
|
16
27
|
memberUpdateHandler: MemberUpdateHandler;
|
|
17
28
|
presenceUpdateHandler: PresenceUpdateHandler;
|
|
18
|
-
|
|
29
|
+
rest: ApiHandler;
|
|
30
|
+
constructor(options: MakePartial<WorkerManagerOptions, 'token' | 'intents' | 'info' | 'handlePayload'>);
|
|
19
31
|
setCache(adapter: Adapter): void;
|
|
32
|
+
setRest(rest: ApiHandler): void;
|
|
20
33
|
get remaining(): number;
|
|
21
34
|
get concurrency(): number;
|
|
22
35
|
get totalWorkers(): number;
|
|
@@ -65,5 +78,19 @@ export type ManagerSendCacheResult = CreateManagerMessage<'CACHE_RESULT', {
|
|
|
65
78
|
result: any;
|
|
66
79
|
}>;
|
|
67
80
|
export type ManagerSendBotReady = CreateManagerMessage<'BOT_READY'>;
|
|
68
|
-
export type
|
|
81
|
+
export type ManagerSendApiResponse = CreateManagerMessage<'API_RESPONSE', {
|
|
82
|
+
response: any;
|
|
83
|
+
error?: any;
|
|
84
|
+
nonce: string;
|
|
85
|
+
}>;
|
|
86
|
+
export type ManagerExecuteEval = CreateManagerMessage<'EXECUTE_EVAL', {
|
|
87
|
+
func: string;
|
|
88
|
+
nonce: string;
|
|
89
|
+
toWorkerId: number;
|
|
90
|
+
}>;
|
|
91
|
+
export type ManagerSendEvalResponse = CreateManagerMessage<'EVAL_RESPONSE', {
|
|
92
|
+
response: any;
|
|
93
|
+
nonce: string;
|
|
94
|
+
}>;
|
|
95
|
+
export type ManagerMessages = ManagerAllowConnect | ManagerSpawnShards | ManagerSendPayload | ManagerRequestShardInfo | ManagerRequestWorkerInfo | ManagerSendCacheResult | ManagerSendBotReady | ManagerSendApiResponse | ManagerSendEvalResponse | ManagerExecuteEval;
|
|
69
96
|
export {};
|
|
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.WorkerManager = void 0;
|
|
4
4
|
const node_crypto_1 = require("node:crypto");
|
|
5
5
|
const node_worker_threads_1 = require("node:worker_threads");
|
|
6
|
+
const __1 = require("../..");
|
|
6
7
|
const cache_1 = require("../../cache");
|
|
8
|
+
const base_1 = require("../../client/base");
|
|
7
9
|
const common_1 = require("../../common");
|
|
8
10
|
const constants_1 = require("../constants");
|
|
9
11
|
const structures_1 = require("../structures");
|
|
@@ -18,28 +20,18 @@ class WorkerManager extends Map {
|
|
|
18
20
|
promises = new Map();
|
|
19
21
|
memberUpdateHandler = new memberUpdate_1.MemberUpdateHandler();
|
|
20
22
|
presenceUpdateHandler = new presenceUpdate_1.PresenceUpdateHandler();
|
|
23
|
+
rest;
|
|
21
24
|
constructor(options) {
|
|
22
25
|
super();
|
|
23
|
-
options.totalShards ??= options.info.shards;
|
|
24
26
|
this.options = (0, common_1.MergeOptions)(constants_1.WorkerManagerDefaults, options);
|
|
25
|
-
this.options.workers ??= Math.ceil(this.options.totalShards / this.options.shardsPerWorker);
|
|
26
|
-
this.options.info.shards = options.totalShards;
|
|
27
|
-
options.shardEnd ??= options.totalShards;
|
|
28
|
-
options.shardStart ??= 0;
|
|
29
|
-
this.connectQueue = new timeout_1.ConnectQueue(5.5e3, this.concurrency);
|
|
30
|
-
if (this.options.debug) {
|
|
31
|
-
this.debugger = new common_1.Logger({
|
|
32
|
-
name: '[WorkerManager]',
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
if (this.totalShards / this.shardsPerWorker > this.workers) {
|
|
36
|
-
throw new Error(`Cannot create enough shards in the specified workers, minimum: ${Math.ceil(this.totalShards / this.shardsPerWorker)}`);
|
|
37
|
-
}
|
|
38
27
|
this.cacheAdapter = new cache_1.MemoryAdapter();
|
|
39
28
|
}
|
|
40
29
|
setCache(adapter) {
|
|
41
30
|
this.cacheAdapter = adapter;
|
|
42
31
|
}
|
|
32
|
+
setRest(rest) {
|
|
33
|
+
this.rest = rest;
|
|
34
|
+
}
|
|
43
35
|
get remaining() {
|
|
44
36
|
return this.options.info.session_start_limit.remaining;
|
|
45
37
|
}
|
|
@@ -104,6 +96,7 @@ class WorkerManager extends Map {
|
|
|
104
96
|
shards: shards[i],
|
|
105
97
|
intents: this.options.intents,
|
|
106
98
|
workerId: i,
|
|
99
|
+
workerProxy: this.options.workerProxy,
|
|
107
100
|
});
|
|
108
101
|
this.set(i, worker);
|
|
109
102
|
}
|
|
@@ -173,62 +166,112 @@ class WorkerManager extends Map {
|
|
|
173
166
|
break;
|
|
174
167
|
case 'RESULT_PAYLOAD':
|
|
175
168
|
{
|
|
176
|
-
const
|
|
177
|
-
if (!
|
|
169
|
+
const resultPayload = this.promises.get(message.nonce);
|
|
170
|
+
if (!resultPayload) {
|
|
178
171
|
return;
|
|
179
172
|
}
|
|
180
173
|
this.promises.delete(message.nonce);
|
|
181
|
-
|
|
174
|
+
clearTimeout(resultPayload.timeout);
|
|
175
|
+
resultPayload.resolve(true);
|
|
182
176
|
}
|
|
183
177
|
break;
|
|
184
178
|
case 'SHARD_INFO':
|
|
185
179
|
{
|
|
186
180
|
const { nonce, type, ...data } = message;
|
|
187
|
-
const
|
|
188
|
-
if (!
|
|
181
|
+
const shardInfo = this.promises.get(nonce);
|
|
182
|
+
if (!shardInfo) {
|
|
189
183
|
return;
|
|
190
184
|
}
|
|
191
185
|
this.promises.delete(nonce);
|
|
192
|
-
|
|
186
|
+
clearTimeout(shardInfo.timeout);
|
|
187
|
+
shardInfo.resolve(data);
|
|
193
188
|
}
|
|
194
189
|
break;
|
|
195
190
|
case 'WORKER_INFO':
|
|
196
191
|
{
|
|
197
192
|
const { nonce, type, ...data } = message;
|
|
198
|
-
const
|
|
199
|
-
if (!
|
|
193
|
+
const workerInfo = this.promises.get(nonce);
|
|
194
|
+
if (!workerInfo) {
|
|
200
195
|
return;
|
|
201
196
|
}
|
|
202
197
|
this.promises.delete(nonce);
|
|
203
|
-
|
|
198
|
+
clearTimeout(workerInfo.timeout);
|
|
199
|
+
workerInfo.resolve(data);
|
|
204
200
|
}
|
|
205
201
|
break;
|
|
206
202
|
case 'WORKER_READY':
|
|
207
203
|
{
|
|
208
|
-
|
|
204
|
+
this.get(message.workerId).ready = true;
|
|
205
|
+
if ([...this.values()].every(w => w.ready)) {
|
|
209
206
|
this.get(this.keys().next().value)?.postMessage({
|
|
210
207
|
type: 'BOT_READY',
|
|
211
208
|
});
|
|
209
|
+
this.forEach(w => {
|
|
210
|
+
delete w.ready;
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
break;
|
|
215
|
+
case 'WORKER_API_REQUEST':
|
|
216
|
+
{
|
|
217
|
+
const response = await this.rest.request(message.method, message.url, message.requestOptions);
|
|
218
|
+
this.get(message.workerId).postMessage({
|
|
219
|
+
nonce: message.nonce,
|
|
220
|
+
response,
|
|
221
|
+
type: 'API_RESPONSE',
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
break;
|
|
225
|
+
case 'EVAL_RESPONSE':
|
|
226
|
+
{
|
|
227
|
+
const { nonce, type, ...data } = message;
|
|
228
|
+
const evalResponse = this.promises.get(nonce);
|
|
229
|
+
if (!evalResponse) {
|
|
230
|
+
return;
|
|
212
231
|
}
|
|
232
|
+
this.promises.delete(nonce);
|
|
233
|
+
clearTimeout(evalResponse.timeout);
|
|
234
|
+
evalResponse.resolve(data.response);
|
|
235
|
+
}
|
|
236
|
+
break;
|
|
237
|
+
case 'EVAL':
|
|
238
|
+
{
|
|
239
|
+
const nonce = this.generateNonce();
|
|
240
|
+
this.get(message.toWorkerId).postMessage({
|
|
241
|
+
nonce,
|
|
242
|
+
func: message.func,
|
|
243
|
+
type: 'EXECUTE_EVAL',
|
|
244
|
+
toWorkerId: message.toWorkerId,
|
|
245
|
+
});
|
|
246
|
+
this.generateSendPromise(nonce, 'Eval timeout').then(val => this.get(message.workerId).postMessage({
|
|
247
|
+
nonce: message.nonce,
|
|
248
|
+
response: val,
|
|
249
|
+
type: 'EVAL_RESPONSE',
|
|
250
|
+
}));
|
|
213
251
|
}
|
|
214
252
|
break;
|
|
215
253
|
}
|
|
216
254
|
}
|
|
217
255
|
generateNonce(large = true) {
|
|
218
|
-
const
|
|
219
|
-
|
|
256
|
+
const uuid = (0, node_crypto_1.randomUUID)();
|
|
257
|
+
const nonce = large ? uuid : uuid.split('-')[0];
|
|
258
|
+
if (this.promises.has(nonce))
|
|
259
|
+
return this.generateNonce(large);
|
|
260
|
+
return nonce;
|
|
220
261
|
}
|
|
221
262
|
generateSendPromise(nonce, message = 'Timeout') {
|
|
222
263
|
let resolve = (_) => {
|
|
223
264
|
/**/
|
|
224
265
|
};
|
|
266
|
+
let timeout = -1;
|
|
225
267
|
const promise = new Promise((res, rej) => {
|
|
226
268
|
resolve = res;
|
|
227
|
-
setTimeout(() => {
|
|
269
|
+
timeout = setTimeout(() => {
|
|
270
|
+
this.promises.delete(nonce);
|
|
228
271
|
rej(new Error(message));
|
|
229
|
-
},
|
|
272
|
+
}, 60e3);
|
|
230
273
|
});
|
|
231
|
-
this.promises.set(nonce, resolve);
|
|
274
|
+
this.promises.set(nonce, { resolve, timeout });
|
|
232
275
|
return promise;
|
|
233
276
|
}
|
|
234
277
|
async send(data, shardId) {
|
|
@@ -266,6 +309,32 @@ class WorkerManager extends Map {
|
|
|
266
309
|
return this.generateSendPromise(nonce, 'Get worker info timeout');
|
|
267
310
|
}
|
|
268
311
|
async start() {
|
|
312
|
+
const rc = await base_1.BaseClient.prototype.getRC();
|
|
313
|
+
this.options.debug ||= rc.debug;
|
|
314
|
+
this.options.intents ||= rc.intents ?? 0;
|
|
315
|
+
this.options.token ??= rc.token;
|
|
316
|
+
this.rest ??= new __1.ApiHandler({
|
|
317
|
+
token: this.options.token,
|
|
318
|
+
baseUrl: 'api/v10',
|
|
319
|
+
domain: 'https://discord.com',
|
|
320
|
+
debug: this.options.debug,
|
|
321
|
+
});
|
|
322
|
+
this.options.info ??= await new __1.Router(this.rest).createProxy().gateway.bot.get();
|
|
323
|
+
this.options.totalShards ??= this.options.info.shards;
|
|
324
|
+
this.options = (0, common_1.MergeOptions)(constants_1.WorkerManagerDefaults, this.options);
|
|
325
|
+
this.options.workers ??= Math.ceil(this.options.totalShards / this.options.shardsPerWorker);
|
|
326
|
+
this.options.info.shards = this.options.totalShards;
|
|
327
|
+
this.options.shardEnd ??= this.options.totalShards;
|
|
328
|
+
this.options.shardStart ??= 0;
|
|
329
|
+
this.connectQueue = new timeout_1.ConnectQueue(5.5e3, this.concurrency);
|
|
330
|
+
if (this.options.debug) {
|
|
331
|
+
this.debugger = new common_1.Logger({
|
|
332
|
+
name: '[WorkerManager]',
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
if (this.totalShards / this.shardsPerWorker > this.workers) {
|
|
336
|
+
throw new Error(`Cannot create enough shards in the specified workers, minimum: ${Math.ceil(this.totalShards / this.shardsPerWorker)}`);
|
|
337
|
+
}
|
|
269
338
|
const spaces = this.prepareSpaces();
|
|
270
339
|
await this.prepareWorkers(spaces);
|
|
271
340
|
}
|