seyfert 1.2.1 → 1.2.3
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/LICENSE +190 -190
- package/README.md +46 -46
- package/lib/api/Router.d.ts +9 -0
- package/lib/api/Router.js +16 -8
- package/lib/api/Routes/cdn.d.ts +26 -15
- package/lib/api/api.d.ts +2 -3
- package/lib/api/api.js +4 -9
- package/lib/api/index.d.ts +0 -1
- package/lib/api/index.js +0 -1
- package/lib/builders/Modal.d.ts +4 -1
- package/lib/builders/Modal.js +4 -1
- package/lib/cache/adapters/default.d.ts +1 -0
- package/lib/cache/adapters/default.js +4 -0
- package/lib/cache/adapters/redis.d.ts +2 -0
- package/lib/cache/adapters/redis.js +17 -0
- package/lib/cache/adapters/types.d.ts +1 -0
- package/lib/cache/adapters/workeradapter.d.ts +1 -0
- package/lib/cache/adapters/workeradapter.js +6 -9
- package/lib/cache/index.d.ts +4 -6
- package/lib/cache/index.js +3 -0
- package/lib/cache/resources/overwrites.d.ts +2 -0
- package/lib/cache/resources/voice-states.d.ts +7 -2
- package/lib/cache/resources/voice-states.js +11 -0
- package/lib/client/base.d.ts +1 -1
- package/lib/client/base.js +8 -5
- package/lib/client/oninteractioncreate.js +7 -7
- package/lib/client/onmessagecreate.js +27 -15
- package/lib/client/workerclient.js +6 -12
- package/lib/commands/applications/chat.d.ts +20 -15
- package/lib/commands/applications/chat.js +13 -7
- package/lib/commands/applications/chatcontext.d.ts +2 -1
- package/lib/commands/applications/chatcontext.js +3 -0
- package/lib/commands/applications/menu.d.ts +4 -3
- package/lib/commands/applications/menu.js +9 -6
- package/lib/commands/applications/menucontext.d.ts +4 -1
- package/lib/commands/applications/menucontext.js +9 -0
- package/lib/commands/applications/shared.d.ts +4 -0
- package/lib/commands/applications/shared.js +6 -0
- package/lib/commands/basecontex.d.ts +1 -1
- package/lib/commands/basecontex.js +5 -11
- package/lib/commands/decorators.d.ts +14 -4
- package/lib/commands/decorators.js +29 -5
- package/lib/commands/handler.js +2 -0
- package/lib/common/shorters/channels.d.ts +12 -2
- package/lib/common/shorters/channels.js +16 -2
- package/lib/common/shorters/members.d.ts +6 -0
- package/lib/common/shorters/members.js +6 -0
- package/lib/common/shorters/messages.d.ts +2 -2
- package/lib/common/shorters/messages.js +7 -3
- package/lib/common/types/options.d.ts +2 -2
- package/lib/components/componentcontext.d.ts +1 -0
- package/lib/components/componentcontext.js +3 -0
- package/lib/structures/GuildEmoji.d.ts +2 -2
- package/lib/structures/GuildEmoji.js +1 -1
- package/lib/structures/GuildMember.d.ts +1 -5
- package/lib/structures/GuildMember.js +3 -3
- package/lib/structures/Message.d.ts +1 -1
- package/lib/structures/User.d.ts +2 -3
- package/lib/structures/User.js +9 -4
- package/lib/structures/VoiceState.d.ts +18 -0
- package/lib/structures/VoiceState.js +48 -0
- package/lib/structures/Webhook.js +1 -1
- package/lib/structures/channels.d.ts +11 -3
- package/lib/structures/channels.js +14 -1
- package/lib/structures/extra/BaseGuild.js +3 -3
- package/lib/structures/extra/Permissions.d.ts +1 -1
- package/lib/structures/index.d.ts +1 -0
- package/lib/structures/index.js +1 -0
- package/lib/websocket/discord/shard.d.ts +4 -4
- package/lib/websocket/discord/shard.js +12 -17
- package/lib/websocket/discord/sharder.d.ts +1 -1
- package/lib/websocket/discord/sharder.js +2 -2
- package/lib/websocket/discord/worker.d.ts +1 -1
- package/lib/websocket/discord/workermanager.js +4 -10
- package/lib/websocket/structures/index.d.ts +6 -99
- package/lib/websocket/structures/index.js +29 -211
- package/lib/websocket/structures/timeout.d.ts +2 -2
- package/lib/websocket/structures/timeout.js +13 -16
- package/package.json +2 -2
- package/lib/api/CDN.d.ts +0 -212
- package/lib/api/CDN.js +0 -228
- package/lib/common/shorters/overwrites.d.ts +0 -29
- package/lib/common/shorters/overwrites.js +0 -63
- package/lib/components/listener.d.ts +0 -11
- package/lib/components/listener.js +0 -17
- package/lib/structures/extra/BaseComponent.d.ts +0 -9
- package/lib/structures/extra/BaseComponent.js +0 -12
- package/lib/structures/extra/BaseSelectMenuComponent.d.ts +0 -9
- package/lib/structures/extra/BaseSelectMenuComponent.js +0 -13
|
@@ -44,7 +44,7 @@ export declare class Message extends BaseMessage {
|
|
|
44
44
|
reply(body: Omit<MessageCreateBodyRequest, 'message_reference'>, fail?: boolean): Promise<Message>;
|
|
45
45
|
edit(body: MessageUpdateBodyRequest): Promise<Message>;
|
|
46
46
|
write(body: MessageCreateBodyRequest): Promise<Message>;
|
|
47
|
-
delete(reason?: string): Promise<void
|
|
47
|
+
delete(reason?: string): Promise<void>;
|
|
48
48
|
crosspost(reason?: string): Promise<Message>;
|
|
49
49
|
}
|
|
50
50
|
export type EditMessageWebhook = Omit<MessageWebhookMethodEditParams, 'messageId'>;
|
package/lib/structures/User.d.ts
CHANGED
|
@@ -17,11 +17,10 @@ export declare class User extends DiscordBase<APIUser> {
|
|
|
17
17
|
dm(force?: boolean): Promise<import("./channels").DMChannel>;
|
|
18
18
|
write(body: MessageCreateBodyRequest): Promise<import("./Message").Message>;
|
|
19
19
|
avatarURL(options?: ImageOptions): string;
|
|
20
|
+
avatarDecorationURL(options?: ImageOptions): string | undefined;
|
|
20
21
|
bannerURL(options?: ImageOptions): string | undefined;
|
|
21
22
|
presence(): import("..").ReturnCache<(Omit<import("discord-api-types/v10").GatewayPresenceUpdate, "user"> & {
|
|
22
|
-
id: string;
|
|
23
|
-
* Fetch user
|
|
24
|
-
*/
|
|
23
|
+
id: string;
|
|
25
24
|
} & {
|
|
26
25
|
guild_id: string;
|
|
27
26
|
}) | undefined>;
|
package/lib/structures/User.js
CHANGED
|
@@ -27,17 +27,22 @@ class User extends DiscordBase_1.DiscordBase {
|
|
|
27
27
|
avatarURL(options) {
|
|
28
28
|
if (!this.avatar) {
|
|
29
29
|
const avatarIndex = this.discriminator === '0' ? Number(BigInt(this.id) >> 22n) % 6 : Number.parseInt(this.discriminator) % 5;
|
|
30
|
-
return this.rest.cdn.
|
|
30
|
+
return this.rest.cdn.embed.avatars.get(avatarIndex);
|
|
31
31
|
}
|
|
32
|
-
return this.rest.cdn.
|
|
32
|
+
return this.rest.cdn.avatars(this.id).get(this.avatar, options);
|
|
33
|
+
}
|
|
34
|
+
avatarDecorationURL(options) {
|
|
35
|
+
if (!this.avatarDecoration)
|
|
36
|
+
return;
|
|
37
|
+
return this.rest.cdn['avatar-decorations'](this.id).get(this.avatarDecoration, options);
|
|
33
38
|
}
|
|
34
39
|
bannerURL(options) {
|
|
35
40
|
if (!this.banner)
|
|
36
41
|
return;
|
|
37
|
-
return this.rest.cdn.
|
|
42
|
+
return this.rest.cdn.banners(this.id).get(this.banner, options);
|
|
38
43
|
}
|
|
39
44
|
presence() {
|
|
40
|
-
return this.
|
|
45
|
+
return this.client.members.presence(this.id);
|
|
41
46
|
}
|
|
42
47
|
toString() {
|
|
43
48
|
return `<@${this.id}>`;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { GuildMember, UsingClient } from '../';
|
|
2
|
+
import type { VoiceStateResource } from '../cache/resources/voice-states';
|
|
3
|
+
import type { ObjectToLower } from '../common';
|
|
4
|
+
import { Base } from './extra/Base';
|
|
5
|
+
export interface VoiceState extends Base, ObjectToLower<VoiceStateResource> {
|
|
6
|
+
}
|
|
7
|
+
export declare class VoiceState extends Base {
|
|
8
|
+
private withMember?;
|
|
9
|
+
constructor(client: UsingClient, data: VoiceStateResource, withMember?: GuildMember | undefined);
|
|
10
|
+
isMuted(): boolean;
|
|
11
|
+
member(force?: boolean): Promise<GuildMember>;
|
|
12
|
+
user(force?: boolean): Promise<import("./User").User>;
|
|
13
|
+
channel(force?: boolean): Promise<import("./channels").BaseChannel<import("discord-api-types/v10").ChannelType> | import("./channels").DMChannel | import("./channels").CategoryChannel | undefined>;
|
|
14
|
+
setMute(mute?: boolean, reason?: string): Promise<GuildMember>;
|
|
15
|
+
setDeaf(deaf?: boolean, reason?: string): Promise<GuildMember>;
|
|
16
|
+
disconnect(reason?: string): Promise<GuildMember>;
|
|
17
|
+
setChannel(channel_id: null | string, reason?: string): Promise<GuildMember>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VoiceState = void 0;
|
|
4
|
+
const Base_1 = require("./extra/Base");
|
|
5
|
+
class VoiceState extends Base_1.Base {
|
|
6
|
+
withMember;
|
|
7
|
+
constructor(client, data, withMember) {
|
|
8
|
+
super(client);
|
|
9
|
+
this.withMember = withMember;
|
|
10
|
+
this.__patchThis(data);
|
|
11
|
+
}
|
|
12
|
+
isMuted() {
|
|
13
|
+
return this.mute || this.selfMute;
|
|
14
|
+
}
|
|
15
|
+
async member(force) {
|
|
16
|
+
return (this.withMember ??= await this.client.members.fetch(this.guildId, this.userId, force));
|
|
17
|
+
}
|
|
18
|
+
async user(force) {
|
|
19
|
+
return this.client.users.fetch(this.userId, force);
|
|
20
|
+
}
|
|
21
|
+
async channel(force) {
|
|
22
|
+
if (!this.channelId)
|
|
23
|
+
return;
|
|
24
|
+
return this.client.channels.fetch(this.channelId, force);
|
|
25
|
+
}
|
|
26
|
+
async setMute(mute = !this.mute, reason) {
|
|
27
|
+
return this.client.members.edit(this.guildId, this.userId, { mute }, reason).then(member => {
|
|
28
|
+
this.mute = mute;
|
|
29
|
+
return member;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async setDeaf(deaf = !this.deaf, reason) {
|
|
33
|
+
return this.client.members.edit(this.guildId, this.userId, { deaf }, reason).then(member => {
|
|
34
|
+
this.deaf = deaf;
|
|
35
|
+
return member;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async disconnect(reason) {
|
|
39
|
+
return this.setChannel(null, reason);
|
|
40
|
+
}
|
|
41
|
+
async setChannel(channel_id, reason) {
|
|
42
|
+
return this.client.members.edit(this.guildId, this.userId, { channel_id }, reason).then(member => {
|
|
43
|
+
this.channelId = channel_id;
|
|
44
|
+
return member;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.VoiceState = VoiceState;
|
|
@@ -60,7 +60,7 @@ class Webhook extends DiscordBase_1.DiscordBase {
|
|
|
60
60
|
if (!this.avatar) {
|
|
61
61
|
return null;
|
|
62
62
|
}
|
|
63
|
-
return this.rest.cdn.
|
|
63
|
+
return this.rest.cdn.avatars(this.id).get(this.avatar, options);
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
66
|
* Fetches the webhook data from the Discord API.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type APIChannelBase, type
|
|
1
|
+
import { ChannelType, VideoQualityMode, type APIChannelBase, type APIDMChannel, type APIGuildCategoryChannel, type APIGuildChannel, type APIGuildForumChannel, type APIGuildForumDefaultReactionEmoji, type APIGuildForumTag, type APIGuildMediaChannel, type APIGuildStageVoiceChannel, type APIGuildVoiceChannel, type APINewsChannel, type APITextChannel, type APIThreadChannel, type RESTGetAPIChannelMessageReactionUsersQuery, type RESTPatchAPIChannelJSONBody, type RESTPatchAPIGuildChannelPositionsJSONBody, type RESTPostAPIChannelWebhookJSONBody, type RESTPostAPIGuildChannelJSONBody, type RESTPostAPIGuildForumThreadsJSONBody, type SortOrderType, type ThreadAutoArchiveDuration } from 'discord-api-types/v10';
|
|
2
2
|
import type { UsingClient } from '../commands';
|
|
3
3
|
import type { EmojiResolvable, MessageCreateBodyRequest, MessageUpdateBodyRequest, MethodContext, ObjectToLower, StringToNumber, ToClass } from '../common';
|
|
4
4
|
import type { GuildMember } from './GuildMember';
|
|
@@ -64,12 +64,14 @@ export declare class BaseGuildChannel extends BaseChannel<ChannelType> {
|
|
|
64
64
|
id: string;
|
|
65
65
|
deny: import("./extra/Permissions").PermissionsBitField;
|
|
66
66
|
allow: import("./extra/Permissions").PermissionsBitField;
|
|
67
|
+
guildId: string;
|
|
67
68
|
}[] | undefined>;
|
|
68
69
|
values: () => {
|
|
69
70
|
type: number;
|
|
70
71
|
id: string;
|
|
71
72
|
deny: import("./extra/Permissions").PermissionsBitField;
|
|
72
73
|
allow: import("./extra/Permissions").PermissionsBitField;
|
|
74
|
+
guildId: string;
|
|
73
75
|
}[][];
|
|
74
76
|
};
|
|
75
77
|
memberPermissions(member: GuildMember, checkAdmin?: boolean): Promise<import("./extra/Permissions").PermissionsBitField>;
|
|
@@ -80,18 +82,21 @@ export declare class BaseGuildChannel extends BaseChannel<ChannelType> {
|
|
|
80
82
|
id: string;
|
|
81
83
|
deny: import("./extra/Permissions").PermissionsBitField;
|
|
82
84
|
allow: import("./extra/Permissions").PermissionsBitField;
|
|
85
|
+
guildId: string;
|
|
83
86
|
} | undefined;
|
|
84
87
|
roles: {
|
|
85
88
|
type: number;
|
|
86
89
|
id: string;
|
|
87
90
|
deny: import("./extra/Permissions").PermissionsBitField;
|
|
88
91
|
allow: import("./extra/Permissions").PermissionsBitField;
|
|
92
|
+
guildId: string;
|
|
89
93
|
}[];
|
|
90
94
|
member: {
|
|
91
95
|
type: number;
|
|
92
96
|
id: string;
|
|
93
97
|
deny: import("./extra/Permissions").PermissionsBitField;
|
|
94
98
|
allow: import("./extra/Permissions").PermissionsBitField;
|
|
99
|
+
guildId: string;
|
|
95
100
|
} | undefined;
|
|
96
101
|
}>;
|
|
97
102
|
guild(force?: boolean): Promise<import("./Guild").Guild<"cached"> | import("./Guild").Guild<"api">>;
|
|
@@ -108,7 +113,7 @@ export declare class MessagesMethods extends DiscordBase {
|
|
|
108
113
|
write: (body: MessageCreateBodyRequest) => Promise<import("./Message").Message>;
|
|
109
114
|
edit: (messageId: string, body: MessageUpdateBodyRequest) => Promise<import("./Message").Message>;
|
|
110
115
|
crosspost: (messageId: string, reason?: string) => Promise<import("./Message").Message>;
|
|
111
|
-
delete: (messageId: string, reason?: string) => Promise<void
|
|
116
|
+
delete: (messageId: string, reason?: string) => Promise<void>;
|
|
112
117
|
fetch: (messageId: string) => Promise<import("./Message").Message>;
|
|
113
118
|
purge: (messages: string[], reason?: string) => Promise<never>;
|
|
114
119
|
};
|
|
@@ -129,7 +134,7 @@ export declare class MessagesMethods extends DiscordBase {
|
|
|
129
134
|
write: (body: MessageCreateBodyRequest) => Promise<import("./Message").Message>;
|
|
130
135
|
edit: (messageId: string, body: MessageUpdateBodyRequest) => Promise<import("./Message").Message>;
|
|
131
136
|
crosspost: (messageId: string, reason?: string) => Promise<import("./Message").Message>;
|
|
132
|
-
delete: (messageId: string, reason?: string) => Promise<void
|
|
137
|
+
delete: (messageId: string, reason?: string) => Promise<void>;
|
|
133
138
|
fetch: (messageId: string) => Promise<import("./Message").Message>;
|
|
134
139
|
purge: (messages: string[], reason?: string) => Promise<never>;
|
|
135
140
|
};
|
|
@@ -168,14 +173,17 @@ export declare class ThreadOnlyMethods extends DiscordBase {
|
|
|
168
173
|
setReactionEmoji(emoji: APIGuildForumDefaultReactionEmoji, reason?: string): Promise<AllChannels>;
|
|
169
174
|
setSortOrder(sort: SortOrderType, reason?: string): Promise<AllChannels>;
|
|
170
175
|
setThreadRateLimit(rate: number, reason?: string): Promise<AllChannels>;
|
|
176
|
+
thread(body: RESTPostAPIGuildForumThreadsJSONBody, reason?: string): Promise<ThreadChannel>;
|
|
171
177
|
}
|
|
172
178
|
export interface VoiceChannelMethods extends BaseChannel<ChannelType> {
|
|
173
179
|
}
|
|
174
180
|
export declare class VoiceChannelMethods extends DiscordBase {
|
|
181
|
+
guildId?: string;
|
|
175
182
|
setBitrate(bitrate: number | null, reason?: string): Promise<AllChannels>;
|
|
176
183
|
setUserLimit(user_limit: number | null, reason?: string): Promise<AllChannels>;
|
|
177
184
|
setRTC(rtc_region: string | null, reason?: string): Promise<AllChannels>;
|
|
178
185
|
setVideoQuality(quality: keyof typeof VideoQualityMode, reason?: string): Promise<AllChannels>;
|
|
186
|
+
states(): Promise<import("./VoiceState").VoiceState[]>;
|
|
179
187
|
}
|
|
180
188
|
export declare class WebhookGuildMethods extends DiscordBase {
|
|
181
189
|
webhooks: {
|
|
@@ -229,12 +229,16 @@ let ThreadOnlyMethods = class ThreadOnlyMethods extends DiscordBase_1.DiscordBas
|
|
|
229
229
|
setThreadRateLimit(rate, reason) {
|
|
230
230
|
return this.edit({ default_thread_rate_limit_per_user: rate }, reason);
|
|
231
231
|
}
|
|
232
|
+
async thread(body, reason) {
|
|
233
|
+
return this.client.channels.thread(this.id, body, reason);
|
|
234
|
+
}
|
|
232
235
|
};
|
|
233
236
|
exports.ThreadOnlyMethods = ThreadOnlyMethods;
|
|
234
237
|
exports.ThreadOnlyMethods = ThreadOnlyMethods = __decorate([
|
|
235
238
|
(0, ts_mixer_1.mix)(TopicableGuildChannel)
|
|
236
239
|
], ThreadOnlyMethods);
|
|
237
240
|
class VoiceChannelMethods extends DiscordBase_1.DiscordBase {
|
|
241
|
+
guildId;
|
|
238
242
|
setBitrate(bitrate, reason) {
|
|
239
243
|
return this.edit({ bitrate }, reason);
|
|
240
244
|
}
|
|
@@ -247,13 +251,22 @@ class VoiceChannelMethods extends DiscordBase_1.DiscordBase {
|
|
|
247
251
|
setVideoQuality(quality, reason) {
|
|
248
252
|
return this.edit({ video_quality_mode: v10_1.VideoQualityMode[quality] }, reason);
|
|
249
253
|
}
|
|
254
|
+
async states() {
|
|
255
|
+
if (!this.guildId)
|
|
256
|
+
return [];
|
|
257
|
+
const states = await this.cache.voiceStates?.values(this.guildId);
|
|
258
|
+
if (!states?.length)
|
|
259
|
+
return [];
|
|
260
|
+
const filter = states.filter(state => state.channelId === this.id);
|
|
261
|
+
return filter;
|
|
262
|
+
}
|
|
250
263
|
}
|
|
251
264
|
exports.VoiceChannelMethods = VoiceChannelMethods;
|
|
252
265
|
class WebhookGuildMethods extends DiscordBase_1.DiscordBase {
|
|
253
266
|
webhooks = WebhookGuildMethods.guild({ client: this.client, guildId: this.id });
|
|
254
267
|
static guild(ctx) {
|
|
255
268
|
return {
|
|
256
|
-
list: () => ctx.client.webhooks.
|
|
269
|
+
list: () => ctx.client.webhooks.listFromGuild(ctx.guildId),
|
|
257
270
|
};
|
|
258
271
|
}
|
|
259
272
|
}
|
|
@@ -38,7 +38,7 @@ class BaseGuild extends DiscordBase_1.DiscordBase {
|
|
|
38
38
|
if (!this.icon) {
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
|
-
return this.rest.cdn.
|
|
41
|
+
return this.rest.cdn.icons(this.id).get(this.icon, options);
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
44
|
* splashURL gets the current guild splash as a string.
|
|
@@ -50,7 +50,7 @@ class BaseGuild extends DiscordBase_1.DiscordBase {
|
|
|
50
50
|
if (!this.splash) {
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
53
|
-
return this.rest.cdn
|
|
53
|
+
return this.rest.cdn['discovery-splashes'](this.id).get(this.splash, options);
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
56
|
* bannerURL gets the current guild banner as a string.
|
|
@@ -62,7 +62,7 @@ class BaseGuild extends DiscordBase_1.DiscordBase {
|
|
|
62
62
|
if (!this.banner) {
|
|
63
63
|
return;
|
|
64
64
|
}
|
|
65
|
-
return this.rest.cdn.
|
|
65
|
+
return this.rest.cdn.banners(this.id).get(this.banner, options);
|
|
66
66
|
}
|
|
67
67
|
toString() {
|
|
68
68
|
return this.name;
|
|
@@ -53,7 +53,7 @@ export declare class PermissionsBitField extends BitField<typeof PermissionFlags
|
|
|
53
53
|
readonly SendVoiceMessages: bigint;
|
|
54
54
|
};
|
|
55
55
|
static All: bigint;
|
|
56
|
-
keys: (bits
|
|
56
|
+
keys: (bits?: BitFieldResolvable<typeof PermissionFlagsBits>[]) => PermissionStrings;
|
|
57
57
|
has(...bits: BitFieldResolvable<typeof PermissionFlagsBits>[]): boolean;
|
|
58
58
|
strictHas(...bits: BitFieldResolvable<typeof PermissionFlagsBits>[]): boolean;
|
|
59
59
|
}
|
package/lib/structures/index.js
CHANGED
|
@@ -27,5 +27,6 @@ __exportStar(require("./Interaction"), exports);
|
|
|
27
27
|
__exportStar(require("./Message"), exports);
|
|
28
28
|
__exportStar(require("./Sticker"), exports);
|
|
29
29
|
__exportStar(require("./User"), exports);
|
|
30
|
+
__exportStar(require("./VoiceState"), exports);
|
|
30
31
|
__exportStar(require("./Webhook"), exports);
|
|
31
32
|
__exportStar(require("./channels"), exports);
|
|
@@ -3,7 +3,7 @@ import type { GatewayReceivePayload, GatewaySendPayload } from 'discord-api-type
|
|
|
3
3
|
import type WS from 'ws';
|
|
4
4
|
import { type CloseEvent } from 'ws';
|
|
5
5
|
import type { Logger } from '../../common';
|
|
6
|
-
import { DynamicBucket
|
|
6
|
+
import { DynamicBucket } from '../structures';
|
|
7
7
|
import { ConnectTimeout } from '../structures/timeout';
|
|
8
8
|
import { BaseSocket } from './basesocket';
|
|
9
9
|
import type { ShardData, ShardOptions } from './shared';
|
|
@@ -23,7 +23,7 @@ export declare class Shard {
|
|
|
23
23
|
connectTimeout: ConnectTimeout;
|
|
24
24
|
heart: ShardHeart;
|
|
25
25
|
bucket: DynamicBucket;
|
|
26
|
-
offlineSendQueue:
|
|
26
|
+
offlineSendQueue: ((_?: unknown) => void)[];
|
|
27
27
|
constructor(id: number, options: ShardOptions);
|
|
28
28
|
get latency(): number;
|
|
29
29
|
get isOpen(): boolean;
|
|
@@ -31,7 +31,7 @@ export declare class Shard {
|
|
|
31
31
|
get resumeGatewayURL(): string | undefined;
|
|
32
32
|
get currentGatewayURL(): string;
|
|
33
33
|
connect(): Promise<void>;
|
|
34
|
-
send<T extends GatewaySendPayload = GatewaySendPayload>(
|
|
34
|
+
send<T extends GatewaySendPayload = GatewaySendPayload>(force: boolean, message: T): Promise<void>;
|
|
35
35
|
identify(): Promise<void>;
|
|
36
36
|
get resumable(): boolean;
|
|
37
37
|
resume(): Promise<void>;
|
|
@@ -42,6 +42,6 @@ export declare class Shard {
|
|
|
42
42
|
protected handleClosed(close: CloseEvent): Promise<void>;
|
|
43
43
|
close(code: number, reason: string): Promise<void>;
|
|
44
44
|
protected handleMessage({ data }: WS.MessageEvent): Promise<void>;
|
|
45
|
-
checkOffline(
|
|
45
|
+
checkOffline(force: boolean): Promise<unknown>;
|
|
46
46
|
calculateSafeRequests(): number;
|
|
47
47
|
}
|
|
@@ -23,7 +23,7 @@ class Shard {
|
|
|
23
23
|
ack: true,
|
|
24
24
|
};
|
|
25
25
|
bucket;
|
|
26
|
-
offlineSendQueue =
|
|
26
|
+
offlineSendQueue = [];
|
|
27
27
|
constructor(id, options) {
|
|
28
28
|
this.id = id;
|
|
29
29
|
this.options = options;
|
|
@@ -34,12 +34,7 @@ class Shard {
|
|
|
34
34
|
if (options.debugger)
|
|
35
35
|
this.debugger = options.debugger;
|
|
36
36
|
const safe = this.calculateSafeRequests();
|
|
37
|
-
this.bucket = new structures_1.DynamicBucket({
|
|
38
|
-
limit: safe,
|
|
39
|
-
refillAmount: safe,
|
|
40
|
-
refillInterval: 6e4,
|
|
41
|
-
debugger: this.debugger,
|
|
42
|
-
});
|
|
37
|
+
this.bucket = new structures_1.DynamicBucket({ refillInterval: 6e4, limit: safe, debugger: options.debugger });
|
|
43
38
|
}
|
|
44
39
|
get latency() {
|
|
45
40
|
return this.heart.lastAck && this.heart.lastBeat
|
|
@@ -76,7 +71,7 @@ class Shard {
|
|
|
76
71
|
this.heart.ack = true;
|
|
77
72
|
};
|
|
78
73
|
}
|
|
79
|
-
async send(
|
|
74
|
+
async send(force, message) {
|
|
80
75
|
this.debugger?.info(`[Shard #${this.id}] Sending: ${v10_1.GatewayOpcodes[message.op]} ${JSON.stringify(message.d, (_, value) => {
|
|
81
76
|
if (typeof value === 'string')
|
|
82
77
|
return value.replace(this.options.token, v => {
|
|
@@ -85,13 +80,13 @@ class Shard {
|
|
|
85
80
|
});
|
|
86
81
|
return value;
|
|
87
82
|
}, 1)}`);
|
|
88
|
-
await this.checkOffline(
|
|
89
|
-
await this.bucket.acquire(
|
|
90
|
-
await this.checkOffline(
|
|
83
|
+
await this.checkOffline(force);
|
|
84
|
+
await this.bucket.acquire(force);
|
|
85
|
+
await this.checkOffline(force);
|
|
91
86
|
this.websocket?.send(JSON.stringify(message));
|
|
92
87
|
}
|
|
93
88
|
async identify() {
|
|
94
|
-
await this.send(
|
|
89
|
+
await this.send(true, {
|
|
95
90
|
op: v10_1.GatewayOpcodes.Identify,
|
|
96
91
|
d: {
|
|
97
92
|
token: `Bot ${this.options.token}`,
|
|
@@ -107,7 +102,7 @@ class Shard {
|
|
|
107
102
|
return !!(this.data.resume_gateway_url && this.data.session_id && this.data.resumeSeq !== null);
|
|
108
103
|
}
|
|
109
104
|
async resume() {
|
|
110
|
-
await this.send(
|
|
105
|
+
await this.send(true, {
|
|
111
106
|
op: v10_1.GatewayOpcodes.Resume,
|
|
112
107
|
d: {
|
|
113
108
|
seq: this.data.resumeSeq,
|
|
@@ -185,13 +180,13 @@ class Shard {
|
|
|
185
180
|
{
|
|
186
181
|
switch (packet.t) {
|
|
187
182
|
case v10_1.GatewayDispatchEvents.Resumed:
|
|
188
|
-
this.offlineSendQueue.
|
|
183
|
+
this.offlineSendQueue.map((resolve) => resolve());
|
|
189
184
|
this.options.handlePayload(this.id, packet);
|
|
190
185
|
break;
|
|
191
186
|
case v10_1.GatewayDispatchEvents.Ready: {
|
|
192
187
|
this.data.resume_gateway_url = packet.d.resume_gateway_url;
|
|
193
188
|
this.data.session_id = packet.d.session_id;
|
|
194
|
-
this.offlineSendQueue.
|
|
189
|
+
this.offlineSendQueue.map((resolve) => resolve());
|
|
195
190
|
this.options.handlePayload(this.id, packet);
|
|
196
191
|
break;
|
|
197
192
|
}
|
|
@@ -251,9 +246,9 @@ class Shard {
|
|
|
251
246
|
}
|
|
252
247
|
return this.onpacket(JSON.parse(data));
|
|
253
248
|
}
|
|
254
|
-
checkOffline(
|
|
249
|
+
checkOffline(force) {
|
|
255
250
|
if (!this.isOpen) {
|
|
256
|
-
return new Promise(resolve => this.offlineSendQueue
|
|
251
|
+
return new Promise(resolve => this.offlineSendQueue[force ? 'unshift' : 'push'](resolve));
|
|
257
252
|
}
|
|
258
253
|
return Promise.resolve();
|
|
259
254
|
}
|
|
@@ -22,7 +22,7 @@ export declare class ShardManager extends Map<number, Shard> {
|
|
|
22
22
|
disconnect(shardId: number): Promise<void> | undefined;
|
|
23
23
|
disconnectAll(): Promise<unknown>;
|
|
24
24
|
setShardPresence(shardId: number, payload: GatewayUpdatePresence['d']): void;
|
|
25
|
-
setPresence(payload: GatewayUpdatePresence['d']): Promise<void
|
|
25
|
+
setPresence(payload: GatewayUpdatePresence['d']): Promise<void>;
|
|
26
26
|
joinVoice(guild_id: string, channel_id: string, options: ObjectToLower<Pick<GatewayVoiceStateUpdate['d'], 'self_deaf' | 'self_mute'>>): void;
|
|
27
27
|
leaveVoice(guild_id: string): void;
|
|
28
28
|
send<T extends GatewaySendPayload>(shardId: number, payload: T): void;
|
|
@@ -82,7 +82,7 @@ class ShardManager extends Map {
|
|
|
82
82
|
*/
|
|
83
83
|
spawnBuckets() {
|
|
84
84
|
this.debugger?.info('#0 Preparing buckets');
|
|
85
|
-
const chunks = structures_1.
|
|
85
|
+
const chunks = structures_1.DynamicBucket.chunk(new Array(this.shardEnd - this.shardStart), this.concurrency);
|
|
86
86
|
chunks.forEach((arr, index) => {
|
|
87
87
|
for (let i = 0; i < arr.length; i++) {
|
|
88
88
|
const id = i + (index > 0 ? index * this.concurrency : 0) + this.shardStart;
|
|
@@ -155,7 +155,7 @@ class ShardManager extends Map {
|
|
|
155
155
|
payload,
|
|
156
156
|
});
|
|
157
157
|
}
|
|
158
|
-
this.get(shardId)?.send(
|
|
158
|
+
this.get(shardId)?.send(false, payload);
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
exports.ShardManager = ShardManager;
|
|
@@ -25,7 +25,7 @@ export type WorkerSendResultPayload = CreateWorkerMessage<'RESULT_PAYLOAD', {
|
|
|
25
25
|
}>;
|
|
26
26
|
export type WorkerSendCacheRequest = CreateWorkerMessage<'CACHE_REQUEST', {
|
|
27
27
|
nonce: string;
|
|
28
|
-
method: 'scan' | 'get' | 'set' | 'patch' | 'values' | 'keys' | 'count' | 'remove' | 'contains' | 'getToRelationship' | 'bulkAddToRelationShip' | 'addToRelationship' | 'removeRelationship' | 'removeToRelationship';
|
|
28
|
+
method: 'scan' | 'get' | 'set' | 'patch' | 'values' | 'keys' | 'count' | 'remove' | 'flush' | 'contains' | 'getToRelationship' | 'bulkAddToRelationShip' | 'addToRelationship' | 'removeRelationship' | 'removeToRelationship';
|
|
29
29
|
args: any[];
|
|
30
30
|
}>;
|
|
31
31
|
export type WorkerSendShardInfo = CreateWorkerMessage<'SHARD_INFO', WorkerShardInfo & {
|
|
@@ -83,7 +83,7 @@ class WorkerManager extends Map {
|
|
|
83
83
|
}
|
|
84
84
|
prepareSpaces() {
|
|
85
85
|
this.debugger?.info('Preparing buckets');
|
|
86
|
-
const chunks = structures_1.
|
|
86
|
+
const chunks = structures_1.DynamicBucket.chunk(new Array(this.shardEnd - this.shardStart), this.options.shardsPerWorker);
|
|
87
87
|
chunks.forEach((shards, index) => {
|
|
88
88
|
for (let i = 0; i < shards.length; i++) {
|
|
89
89
|
const id = i + (index > 0 ? index * this.options.shardsPerWorker : 0) + this.shardStart;
|
|
@@ -310,19 +310,13 @@ class WorkerManager extends Map {
|
|
|
310
310
|
return nonce;
|
|
311
311
|
}
|
|
312
312
|
generateSendPromise(nonce, message = 'Timeout') {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
};
|
|
316
|
-
let timeout = -1;
|
|
317
|
-
const promise = new Promise((res, rej) => {
|
|
318
|
-
resolve = res;
|
|
319
|
-
timeout = setTimeout(() => {
|
|
313
|
+
return new Promise((res, rej) => {
|
|
314
|
+
const timeout = setTimeout(() => {
|
|
320
315
|
this.promises.delete(nonce);
|
|
321
316
|
rej(new Error(message));
|
|
322
317
|
}, 60e3);
|
|
318
|
+
this.promises.set(nonce, { resolve: res, timeout });
|
|
323
319
|
});
|
|
324
|
-
this.promises.set(nonce, { resolve, timeout });
|
|
325
|
-
return promise;
|
|
326
320
|
}
|
|
327
321
|
async send(data, shardId) {
|
|
328
322
|
const workerId = this.calculateWorkerId(shardId);
|
|
@@ -1,117 +1,24 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type
|
|
3
|
-
/**
|
|
4
|
-
* just any kind of request to queue and resolve later
|
|
5
|
-
*/
|
|
6
|
-
export type QueuedRequest = (value: void | Promise<void>) => Promise<unknown> | any;
|
|
2
|
+
import { type Logger } from '../../common';
|
|
7
3
|
/**
|
|
8
4
|
* options of the dynamic bucket
|
|
9
5
|
*/
|
|
10
6
|
export interface DynamicBucketOptions {
|
|
11
7
|
limit: number;
|
|
12
8
|
refillInterval: number;
|
|
13
|
-
refillAmount: number;
|
|
14
9
|
debugger?: Logger;
|
|
15
10
|
}
|
|
16
|
-
/**
|
|
17
|
-
* generally useless for interaction based bots
|
|
18
|
-
* ideally this would only be triggered on certain paths
|
|
19
|
-
* example: a huge amount of messages being spammed
|
|
20
|
-
*
|
|
21
|
-
* a dynamic bucket is just a priority queue implemented using linked lists
|
|
22
|
-
* we create an empty bucket for every path
|
|
23
|
-
* dynamically allocating memory improves the final memory footprint
|
|
24
|
-
*/
|
|
25
11
|
export declare class DynamicBucket {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
refillAmount: number;
|
|
29
|
-
/** The queue of requests to acquire an available request. Mapped by <shardId, resolve()> */
|
|
30
|
-
queue: PriorityQueue<QueuedRequest>;
|
|
31
|
-
/** The amount of requests that have been used up already. */
|
|
12
|
+
options: DynamicBucketOptions;
|
|
13
|
+
queue: ((value?: unknown) => any)[];
|
|
32
14
|
used: number;
|
|
33
|
-
|
|
34
|
-
processing: boolean;
|
|
35
|
-
/** The timeout id for the timer to reduce the used amount by the refill amount. */
|
|
36
|
-
timeoutId?: NodeJS.Timeout;
|
|
37
|
-
/** The timestamp in milliseconds when the next refill is scheduled. */
|
|
15
|
+
processing?: boolean;
|
|
38
16
|
refillsAt?: number;
|
|
39
|
-
|
|
17
|
+
timeoutId?: NodeJS.Timeout;
|
|
40
18
|
constructor(options: DynamicBucketOptions);
|
|
41
19
|
get remaining(): number;
|
|
42
20
|
refill(): void;
|
|
43
|
-
/** Begin processing the queue. */
|
|
44
21
|
processQueue(): Promise<void>;
|
|
45
|
-
|
|
46
|
-
acquire(priority: number): Promise<void>;
|
|
47
|
-
toString(): string;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* abstract node lol
|
|
51
|
-
*/
|
|
52
|
-
export interface AbstractNode<T> {
|
|
53
|
-
data: T;
|
|
54
|
-
next: this | null;
|
|
55
|
-
}
|
|
56
|
-
export interface QueuePusher<T> {
|
|
57
|
-
push(data: T): NonNullable<TNode<T>>;
|
|
58
|
-
}
|
|
59
|
-
export interface QueuePusherWithPriority<T> {
|
|
60
|
-
push(data: T, priority: number): NonNullable<PNode<T>>;
|
|
61
|
-
}
|
|
62
|
-
export declare class TNode<T> implements AbstractNode<T> {
|
|
63
|
-
data: T;
|
|
64
|
-
next: this | null;
|
|
65
|
-
constructor(data: T);
|
|
66
|
-
static null<T>(list: AbstractNode<T> | null): list is null;
|
|
67
|
-
}
|
|
68
|
-
export declare class PNode<T> extends TNode<T> {
|
|
69
|
-
priority: number;
|
|
70
|
-
constructor(data: T, priority: number);
|
|
71
|
-
}
|
|
72
|
-
export declare abstract class Queue<T> {
|
|
73
|
-
protected abstract head: AbstractNode<T> | null;
|
|
74
|
-
/**
|
|
75
|
-
* O(1)
|
|
76
|
-
*/
|
|
77
|
-
pop(): AbstractNode<T> | null;
|
|
78
|
-
/**
|
|
79
|
-
* O(1)
|
|
80
|
-
*/
|
|
81
|
-
peek(): T;
|
|
82
|
-
/**
|
|
83
|
-
* O(n)
|
|
84
|
-
*/
|
|
85
|
-
size(): number;
|
|
86
|
-
/**
|
|
87
|
-
* O(1)
|
|
88
|
-
*/
|
|
89
|
-
isEmpty(): boolean;
|
|
90
|
-
[Symbol.iterator](): IterableIterator<T>;
|
|
91
|
-
toArray(): T[];
|
|
92
|
-
toString(): string;
|
|
93
|
-
}
|
|
94
|
-
export declare class LinkedList<T> extends Queue<T> implements QueuePusher<T> {
|
|
95
|
-
protected head: TNode<T> | null;
|
|
96
|
-
/**
|
|
97
|
-
* O(1)
|
|
98
|
-
*/
|
|
99
|
-
push(data: T): NonNullable<TNode<T>>;
|
|
100
|
-
}
|
|
101
|
-
export declare class PriorityQueue<T> extends Queue<T> implements QueuePusherWithPriority<T> {
|
|
102
|
-
protected head: PNode<T> | null;
|
|
103
|
-
/**
|
|
104
|
-
* O(#priorities)
|
|
105
|
-
*/
|
|
106
|
-
push(data: T, priority: number): NonNullable<PNode<T>>;
|
|
107
|
-
}
|
|
108
|
-
export declare class SequentialBucket {
|
|
109
|
-
private connections;
|
|
110
|
-
private capacity;
|
|
111
|
-
private spawnTimeout;
|
|
112
|
-
constructor(maxCapacity: number);
|
|
113
|
-
destroy(): Promise<void>;
|
|
114
|
-
push(promise: QueuedRequest): Promise<void>;
|
|
115
|
-
acquire(promises?: LinkedList<QueuedRequest>): Promise<boolean>;
|
|
22
|
+
acquire(force?: boolean): Promise<unknown>;
|
|
116
23
|
static chunk<T>(array: T[], chunks: number): T[][];
|
|
117
24
|
}
|