disgroove 2.2.1-dev.d0eed5e → 2.2.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 +3 -1
- package/dist/lib/Client.d.ts +222 -220
- package/dist/lib/Client.js +412 -415
- package/dist/lib/constants.d.ts +4 -4
- package/dist/lib/constants.js +4 -4
- package/dist/lib/gateway/Shard.d.ts +4 -2
- package/dist/lib/gateway/Shard.js +94 -74
- package/dist/lib/gateway/ShardManager.d.ts +6 -1
- package/dist/lib/gateway/ShardManager.js +6 -0
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js +1 -0
- package/dist/lib/rest/CDN.d.ts +20 -20
- package/dist/lib/rest/CDN.js +20 -20
- package/dist/lib/rest/Endpoints.d.ts +81 -81
- package/dist/lib/rest/Endpoints.js +91 -91
- package/dist/lib/types/application-command.d.ts +4 -4
- package/dist/lib/types/application.d.ts +2 -2
- package/dist/lib/types/audit-log.d.ts +5 -5
- package/dist/lib/types/auto-moderation.d.ts +3 -3
- package/dist/lib/types/channel.d.ts +23 -21
- package/dist/lib/types/entitlements.d.ts +6 -6
- package/dist/lib/types/gateway-events.d.ts +83 -70
- package/dist/lib/types/guild-scheduled-event.d.ts +5 -5
- package/dist/lib/types/guild-template.d.ts +2 -2
- package/dist/lib/types/guild.d.ts +17 -17
- package/dist/lib/types/interaction.d.ts +8 -8
- package/dist/lib/types/message-components.d.ts +4 -4
- package/dist/lib/types/poll.d.ts +1 -1
- package/dist/lib/types/role.d.ts +3 -3
- package/dist/lib/types/sku.d.ts +2 -2
- package/dist/lib/types/stage-instance.d.ts +3 -3
- package/dist/lib/types/sticker.d.ts +5 -5
- package/dist/lib/types/team.d.ts +2 -2
- package/dist/lib/types/user.d.ts +1 -1
- package/dist/lib/types/voice-connections.d.ts +64 -0
- package/dist/lib/types/voice-connections.js +2 -0
- package/dist/lib/types/voice.d.ts +4 -4
- package/dist/lib/types/webhook.d.ts +3 -3
- package/dist/lib/utils/Util.d.ts +2 -2
- package/dist/lib/utils/Util.js +195 -193
- package/dist/lib/voice/VoiceConnection.d.ts +57 -0
- package/dist/lib/voice/VoiceConnection.js +150 -0
- package/dist/lib/voice/VoiceConnectionManager.d.ts +19 -0
- package/dist/lib/voice/VoiceConnectionManager.js +66 -0
- package/dist/lib/voice/index.d.ts +2 -0
- package/dist/lib/voice/index.js +18 -0
- package/dist/package.json +3 -3
- package/package.json +3 -3
@@ -0,0 +1,57 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
import WebSocket from "ws";
|
3
|
+
import type { snowflake } from "../types/common";
|
4
|
+
import EventEmitter from "node:events";
|
5
|
+
import type { ResumeConnectionPayload, SelectProtocolPayload, SessionDescriptionPayload, VoiceIdentifyPayload, VoiceReadyPayload } from "../types/voice-connections";
|
6
|
+
export declare class VoiceConnection extends EventEmitter {
|
7
|
+
ws: WebSocket;
|
8
|
+
endpoint: string;
|
9
|
+
serverID: snowflake;
|
10
|
+
userID: snowflake;
|
11
|
+
sessionID: string;
|
12
|
+
token: string;
|
13
|
+
private heartbeatInterval;
|
14
|
+
ssrc: number;
|
15
|
+
constructor(endpoint: string, options: VoiceIdentifyPayload);
|
16
|
+
/** https://discord.com/developers/docs/topics/voice-connections#connecting-to-voice */
|
17
|
+
connect(): void;
|
18
|
+
/** https://discord.com/developers/docs/topics/gateway#connections */
|
19
|
+
disconnect(): void;
|
20
|
+
/** https://discord.com/developers/docs/topics/voice-connections#heartbeating */
|
21
|
+
heartbeat(): void;
|
22
|
+
/** https://discord.com/developers/docs/topics/voice-connections#establishing-a-voice-websocket-connection-example-voice-identify-payload */
|
23
|
+
identify(options: VoiceIdentifyPayload): void;
|
24
|
+
private onWebSocketOpen;
|
25
|
+
private onWebSocketMessage;
|
26
|
+
private onWebSocketError;
|
27
|
+
private onWebSocketClose;
|
28
|
+
/** https://discord.com/developers/docs/topics/voice-connections#resuming-voice-connection */
|
29
|
+
resume(options: ResumeConnectionPayload): void;
|
30
|
+
/** https://discord.com/developers/docs/topics/voice-connections#establishing-a-voice-udp-connection */
|
31
|
+
selectProtocol(options: SelectProtocolPayload): void;
|
32
|
+
/** https://discord.com/developers/docs/topics/voice-connections#speaking */
|
33
|
+
speaking(speaking: number): void;
|
34
|
+
}
|
35
|
+
export declare interface VoiceConnection extends EventEmitter {
|
36
|
+
addListener<K extends keyof VoiceConnectionEvents>(eventName: K, listener: (...args: VoiceConnectionEvents[K]) => void): this;
|
37
|
+
emit<K extends keyof VoiceConnectionEvents>(eventName: K, ...args: VoiceConnectionEvents[K]): boolean;
|
38
|
+
listenerCount(eventName: keyof VoiceConnectionEvents): number;
|
39
|
+
listeners(eventName: keyof VoiceConnectionEvents): Array<Function>;
|
40
|
+
off<K extends keyof VoiceConnectionEvents>(eventName: K, listener: (...args: VoiceConnectionEvents[K]) => void): this;
|
41
|
+
on<K extends keyof VoiceConnectionEvents>(eventName: K, listener: (...args: VoiceConnectionEvents[K]) => void): this;
|
42
|
+
once<K extends keyof VoiceConnectionEvents>(eventName: K, listener: (...args: VoiceConnectionEvents[K]) => void): this;
|
43
|
+
prependListener<K extends keyof VoiceConnectionEvents>(eventName: K, listener: (...args: VoiceConnectionEvents[K]) => void): this;
|
44
|
+
prependOnceListener<K extends keyof VoiceConnectionEvents>(eventName: K, listener: (...args: VoiceConnectionEvents[K]) => void): this;
|
45
|
+
rawListeners(eventName: keyof VoiceConnectionEvents): Array<Function>;
|
46
|
+
removeAllListeners(event?: keyof VoiceConnectionEvents): this;
|
47
|
+
removeListener<K extends keyof VoiceConnectionEvents>(eventName: K, listener: (...args: VoiceConnectionEvents[K]) => void): this;
|
48
|
+
}
|
49
|
+
export interface VoiceConnectionEvents {
|
50
|
+
ready: [voiceServer: VoiceReadyPayload];
|
51
|
+
sessionDescription: [session: SessionDescriptionPayload];
|
52
|
+
speaking: [speaking: number];
|
53
|
+
heartbeatACK: [heartbeat: number];
|
54
|
+
hello: [];
|
55
|
+
resumed: [];
|
56
|
+
clientDisconnect: [];
|
57
|
+
}
|
@@ -0,0 +1,150 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.VoiceConnection = void 0;
|
7
|
+
const ws_1 = __importDefault(require("ws"));
|
8
|
+
const constants_1 = require("../constants");
|
9
|
+
const utils_1 = require("../utils");
|
10
|
+
const node_events_1 = __importDefault(require("node:events"));
|
11
|
+
class VoiceConnection extends node_events_1.default {
|
12
|
+
ws;
|
13
|
+
endpoint;
|
14
|
+
serverID;
|
15
|
+
userID;
|
16
|
+
sessionID;
|
17
|
+
token;
|
18
|
+
heartbeatInterval;
|
19
|
+
ssrc;
|
20
|
+
constructor(endpoint, options) {
|
21
|
+
super();
|
22
|
+
this.ws = new ws_1.default(`wss://${endpoint}?v=4`);
|
23
|
+
this.endpoint = endpoint;
|
24
|
+
this.serverID = options.serverID;
|
25
|
+
this.userID = options.userID;
|
26
|
+
this.sessionID = options.sessionID;
|
27
|
+
this.token = options.token;
|
28
|
+
}
|
29
|
+
/** https://discord.com/developers/docs/topics/voice-connections#connecting-to-voice */
|
30
|
+
connect() {
|
31
|
+
this.ws.on("open", () => this.onWebSocketOpen());
|
32
|
+
this.ws.on("message", (data) => this.onWebSocketMessage(data));
|
33
|
+
this.ws.on("error", (err) => this.onWebSocketError(err));
|
34
|
+
this.ws.on("close", (code, reason) => this.onWebSocketClose(code, reason));
|
35
|
+
}
|
36
|
+
/** https://discord.com/developers/docs/topics/gateway#connections */
|
37
|
+
disconnect() {
|
38
|
+
if (this.heartbeatInterval) {
|
39
|
+
clearInterval(this.heartbeatInterval);
|
40
|
+
this.heartbeatInterval = null;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
/** https://discord.com/developers/docs/topics/voice-connections#heartbeating */
|
44
|
+
heartbeat() {
|
45
|
+
this.ws.send(JSON.stringify({
|
46
|
+
op: constants_1.VoiceOPCodes.Heartbeat,
|
47
|
+
d: Date.now(),
|
48
|
+
}));
|
49
|
+
}
|
50
|
+
/** https://discord.com/developers/docs/topics/voice-connections#establishing-a-voice-websocket-connection-example-voice-identify-payload */
|
51
|
+
identify(options) {
|
52
|
+
this.ws.send(JSON.stringify({
|
53
|
+
op: constants_1.VoiceOPCodes.Identify,
|
54
|
+
d: {
|
55
|
+
server_id: options.serverID,
|
56
|
+
user_id: options.userID,
|
57
|
+
session_id: options.sessionID,
|
58
|
+
token: options.token,
|
59
|
+
},
|
60
|
+
}));
|
61
|
+
}
|
62
|
+
onWebSocketOpen() {
|
63
|
+
this.identify({
|
64
|
+
serverID: this.serverID,
|
65
|
+
userID: this.userID,
|
66
|
+
sessionID: this.sessionID,
|
67
|
+
token: this.token,
|
68
|
+
});
|
69
|
+
}
|
70
|
+
onWebSocketMessage(data) {
|
71
|
+
const packet = JSON.parse(data.toString());
|
72
|
+
switch (packet.op) {
|
73
|
+
case constants_1.VoiceOPCodes.Ready:
|
74
|
+
{
|
75
|
+
this.ssrc = packet.d.ssrc;
|
76
|
+
this.emit("ready", {
|
77
|
+
ssrc: packet.d.ssrc,
|
78
|
+
ip: packet.d.ip,
|
79
|
+
port: packet.d.port,
|
80
|
+
modes: packet.d.modes,
|
81
|
+
});
|
82
|
+
}
|
83
|
+
break;
|
84
|
+
case constants_1.VoiceOPCodes.SessionDescription:
|
85
|
+
this.emit("sessionDescription", {
|
86
|
+
mode: packet.d.mode,
|
87
|
+
secretKey: packet.d.secret_key,
|
88
|
+
});
|
89
|
+
break;
|
90
|
+
case constants_1.VoiceOPCodes.Speaking:
|
91
|
+
this.emit("speaking", packet.d.speaking);
|
92
|
+
break;
|
93
|
+
case constants_1.VoiceOPCodes.HeartbeatACK:
|
94
|
+
this.emit("heartbeatACK", packet.d);
|
95
|
+
break;
|
96
|
+
case constants_1.VoiceOPCodes.Hello:
|
97
|
+
{
|
98
|
+
this.heartbeatInterval = setInterval(() => this.heartbeat(), packet.d.heartbeat_interval);
|
99
|
+
this.emit("hello");
|
100
|
+
}
|
101
|
+
break;
|
102
|
+
case constants_1.VoiceOPCodes.Resumed:
|
103
|
+
this.emit("resumed");
|
104
|
+
break;
|
105
|
+
case constants_1.VoiceOPCodes.ClientDisconnect:
|
106
|
+
this.emit("clientDisconnect");
|
107
|
+
break;
|
108
|
+
}
|
109
|
+
}
|
110
|
+
onWebSocketError(err) {
|
111
|
+
throw err;
|
112
|
+
}
|
113
|
+
onWebSocketClose(code, reason) {
|
114
|
+
if (code === 1000)
|
115
|
+
return;
|
116
|
+
if (code === constants_1.VoiceCloseEventCodes.Disconnect)
|
117
|
+
return this.disconnect();
|
118
|
+
throw new utils_1.GatewayError(`[${code}] ${reason}`);
|
119
|
+
}
|
120
|
+
/** https://discord.com/developers/docs/topics/voice-connections#resuming-voice-connection */
|
121
|
+
resume(options) {
|
122
|
+
this.ws.send(JSON.stringify({
|
123
|
+
op: constants_1.VoiceOPCodes.Resume,
|
124
|
+
d: {
|
125
|
+
server_id: options.serverID,
|
126
|
+
session_id: options.sessionID,
|
127
|
+
token: options.token,
|
128
|
+
},
|
129
|
+
}));
|
130
|
+
}
|
131
|
+
/** https://discord.com/developers/docs/topics/voice-connections#establishing-a-voice-udp-connection */
|
132
|
+
selectProtocol(options) {
|
133
|
+
this.ws.send(JSON.stringify({
|
134
|
+
op: constants_1.VoiceOPCodes.SelectProtocol,
|
135
|
+
d: options,
|
136
|
+
}));
|
137
|
+
}
|
138
|
+
/** https://discord.com/developers/docs/topics/voice-connections#speaking */
|
139
|
+
speaking(speaking) {
|
140
|
+
this.ws.send(JSON.stringify({
|
141
|
+
op: constants_1.VoiceOPCodes.Speaking,
|
142
|
+
d: {
|
143
|
+
speaking,
|
144
|
+
delay: 0,
|
145
|
+
ssrc: this.ssrc,
|
146
|
+
},
|
147
|
+
}));
|
148
|
+
}
|
149
|
+
}
|
150
|
+
exports.VoiceConnection = VoiceConnection;
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import type { snowflake } from "../types/common";
|
2
|
+
import type { ResumeConnectionPayload, SelectProtocolPayload, VoiceIdentifyPayload } from "../types/voice-connections";
|
3
|
+
import { VoiceConnection } from ".";
|
4
|
+
export declare class VoiceConnectionManager extends Map<snowflake, VoiceConnection> {
|
5
|
+
/** https://discord.com/developers/docs/topics/voice-connections#connecting-to-voice */
|
6
|
+
connect(endpoint: string, options: VoiceIdentifyPayload): VoiceConnection;
|
7
|
+
/** https://discord.com/developers/docs/topics/gateway#connections */
|
8
|
+
disconnect(guildID: snowflake): void;
|
9
|
+
/** https://discord.com/developers/docs/topics/voice-connections#heartbeating */
|
10
|
+
heartbeat(guildID: snowflake): void;
|
11
|
+
/** https://discord.com/developers/docs/topics/voice-connections#establishing-a-voice-websocket-connection-example-voice-identify-payload */
|
12
|
+
identify(guildID: snowflake, options: VoiceIdentifyPayload): void;
|
13
|
+
/** https://discord.com/developers/docs/topics/voice-connections#resuming-voice-connection */
|
14
|
+
resume(guildID: snowflake, options: ResumeConnectionPayload): void;
|
15
|
+
/** https://discord.com/developers/docs/topics/voice-connections#establishing-a-voice-udp-connection */
|
16
|
+
selectProtocol(guildID: snowflake, options: SelectProtocolPayload): void;
|
17
|
+
/** https://discord.com/developers/docs/topics/voice-connections#speaking */
|
18
|
+
speaking(guildID: snowflake, speaking: number): void;
|
19
|
+
}
|
@@ -0,0 +1,66 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.VoiceConnectionManager = void 0;
|
4
|
+
const _1 = require(".");
|
5
|
+
class VoiceConnectionManager extends Map {
|
6
|
+
/** https://discord.com/developers/docs/topics/voice-connections#connecting-to-voice */
|
7
|
+
connect(endpoint, options) {
|
8
|
+
let voiceConnection = new _1.VoiceConnection(endpoint, options);
|
9
|
+
if (!this.has(options.serverID)) {
|
10
|
+
this.set(options.serverID, voiceConnection);
|
11
|
+
voiceConnection.connect();
|
12
|
+
}
|
13
|
+
else {
|
14
|
+
this.disconnect(options.serverID);
|
15
|
+
this.set(options.serverID, voiceConnection);
|
16
|
+
}
|
17
|
+
return voiceConnection;
|
18
|
+
}
|
19
|
+
/** https://discord.com/developers/docs/topics/gateway#connections */
|
20
|
+
disconnect(guildID) {
|
21
|
+
if (this.has(guildID)) {
|
22
|
+
this.get(guildID).disconnect();
|
23
|
+
this.delete(guildID);
|
24
|
+
}
|
25
|
+
}
|
26
|
+
/** https://discord.com/developers/docs/topics/voice-connections#heartbeating */
|
27
|
+
heartbeat(guildID) {
|
28
|
+
if (this.has(guildID)) {
|
29
|
+
this.get(guildID).heartbeat();
|
30
|
+
}
|
31
|
+
}
|
32
|
+
/** https://discord.com/developers/docs/topics/voice-connections#establishing-a-voice-websocket-connection-example-voice-identify-payload */
|
33
|
+
identify(guildID, options) {
|
34
|
+
if (this.has(guildID)) {
|
35
|
+
this.get(guildID).identify({
|
36
|
+
serverID: options.serverID,
|
37
|
+
userID: options.userID,
|
38
|
+
sessionID: options.sessionID,
|
39
|
+
token: options.token,
|
40
|
+
});
|
41
|
+
}
|
42
|
+
}
|
43
|
+
/** https://discord.com/developers/docs/topics/voice-connections#resuming-voice-connection */
|
44
|
+
resume(guildID, options) {
|
45
|
+
if (this.has(guildID)) {
|
46
|
+
this.get(guildID).resume({
|
47
|
+
serverID: options.serverID,
|
48
|
+
sessionID: options.sessionID,
|
49
|
+
token: options.token,
|
50
|
+
});
|
51
|
+
}
|
52
|
+
}
|
53
|
+
/** https://discord.com/developers/docs/topics/voice-connections#establishing-a-voice-udp-connection */
|
54
|
+
selectProtocol(guildID, options) {
|
55
|
+
if (this.has(guildID)) {
|
56
|
+
this.get(guildID).selectProtocol(options);
|
57
|
+
}
|
58
|
+
}
|
59
|
+
/** https://discord.com/developers/docs/topics/voice-connections#speaking */
|
60
|
+
speaking(guildID, speaking) {
|
61
|
+
if (this.has(guildID)) {
|
62
|
+
this.get(guildID).speaking(speaking);
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
exports.VoiceConnectionManager = VoiceConnectionManager;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./VoiceConnection"), exports);
|
18
|
+
__exportStar(require("./VoiceConnectionManager"), exports);
|
package/dist/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "disgroove",
|
3
|
-
"version": "2.2.1
|
3
|
+
"version": "2.2.1",
|
4
4
|
"description": "A module to interface with Discord",
|
5
5
|
"main": "./dist/lib/index.js",
|
6
6
|
"types": "./dist/lib/index.d.ts",
|
@@ -25,9 +25,9 @@
|
|
25
25
|
},
|
26
26
|
"homepage": "https://github.com/XenKys/disgroove#readme",
|
27
27
|
"devDependencies": {
|
28
|
-
"@types/node": "^20.14.
|
28
|
+
"@types/node": "^20.14.9",
|
29
29
|
"@types/ws": "^8.5.10",
|
30
|
-
"typescript": "^5.5.
|
30
|
+
"typescript": "^5.5.3"
|
31
31
|
},
|
32
32
|
"dependencies": {
|
33
33
|
"ws": "^8.17.1"
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "disgroove",
|
3
|
-
"version": "2.2.1
|
3
|
+
"version": "2.2.1",
|
4
4
|
"description": "A module to interface with Discord",
|
5
5
|
"main": "./dist/lib/index.js",
|
6
6
|
"types": "./dist/lib/index.d.ts",
|
@@ -25,9 +25,9 @@
|
|
25
25
|
},
|
26
26
|
"homepage": "https://github.com/XenKys/disgroove#readme",
|
27
27
|
"devDependencies": {
|
28
|
-
"@types/node": "^20.14.
|
28
|
+
"@types/node": "^20.14.9",
|
29
29
|
"@types/ws": "^8.5.10",
|
30
|
-
"typescript": "^5.5.
|
30
|
+
"typescript": "^5.5.3"
|
31
31
|
},
|
32
32
|
"dependencies": {
|
33
33
|
"ws": "^8.17.1"
|