disgroove 2.2.1-dev.64c7abc → 2.2.1-dev.d0eed5e
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/dist/lib/Client.d.ts +4 -7
- package/dist/lib/Client.js +2 -1
- package/dist/lib/constants.d.ts +1 -0
- package/dist/lib/constants.js +1 -0
- package/dist/lib/gateway/Shard.d.ts +13 -8
- package/dist/lib/gateway/Shard.js +90 -41
- package/dist/lib/types/gateway-events.d.ts +85 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/lib/Client.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/// <reference types="node" />
|
2
|
-
import { GatewayIntents, type OAuth2Scopes, type
|
2
|
+
import { GatewayIntents, type OAuth2Scopes, type ActionTypes, type ImageWidgetStyleOptions, InteractionCallbackType, type MFALevel, type ReactionTypes, type ApplicationCommandTypes, type EventTypes, type TriggerTypes, type ChannelTypes, type VideoQualityModes, type SortOrderTypes, type ForumLayoutTypes, type InviteTargetTypes, type VerificationLevel, type DefaultMessageNotificationLevel, type ExplicitContentFilterLevel, type SystemChannelFlags, type ApplicationFlags, type ApplicationIntegrationTypes, type ChannelFlags, type GuildFeatures, type GuildScheduledEventEntityTypes, type GuildScheduledEventPrivacyLevel, type GuildScheduledEventStatus, type MessageFlags, type OnboardingMode, type PrivacyLevel, type GuildMemberFlags } from "./constants";
|
3
3
|
import { Util } from "./utils";
|
4
4
|
import { RequestManager, type File } from "./rest";
|
5
5
|
import EventEmitter from "node:events";
|
@@ -13,7 +13,7 @@ import type { Channel, Message, FollowedChannel, ThreadMember, Overwrite, Defaul
|
|
13
13
|
import type { LocaleMap, snowflake, timestamp } from "./types/common";
|
14
14
|
import type { Emoji } from "./types/emoji";
|
15
15
|
import type { Entitlement } from "./types/entitlements";
|
16
|
-
import type {
|
16
|
+
import type { AutoModerationActionExecutionEventFields, ChannelPinsUpdateEventFields, ThreadListSyncEventFields, ThreadMemberUpdateEventExtraFields, ThreadMembersUpdateEventFields, GuildCreateEventExtraFields, GuildAuditLogEntryCreateExtraFields, GuildBanAddEventFields, GuildBanRemoveEventFields, GuildMemberAddEventExtraFields, GuildMemberRemoveEventFields, GuildMemberUpdateEventFields, GuildMembersChunkEventFields, IntegrationCreateEventExtraFields, IntegrationUpdateEventExtraFields, IntegrationDeleteEventFields, InviteCreateEventFields, InviteDeleteEventFields, MessageCreateEventExtraFields, MessageDeleteEventFields, MessageDeleteBulkEventFields, MessageReactionAddEventFields, MessageReactionRemoveEventFields, MessageReactionRemoveAllEventFields, MessageReactionRemoveEmojiEventFields, PresenceUpdateEventFields, TypingStartEventFields, VoiceServerUpdateEventFields, MessagePollVoteAddFields, MessagePollVoteRemoveFields, GatewayPresenceUpdate, RawPayload } from "./types/gateway-events";
|
17
17
|
import type { Guild, GuildMember, WelcomeScreen, GuildWidgetSettings, Ban, Integration, GuildOnboarding, GuildPreview, GuildWidget, UnavailableGuild, OnboardingPrompt, WelcomeScreenChannel } from "./types/guild";
|
18
18
|
import type { GuildScheduledEvent, GuildScheduledEventUser, GuildScheduledEventEntityMetadata } from "./types/guild-scheduled-event";
|
19
19
|
import type { GuildTemplate } from "./types/guild-template";
|
@@ -993,11 +993,7 @@ export declare class Client extends EventEmitter {
|
|
993
993
|
limit?: number;
|
994
994
|
}): Promise<Array<GuildMember>>;
|
995
995
|
/** https://discord.com/developers/docs/topics/gateway-events#update-presence */
|
996
|
-
setPresence(options:
|
997
|
-
activities: Array<Pick<Activity, "name" | "type" | "url" | "state">>;
|
998
|
-
status?: StatusTypes;
|
999
|
-
afk?: boolean;
|
1000
|
-
}): void;
|
996
|
+
setPresence(options: Partial<Pick<GatewayPresenceUpdate, "activities" | "status" | "afk">>): void;
|
1001
997
|
/** https://discord.com/developers/docs/resources/guild-template#sync-guild-template */
|
1002
998
|
syncGuildTemplate(guildId: snowflake, code: string): Promise<GuildTemplate>;
|
1003
999
|
/** https://discord.com/developers/docs/resources/channel#trigger-typing-indicator */
|
@@ -1028,6 +1024,7 @@ export declare interface Client extends EventEmitter {
|
|
1028
1024
|
removeListener<K extends keyof ClientEvents>(eventName: K, listener: (...args: ClientEvents[K]) => void): this;
|
1029
1025
|
}
|
1030
1026
|
export interface ClientEvents {
|
1027
|
+
dispatch: [packet: RawPayload];
|
1031
1028
|
hello: [];
|
1032
1029
|
ready: [];
|
1033
1030
|
resumed: [];
|
package/dist/lib/Client.js
CHANGED
@@ -36,6 +36,7 @@ class Client extends node_events_1.default {
|
|
36
36
|
this.rest = new rest_1.RequestManager(token, this.auth);
|
37
37
|
this.util = new utils_1.Util();
|
38
38
|
this.guildShardMap = {};
|
39
|
+
this.guilds = new Map();
|
39
40
|
}
|
40
41
|
/** https://discord.com/developers/docs/resources/channel#group-dm-add-recipient */
|
41
42
|
addGroupRecipient(channelId, userId, options) {
|
@@ -2061,7 +2062,7 @@ class Client extends node_events_1.default {
|
|
2061
2062
|
/** https://discord.com/developers/docs/topics/gateway-events#update-presence */
|
2062
2063
|
setPresence(options) {
|
2063
2064
|
for (const [id, shard] of this.shards)
|
2064
|
-
shard.
|
2065
|
+
shard.updatePresence(options);
|
2065
2066
|
}
|
2066
2067
|
/** https://discord.com/developers/docs/resources/guild-template#sync-guild-template */
|
2067
2068
|
async syncGuildTemplate(guildId, code) {
|
package/dist/lib/constants.d.ts
CHANGED
@@ -616,6 +616,7 @@ export declare enum StatusTypes {
|
|
616
616
|
}
|
617
617
|
/** https://discord.com/developers/docs/topics/gateway-events#receive-events */
|
618
618
|
export declare enum GatewayEvents {
|
619
|
+
Dispatch = "dispatch",
|
619
620
|
Hello = "hello",
|
620
621
|
Ready = "ready",
|
621
622
|
Resumed = "resumed",
|
package/dist/lib/constants.js
CHANGED
@@ -682,6 +682,7 @@ var StatusTypes;
|
|
682
682
|
/** https://discord.com/developers/docs/topics/gateway-events#receive-events */
|
683
683
|
var GatewayEvents;
|
684
684
|
(function (GatewayEvents) {
|
685
|
+
GatewayEvents["Dispatch"] = "dispatch";
|
685
686
|
GatewayEvents["Hello"] = "hello";
|
686
687
|
GatewayEvents["Ready"] = "ready";
|
687
688
|
GatewayEvents["Resumed"] = "resumed";
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import WebSocket from "ws";
|
2
|
-
import { StatusTypes } from "../constants";
|
3
2
|
import { Client } from "../Client";
|
4
|
-
import type {
|
3
|
+
import type { GatewayPresenceUpdate, Identify, RequestGuildMembers, Resume } from "../types/gateway-events";
|
5
4
|
export declare class Shard {
|
6
5
|
id: number;
|
7
6
|
private heartbeatInterval;
|
@@ -9,17 +8,23 @@ export declare class Shard {
|
|
9
8
|
ws: WebSocket;
|
10
9
|
sessionId: string;
|
11
10
|
constructor(id: number, client: Client);
|
12
|
-
/** https://discord.com/developers/docs/topics/gateway-events#update-presence */
|
13
|
-
setPresence(options: {
|
14
|
-
activities?: Array<Pick<Activity, "name" | "type" | "url" | "state">>;
|
15
|
-
status?: StatusTypes;
|
16
|
-
afk?: boolean;
|
17
|
-
}): void;
|
18
11
|
/** https://discord.com/developers/docs/topics/gateway#connections */
|
19
12
|
connect(): void;
|
13
|
+
/** https://discord.com/developers/docs/topics/gateway#connections */
|
20
14
|
disconnect(): void;
|
15
|
+
/** https://discord.com/developers/docs/topics/gateway-events#heartbeat */
|
16
|
+
heartbeat(lastSequence: number | null): void;
|
17
|
+
/** https://discord.com/developers/docs/topics/gateway-events#identify */
|
18
|
+
identify(options: Identify): void;
|
19
|
+
private onDispatch;
|
21
20
|
private onWebSocketOpen;
|
22
21
|
private onWebSocketMessage;
|
23
22
|
private onWebSocketError;
|
24
23
|
private onWebSocketClose;
|
24
|
+
/** https://discord.com/developers/docs/topics/gateway-events#request-guild-members */
|
25
|
+
requestGuildMembers(options: RequestGuildMembers): void;
|
26
|
+
/** https://discord.com/developers/docs/topics/gateway-events#resume */
|
27
|
+
resume(options: Resume): void;
|
28
|
+
/** https://discord.com/developers/docs/topics/gateway-events#update-presence */
|
29
|
+
updatePresence(options: Partial<Pick<GatewayPresenceUpdate, "activities" | "status" | "afk">>): void;
|
25
30
|
}
|
@@ -42,18 +42,6 @@ class Shard {
|
|
42
42
|
this.client = client;
|
43
43
|
this.ws = new ws_1.default("wss://gateway.discord.gg/?v=10&encoding=json");
|
44
44
|
}
|
45
|
-
/** https://discord.com/developers/docs/topics/gateway-events#update-presence */
|
46
|
-
setPresence(options) {
|
47
|
-
this.ws.send(JSON.stringify({
|
48
|
-
op: constants_1.GatewayOPCodes.PresenceUpdate,
|
49
|
-
d: {
|
50
|
-
since: options.status === constants_1.StatusTypes.Idle ? Date.now() : null,
|
51
|
-
activities: options.activities,
|
52
|
-
status: options.status ?? constants_1.StatusTypes.Online,
|
53
|
-
afk: !!options.afk,
|
54
|
-
},
|
55
|
-
}));
|
56
|
-
}
|
57
45
|
/** https://discord.com/developers/docs/topics/gateway#connections */
|
58
46
|
connect() {
|
59
47
|
this.ws.on("open", () => this.onWebSocketOpen());
|
@@ -61,54 +49,46 @@ class Shard {
|
|
61
49
|
this.ws.on("error", (err) => this.onWebSocketError(err));
|
62
50
|
this.ws.on("close", (code, reason) => this.onWebSocketClose(code, reason));
|
63
51
|
}
|
52
|
+
/** https://discord.com/developers/docs/topics/gateway#connections */
|
64
53
|
disconnect() {
|
65
54
|
if (this.heartbeatInterval) {
|
66
55
|
clearInterval(this.heartbeatInterval);
|
67
56
|
this.heartbeatInterval = null;
|
68
57
|
}
|
69
58
|
}
|
70
|
-
|
59
|
+
/** https://discord.com/developers/docs/topics/gateway-events#heartbeat */
|
60
|
+
heartbeat(lastSequence) {
|
61
|
+
this.ws.send(JSON.stringify({
|
62
|
+
op: constants_1.GatewayOPCodes.Heartbeat,
|
63
|
+
d: lastSequence,
|
64
|
+
}));
|
65
|
+
}
|
66
|
+
/** https://discord.com/developers/docs/topics/gateway-events#identify */
|
67
|
+
identify(options) {
|
71
68
|
this.ws.send(JSON.stringify({
|
72
69
|
op: constants_1.GatewayOPCodes.Identify,
|
73
70
|
d: {
|
74
|
-
token:
|
75
|
-
shard: [this.id, this.client.shardsCount],
|
76
|
-
intents: this.client.intents,
|
71
|
+
token: options.token,
|
77
72
|
properties: {
|
78
|
-
os:
|
79
|
-
browser:
|
80
|
-
device:
|
73
|
+
os: options.properties.os,
|
74
|
+
browser: options.properties.browser,
|
75
|
+
device: options.properties.device,
|
81
76
|
},
|
77
|
+
compress: options.compress,
|
78
|
+
large_threshold: options.largeThreshold,
|
79
|
+
shard: options.shard,
|
80
|
+
presence: options.presence,
|
81
|
+
intents: options.intents,
|
82
82
|
},
|
83
83
|
}));
|
84
84
|
}
|
85
|
-
|
86
|
-
|
87
|
-
switch (packet.op) {
|
88
|
-
case constants_1.GatewayOPCodes.Reconnect:
|
89
|
-
this.client.emit(constants_1.GatewayEvents.Reconnect);
|
90
|
-
break;
|
91
|
-
case constants_1.GatewayOPCodes.InvalidSession:
|
92
|
-
this.client.emit(constants_1.GatewayEvents.InvalidSession);
|
93
|
-
break;
|
94
|
-
case constants_1.GatewayOPCodes.Hello:
|
95
|
-
{
|
96
|
-
this.heartbeatInterval = setInterval(() => {
|
97
|
-
this.ws.send(JSON.stringify({
|
98
|
-
op: constants_1.GatewayOPCodes.Heartbeat,
|
99
|
-
d: null,
|
100
|
-
}));
|
101
|
-
}, packet.d.heartbeat_interval);
|
102
|
-
this.client.emit(constants_1.GatewayEvents.Hello);
|
103
|
-
}
|
104
|
-
break;
|
105
|
-
}
|
85
|
+
onDispatch(packet) {
|
86
|
+
this.client.emit(constants_1.GatewayEvents.Dispatch, packet);
|
106
87
|
switch (packet.t) {
|
107
88
|
case "READY":
|
108
89
|
{
|
109
90
|
this.sessionId = packet.d.session_id;
|
110
91
|
this.client.user = this.client.util.userFromRaw(packet.d.user);
|
111
|
-
this.client.guilds = new Map();
|
112
92
|
this.client.application = packet.d.application;
|
113
93
|
this.client.emit(constants_1.GatewayEvents.Ready);
|
114
94
|
}
|
@@ -511,6 +491,38 @@ class Shard {
|
|
511
491
|
break;
|
512
492
|
}
|
513
493
|
}
|
494
|
+
onWebSocketOpen() {
|
495
|
+
this.identify({
|
496
|
+
token: this.client.token,
|
497
|
+
shard: [this.id, this.client.shardsCount],
|
498
|
+
intents: this.client.intents,
|
499
|
+
properties: {
|
500
|
+
os: process.platform,
|
501
|
+
browser: pkg.name,
|
502
|
+
device: pkg.name,
|
503
|
+
},
|
504
|
+
});
|
505
|
+
}
|
506
|
+
onWebSocketMessage(data) {
|
507
|
+
const packet = JSON.parse(data.toString());
|
508
|
+
switch (packet.op) {
|
509
|
+
case constants_1.GatewayOPCodes.Dispatch:
|
510
|
+
this.onDispatch(packet);
|
511
|
+
break;
|
512
|
+
case constants_1.GatewayOPCodes.Reconnect:
|
513
|
+
this.client.emit(constants_1.GatewayEvents.Reconnect);
|
514
|
+
break;
|
515
|
+
case constants_1.GatewayOPCodes.InvalidSession:
|
516
|
+
this.client.emit(constants_1.GatewayEvents.InvalidSession);
|
517
|
+
break;
|
518
|
+
case constants_1.GatewayOPCodes.Hello:
|
519
|
+
{
|
520
|
+
this.heartbeatInterval = setInterval(() => this.heartbeat(null), packet.d.heartbeat_interval);
|
521
|
+
this.client.emit(constants_1.GatewayEvents.Hello);
|
522
|
+
}
|
523
|
+
break;
|
524
|
+
}
|
525
|
+
}
|
514
526
|
onWebSocketError(err) {
|
515
527
|
throw err;
|
516
528
|
}
|
@@ -519,5 +531,42 @@ class Shard {
|
|
519
531
|
return;
|
520
532
|
throw new utils_1.GatewayError(`[${code}] ${reason}`);
|
521
533
|
}
|
534
|
+
/** https://discord.com/developers/docs/topics/gateway-events#request-guild-members */
|
535
|
+
requestGuildMembers(options) {
|
536
|
+
this.ws.send(JSON.stringify({
|
537
|
+
op: constants_1.GatewayOPCodes.RequestGuildMembers,
|
538
|
+
d: {
|
539
|
+
guild_id: options.guildId,
|
540
|
+
query: options.query,
|
541
|
+
limit: options.limit,
|
542
|
+
presences: options.presences,
|
543
|
+
user_ids: options.userIds,
|
544
|
+
nonce: options.nonce,
|
545
|
+
},
|
546
|
+
}));
|
547
|
+
}
|
548
|
+
/** https://discord.com/developers/docs/topics/gateway-events#resume */
|
549
|
+
resume(options) {
|
550
|
+
this.ws.send(JSON.stringify({
|
551
|
+
op: constants_1.GatewayOPCodes.Resume,
|
552
|
+
d: {
|
553
|
+
token: options.token,
|
554
|
+
session_id: options.sessionId,
|
555
|
+
seq: options.seq,
|
556
|
+
},
|
557
|
+
}));
|
558
|
+
}
|
559
|
+
/** https://discord.com/developers/docs/topics/gateway-events#update-presence */
|
560
|
+
updatePresence(options) {
|
561
|
+
this.ws.send(JSON.stringify({
|
562
|
+
op: constants_1.GatewayOPCodes.PresenceUpdate,
|
563
|
+
d: {
|
564
|
+
since: options.status === constants_1.StatusTypes.Idle ? Date.now() : null,
|
565
|
+
activities: options.activities,
|
566
|
+
status: options.status ?? constants_1.StatusTypes.Online,
|
567
|
+
afk: !!options.afk,
|
568
|
+
},
|
569
|
+
}));
|
570
|
+
}
|
522
571
|
}
|
523
572
|
exports.Shard = Shard;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { ActivityFlags, ActivityType, GuildMemberFlags, InviteTargetTypes, ReactionTypes, StatusTypes, TriggerTypes } from "../constants";
|
1
|
+
import type { ActivityFlags, ActivityType, GatewayIntents, GatewayOPCodes, GuildMemberFlags, InviteTargetTypes, ReactionTypes, StatusTypes, TriggerTypes } from "../constants";
|
2
2
|
import type { RawApplication, Application } from "./application";
|
3
3
|
import type { RawAutoModerationAction, AutoModerationAction } from "./auto-moderation";
|
4
4
|
import type { RawChannel, RawThreadMember, Channel, ThreadMember } from "./channel";
|
@@ -9,6 +9,51 @@ import type { RawGuildScheduledEvent, GuildScheduledEvent } from "./guild-schedu
|
|
9
9
|
import type { RawStageInstance, StageInstance } from "./stage-instance";
|
10
10
|
import type { RawUser, RawAvatarDecorationData, User, AvatarDecorationData } from "./user";
|
11
11
|
import type { RawVoiceState, VoiceState } from "./voice";
|
12
|
+
/** https://discord.com/developers/docs/topics/gateway-events#payload-structure */
|
13
|
+
export interface RawPayload {
|
14
|
+
op: GatewayOPCodes;
|
15
|
+
d: any | null;
|
16
|
+
s: number | null;
|
17
|
+
t: string | null;
|
18
|
+
}
|
19
|
+
/** https://discord.com/developers/docs/topics/gateway-events#identify-identify-structure */
|
20
|
+
export interface RawIdentify {
|
21
|
+
token: string;
|
22
|
+
properties: RawIdentifyConnectionProperties;
|
23
|
+
compress?: boolean;
|
24
|
+
large_threshold?: number;
|
25
|
+
shard?: [number, number];
|
26
|
+
presence?: RawGatewayPresenceUpdate;
|
27
|
+
intents: GatewayIntents;
|
28
|
+
}
|
29
|
+
/** https://discord.com/developers/docs/topics/gateway-events#identify-identify-connection-properties */
|
30
|
+
export interface RawIdentifyConnectionProperties {
|
31
|
+
os: string;
|
32
|
+
browser: string;
|
33
|
+
device: string;
|
34
|
+
}
|
35
|
+
/** https://discord.com/developers/docs/topics/gateway-events#resume-resume-structure */
|
36
|
+
export interface RawResume {
|
37
|
+
token: string;
|
38
|
+
session_id: string;
|
39
|
+
seq: number;
|
40
|
+
}
|
41
|
+
/** https://discord.com/developers/docs/topics/gateway-events#request-guild-members-request-guild-members-structure */
|
42
|
+
export interface RawRequestGuildMembers {
|
43
|
+
guild_id: snowflake;
|
44
|
+
query?: string;
|
45
|
+
limit?: number;
|
46
|
+
presences?: boolean;
|
47
|
+
user_ids?: snowflake | Array<snowflake>;
|
48
|
+
nonce?: string;
|
49
|
+
}
|
50
|
+
/** https://discord.com/developers/docs/topics/gateway-events#update-presence-gateway-presence-update-structure */
|
51
|
+
export interface RawGatewayPresenceUpdate {
|
52
|
+
since: number | null;
|
53
|
+
activities: Array<Pick<RawActivity, "name" | "type" | "url" | "state">>;
|
54
|
+
status: StatusTypes;
|
55
|
+
afk: boolean;
|
56
|
+
}
|
12
57
|
/** https://discord.com/developers/docs/topics/gateway-events#auto-moderation-action-execution-auto-moderation-action-execution-event-fields */
|
13
58
|
export interface RawAutoModerationActionExectionEventFields {
|
14
59
|
guild_id: snowflake;
|
@@ -293,6 +338,45 @@ export interface RawMessagePollVoteRemoveFields {
|
|
293
338
|
guild_id?: snowflake;
|
294
339
|
answer_id: number;
|
295
340
|
}
|
341
|
+
export interface Payload {
|
342
|
+
op: GatewayOPCodes;
|
343
|
+
d: any | null;
|
344
|
+
s: number | null;
|
345
|
+
t: string | null;
|
346
|
+
}
|
347
|
+
export interface Identify {
|
348
|
+
token: string;
|
349
|
+
properties: IdentifyConnectionProperties;
|
350
|
+
compress?: boolean;
|
351
|
+
largeThreshold?: number;
|
352
|
+
shard?: [number, number];
|
353
|
+
presence?: GatewayPresenceUpdate;
|
354
|
+
intents: GatewayIntents;
|
355
|
+
}
|
356
|
+
export interface IdentifyConnectionProperties {
|
357
|
+
os: string;
|
358
|
+
browser: string;
|
359
|
+
device: string;
|
360
|
+
}
|
361
|
+
export interface Resume {
|
362
|
+
token: string;
|
363
|
+
sessionId: string;
|
364
|
+
seq: number;
|
365
|
+
}
|
366
|
+
export interface RequestGuildMembers {
|
367
|
+
guildId: snowflake;
|
368
|
+
query?: string;
|
369
|
+
limit?: number;
|
370
|
+
presences?: boolean;
|
371
|
+
userIds?: snowflake | Array<snowflake>;
|
372
|
+
nonce?: string;
|
373
|
+
}
|
374
|
+
export interface GatewayPresenceUpdate {
|
375
|
+
since: number | null;
|
376
|
+
activities: Array<Pick<Activity, "name" | "type" | "url" | "state">>;
|
377
|
+
status: StatusTypes;
|
378
|
+
afk: boolean;
|
379
|
+
}
|
296
380
|
export interface AutoModerationActionExecutionEventFields {
|
297
381
|
guildId: snowflake;
|
298
382
|
action: AutoModerationAction;
|
package/dist/package.json
CHANGED