lavacord 2.0.0 → 2.0.2
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/cloudstorm.js.map +1 -0
- package/dist/detritus.js.map +1 -0
- package/dist/discord.js.js.map +1 -0
- package/dist/eris.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/LavalinkNode.d.ts +105 -0
- package/dist/lib/LavalinkNode.js +240 -0
- package/dist/lib/LavalinkNode.js.map +1 -0
- package/dist/lib/Manager.d.ts +137 -0
- package/dist/lib/Manager.js +239 -0
- package/dist/lib/Manager.js.map +1 -0
- package/dist/lib/Player.d.ts +139 -0
- package/dist/lib/Player.js +202 -0
- package/dist/lib/Player.js.map +1 -0
- package/dist/lib/Rest.d.ts +63 -0
- package/dist/lib/Rest.js +117 -0
- package/dist/lib/Rest.js.map +1 -0
- package/dist/lib/Types.d.ts +177 -0
- package/dist/lib/Types.js +3 -0
- package/dist/lib/Types.js.map +1 -0
- package/dist/oceanic.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +19 -8
- package/cloudstorm.js.map +0 -1
- package/detritus.js.map +0 -1
- package/discord.js.js.map +0 -1
- package/eris.js.map +0 -1
- package/oceanic.js.map +0 -1
- /package/{cloudstorm.d.ts → dist/cloudstorm.d.ts} +0 -0
- /package/{cloudstorm.js → dist/cloudstorm.js} +0 -0
- /package/{detritus.d.ts → dist/detritus.d.ts} +0 -0
- /package/{detritus.js → dist/detritus.js} +0 -0
- /package/{discord.js.d.ts → dist/discord.js.d.ts} +0 -0
- /package/{discord.js.js → dist/discord.js.js} +0 -0
- /package/{eris.d.ts → dist/eris.d.ts} +0 -0
- /package/{eris.js → dist/eris.js} +0 -0
- /package/{oceanic.d.ts → dist/oceanic.d.ts} +0 -0
- /package/{oceanic.js → dist/oceanic.js} +0 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Manager = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
const LavalinkNode_1 = require("./LavalinkNode");
|
|
6
|
+
const Player_1 = require("./Player");
|
|
7
|
+
/**
|
|
8
|
+
* The class that handles everything to do with Lavalink. it is the hub of the library basically
|
|
9
|
+
*/
|
|
10
|
+
class Manager extends events_1.EventEmitter {
|
|
11
|
+
/**
|
|
12
|
+
* A [**Map**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) of Lavalink Nodes
|
|
13
|
+
*/
|
|
14
|
+
nodes = new Map();
|
|
15
|
+
/**
|
|
16
|
+
* A [**Map**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) of all the players
|
|
17
|
+
*/
|
|
18
|
+
players = new Map();
|
|
19
|
+
/**
|
|
20
|
+
* A [**Map**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) of all the VOICE_SERVER_UPDATE States
|
|
21
|
+
*/
|
|
22
|
+
voiceServers = new Map();
|
|
23
|
+
/**
|
|
24
|
+
* A [**Map**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) of all the VOICE_STATE_UPDATE States
|
|
25
|
+
*/
|
|
26
|
+
voiceStates = new Map();
|
|
27
|
+
/**
|
|
28
|
+
* The user id of the bot this Manager is managing
|
|
29
|
+
*/
|
|
30
|
+
user;
|
|
31
|
+
/**
|
|
32
|
+
* The send function needs for the library to function
|
|
33
|
+
*/
|
|
34
|
+
send;
|
|
35
|
+
/**
|
|
36
|
+
* The Player the manager will use when creating new Players
|
|
37
|
+
*/
|
|
38
|
+
Player = Player_1.Player;
|
|
39
|
+
/**
|
|
40
|
+
* An Set of all the expecting connections guild id's
|
|
41
|
+
*/
|
|
42
|
+
expecting = new Set();
|
|
43
|
+
/**
|
|
44
|
+
* The constructor of the Manager
|
|
45
|
+
* @param nodes A Array of {@link LavalinkNodeOptions} that the Manager will connect to
|
|
46
|
+
* @param options The options for the Manager {@link ManagerOptions}
|
|
47
|
+
*/
|
|
48
|
+
constructor(nodes, options) {
|
|
49
|
+
super();
|
|
50
|
+
if (options.user)
|
|
51
|
+
this.user = options.user;
|
|
52
|
+
if (options.player)
|
|
53
|
+
this.Player = options.player;
|
|
54
|
+
if (options.send)
|
|
55
|
+
this.send = options.send;
|
|
56
|
+
for (const node of nodes)
|
|
57
|
+
this.createNode(node);
|
|
58
|
+
setImmediate(() => {
|
|
59
|
+
if (this.send)
|
|
60
|
+
this.send = () => undefined;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Connects all the {@link LavalinkNode} to the respective Lavalink instance
|
|
65
|
+
*/
|
|
66
|
+
connect() {
|
|
67
|
+
return Promise.all([...this.nodes.values()].map(node => node.connect()));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Disconnects everything, basically destorying the manager.
|
|
71
|
+
* Stops all players, leaves all voice channels then disconnects all LavalinkNodes
|
|
72
|
+
*/
|
|
73
|
+
disconnect() {
|
|
74
|
+
const promises = [];
|
|
75
|
+
for (const id of [...this.players.keys()])
|
|
76
|
+
promises.push(this.leave(id));
|
|
77
|
+
for (const node of [...this.nodes.values()])
|
|
78
|
+
node.destroy();
|
|
79
|
+
return Promise.all(promises);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Creating a {@link LavalinkNode} and adds it to the the nodes Map
|
|
83
|
+
* @param options The node options of the node you're creating
|
|
84
|
+
*/
|
|
85
|
+
createNode(options) {
|
|
86
|
+
const node = new LavalinkNode_1.LavalinkNode(this, options);
|
|
87
|
+
this.nodes.set(options.id, node);
|
|
88
|
+
return node;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Disconnects and Deletes the specified node
|
|
92
|
+
* @param id The id of the node you want to remove
|
|
93
|
+
*/
|
|
94
|
+
removeNode(id) {
|
|
95
|
+
const node = this.nodes.get(id);
|
|
96
|
+
if (!node)
|
|
97
|
+
return false;
|
|
98
|
+
return node.destroy() && this.nodes.delete(id);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Connects the bot to the selected voice channel
|
|
102
|
+
* @param data The Join Data
|
|
103
|
+
* @param joinOptions Selfmute and Selfdeaf options, if you want the bot to be deafen or muted upon joining
|
|
104
|
+
*/
|
|
105
|
+
async join(data, joinOptions = {}) {
|
|
106
|
+
const player = this.players.get(data.guild);
|
|
107
|
+
if (player)
|
|
108
|
+
return player;
|
|
109
|
+
await this.sendWS(data.guild, data.channel, joinOptions);
|
|
110
|
+
return this.spawnPlayer(data);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Leaves the specified voice channel
|
|
114
|
+
* @param guild The guild you want the bot to leave the voice channel of
|
|
115
|
+
*/
|
|
116
|
+
async leave(guild) {
|
|
117
|
+
await this.sendWS(guild, null);
|
|
118
|
+
const player = this.players.get(guild);
|
|
119
|
+
if (!player)
|
|
120
|
+
return false;
|
|
121
|
+
if (player.listenerCount("end") && player.playing)
|
|
122
|
+
player.emit("end", { encodedTrack: player.track, op: "event", type: "TrackEndEvent", reason: "CLEANUP", guildId: guild });
|
|
123
|
+
player.removeAllListeners();
|
|
124
|
+
await player.destroy();
|
|
125
|
+
return this.players.delete(guild);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Switch a player from one node to another, this is to implement fallback
|
|
129
|
+
* @param player The player you want to switch nodes with
|
|
130
|
+
* @param node The node you want to switch to
|
|
131
|
+
*/
|
|
132
|
+
async switch(player, node) {
|
|
133
|
+
const { track, state, voiceUpdateState } = { ...player };
|
|
134
|
+
const position = state.position ? state.position + 2000 : 2000;
|
|
135
|
+
if (!voiceUpdateState) {
|
|
136
|
+
player.node = node;
|
|
137
|
+
return player;
|
|
138
|
+
}
|
|
139
|
+
await player.destroy();
|
|
140
|
+
player.node = node;
|
|
141
|
+
await player.play(track, {
|
|
142
|
+
position,
|
|
143
|
+
volume: state.filters.volume || 1.0,
|
|
144
|
+
filters: state.filters,
|
|
145
|
+
voice: {
|
|
146
|
+
token: voiceUpdateState.event.token,
|
|
147
|
+
endpoint: voiceUpdateState.event.endpoint,
|
|
148
|
+
sessionId: voiceUpdateState.sessionId
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
return player;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* For handling voiceServerUpdate from the user's library of choice
|
|
155
|
+
* @param data The data directly from discord
|
|
156
|
+
*/
|
|
157
|
+
voiceServerUpdate(data) {
|
|
158
|
+
this.voiceServers.set(data.guild_id, data);
|
|
159
|
+
this.expecting.add(data.guild_id);
|
|
160
|
+
return this._attemptConnection(data.guild_id);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* For handling voiceStateUpdate from the user's library of choice
|
|
164
|
+
* @param data The data directly from discord
|
|
165
|
+
*/
|
|
166
|
+
voiceStateUpdate(data) {
|
|
167
|
+
if (data.user_id !== this.user)
|
|
168
|
+
return Promise.resolve(false);
|
|
169
|
+
if (data.channel_id) {
|
|
170
|
+
this.voiceStates.set(data.guild_id, data);
|
|
171
|
+
return this._attemptConnection(data.guild_id);
|
|
172
|
+
}
|
|
173
|
+
this.voiceServers.delete(data.guild_id);
|
|
174
|
+
this.voiceStates.delete(data.guild_id);
|
|
175
|
+
return Promise.resolve(false);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Just a utility method to easily send OPCode 4 websocket events to discord
|
|
179
|
+
* @param guild The guild is
|
|
180
|
+
* @param channel Voice channel id, or null to leave a voice channel
|
|
181
|
+
* @param param2 Selfmute and Selfdeaf options, if you want the bot to be deafen or muted upon joining
|
|
182
|
+
*/
|
|
183
|
+
sendWS(guild, channel, { selfmute = false, selfdeaf = false } = {}) {
|
|
184
|
+
return this.send({
|
|
185
|
+
op: 4,
|
|
186
|
+
d: {
|
|
187
|
+
guild_id: guild,
|
|
188
|
+
channel_id: channel,
|
|
189
|
+
self_mute: selfmute,
|
|
190
|
+
self_deaf: selfdeaf
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Gets all connected nodes, sorts them by cou load of the node
|
|
196
|
+
*/
|
|
197
|
+
get idealNodes() {
|
|
198
|
+
return [...this.nodes.values()]
|
|
199
|
+
.filter(node => node.connected)
|
|
200
|
+
.sort((a, b) => {
|
|
201
|
+
const aload = a.stats.cpu ? a.stats.cpu.systemLoad / a.stats.cpu.cores * 100 : 0;
|
|
202
|
+
const bload = b.stats.cpu ? b.stats.cpu.systemLoad / b.stats.cpu.cores * 100 : 0;
|
|
203
|
+
return aload - bload;
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Handles the data of voiceServerUpdate & voiceStateUpdate to see if a connection is possible with the data we have and if it is then make the connection to lavalink
|
|
208
|
+
* @param guildId The guild id that we're trying to attempt to connect to
|
|
209
|
+
*/
|
|
210
|
+
async _attemptConnection(guildID) {
|
|
211
|
+
const server = this.voiceServers.get(guildID);
|
|
212
|
+
const state = this.voiceStates.get(guildID);
|
|
213
|
+
if (!server || !state || !this.expecting.has(guildID))
|
|
214
|
+
return false;
|
|
215
|
+
const player = this.players.get(guildID);
|
|
216
|
+
if (!player)
|
|
217
|
+
return false;
|
|
218
|
+
await player.connect({ sessionId: state.session_id, event: server });
|
|
219
|
+
this.expecting.delete(guildID);
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* This creates the {@link Player}
|
|
224
|
+
* @param data The Join Data, this is called by {@link Manager.join}
|
|
225
|
+
*/
|
|
226
|
+
spawnPlayer(data) {
|
|
227
|
+
const exists = this.players.get(data.guild);
|
|
228
|
+
if (exists)
|
|
229
|
+
return exists;
|
|
230
|
+
const node = this.nodes.get(data.node);
|
|
231
|
+
if (!node)
|
|
232
|
+
throw new Error(`INVALID_HOST: No available node with ${data.node}`);
|
|
233
|
+
const player = new this.Player(node, data.guild);
|
|
234
|
+
this.players.set(data.guild, player);
|
|
235
|
+
return player;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
exports.Manager = Manager;
|
|
239
|
+
//# sourceMappingURL=Manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Manager.js","sourceRoot":"","sources":["../../src/lib/Manager.ts"],"names":[],"mappings":";;;AAAA,mCAAsC;AACtC,iDAA8C;AAC9C,qCAAkC;AAIlC;;GAEG;AACH,MAAa,OAAQ,SAAQ,qBAAY;IAErC;;OAEG;IACI,KAAK,GAAG,IAAI,GAAG,EAAwB,CAAC;IAC/C;;OAEG;IACI,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC3C;;OAEG;IACI,YAAY,GAAG,IAAI,GAAG,EAA6B,CAAC;IAC3D;;OAEG;IACI,WAAW,GAAG,IAAI,GAAG,EAA4B,CAAC;IACzD;;OAEG;IACI,IAAI,CAAU;IACrB;;OAEG;IACI,IAAI,CAAsC;IACjD;;OAEG;IACK,MAAM,GAAkB,eAAM,CAAC;IACvC;;OAEG;IACK,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;IAE9B;;;;OAIG;IACH,YAAmB,KAAiC,EAAE,OAAuB;QACzE,KAAK,EAAE,CAAC;QAER,IAAI,OAAO,CAAC,IAAI;YAAE,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QAC3C,IAAI,OAAO,CAAC,MAAM;YAAE,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QACjD,IAAI,OAAO,CAAC,IAAI;YAAE,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QAE3C,KAAK,MAAM,IAAI,IAAI,KAAK;YAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAChD,YAAY,CAAC,GAAG,EAAE;YACd,IAAI,IAAI,CAAC,IAAI;g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,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACrC,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AA/OD,0BA+OC"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
import type { LavalinkNode } from "./LavalinkNode";
|
|
3
|
+
import type { Manager } from "./Manager";
|
|
4
|
+
import type { PlayerUpdateVoiceState, JoinOptions } from "./Types";
|
|
5
|
+
import type { EventOP, PlayerState, Equalizer, Filters, PlayerUpdate, UpdatePlayerData, UpdatePlayerResult, DestroyPlayerResult } from "lavalink-types";
|
|
6
|
+
/**
|
|
7
|
+
* The Player class, this handles everything to do with the guild sides of things, like playing, stoping, pausing, resuming etc
|
|
8
|
+
*/
|
|
9
|
+
export declare class Player extends EventEmitter {
|
|
10
|
+
node: LavalinkNode;
|
|
11
|
+
id: string;
|
|
12
|
+
/**
|
|
13
|
+
* The PlayerState of this Player
|
|
14
|
+
*/
|
|
15
|
+
state: Partial<PlayerState> & {
|
|
16
|
+
filters: Filters;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Whether or not the player is actually playing anything
|
|
20
|
+
*/
|
|
21
|
+
playing: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* When the track started playing
|
|
24
|
+
*/
|
|
25
|
+
timestamp: number | null;
|
|
26
|
+
/**
|
|
27
|
+
* Whether or not the song that is playing is paused or not
|
|
28
|
+
*/
|
|
29
|
+
paused: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* The current track in Lavalink's base64 string form
|
|
32
|
+
*/
|
|
33
|
+
track: string | null;
|
|
34
|
+
/**
|
|
35
|
+
* The voiceUpdateState of the player, used for swtiching nodes
|
|
36
|
+
*/
|
|
37
|
+
voiceUpdateState: PlayerUpdateVoiceState | null;
|
|
38
|
+
/**
|
|
39
|
+
* The constructor of the player
|
|
40
|
+
* @param node The Lavalink of the player
|
|
41
|
+
* @param id the id of the player, aka the guild id
|
|
42
|
+
*/
|
|
43
|
+
constructor(node: LavalinkNode, id: string);
|
|
44
|
+
/**
|
|
45
|
+
* Updates the current player on lavalink
|
|
46
|
+
* @param options Update options
|
|
47
|
+
* @param noReplace If the event should be dropped if there's a currently playing track should encodedTrack or identifier be present in options
|
|
48
|
+
*/
|
|
49
|
+
update(options: UpdatePlayerData, noReplace?: boolean): Promise<UpdatePlayerResult>;
|
|
50
|
+
/**
|
|
51
|
+
* Plays the specified song using the base64 string from lavalink
|
|
52
|
+
* @param track The base64 string of the song that you want to play
|
|
53
|
+
* @param options Play options
|
|
54
|
+
*/
|
|
55
|
+
play(track: string, options?: Omit<UpdatePlayerData, "encodedTrack" | "identifier"> & {
|
|
56
|
+
noReplace?: boolean;
|
|
57
|
+
}): Promise<UpdatePlayerResult>;
|
|
58
|
+
/**
|
|
59
|
+
* Stops the music, depending on how the end event is handled this will either stop
|
|
60
|
+
*/
|
|
61
|
+
stop(): Promise<UpdatePlayerData>;
|
|
62
|
+
/**
|
|
63
|
+
* Pauses/Resumes the song depending on what is specified
|
|
64
|
+
* @param pause Whether or not to pause whats currently playing
|
|
65
|
+
*/
|
|
66
|
+
pause(pause: boolean): Promise<UpdatePlayerData>;
|
|
67
|
+
/**
|
|
68
|
+
* Resumes the current song
|
|
69
|
+
*/
|
|
70
|
+
resume(): Promise<UpdatePlayerData>;
|
|
71
|
+
/**
|
|
72
|
+
* Changes the volume, only for the current song
|
|
73
|
+
* @param volume The volume as a float from 0.0 to 10.0. 1.0 is default.
|
|
74
|
+
*/
|
|
75
|
+
volume(volume: number): Promise<UpdatePlayerData>;
|
|
76
|
+
/**
|
|
77
|
+
* Seeks the current song to a certain position
|
|
78
|
+
* @param position Seeks the song to the position specified in milliseconds, use the duration of the song from lavalink to get the duration
|
|
79
|
+
*/
|
|
80
|
+
seek(position: number): Promise<UpdatePlayerData>;
|
|
81
|
+
filters(options: Filters): Promise<UpdatePlayerData>;
|
|
82
|
+
/**
|
|
83
|
+
* Sets the equalizer of the current song, if you wanted to do something like bassboost
|
|
84
|
+
* @param bands The bands that you want lavalink to modify read [IMPLEMENTATION.md](https://github.com/freyacodes/Lavalink/blob/master/IMPLEMENTATION.md#outgoing-messages) for more information
|
|
85
|
+
*/
|
|
86
|
+
equalizer(bands: Equalizer[]): Promise<UpdatePlayerData>;
|
|
87
|
+
/**
|
|
88
|
+
* Sends a destroy signal to lavalink, basically just a cleanup op for lavalink to clean its shit up
|
|
89
|
+
*/
|
|
90
|
+
destroy(): Promise<DestroyPlayerResult>;
|
|
91
|
+
/**
|
|
92
|
+
* Sends voiceUpdate information to lavalink so it can connect to discords voice servers properly
|
|
93
|
+
* @param data The data lavalink needs to connect and recieve data from discord
|
|
94
|
+
*/
|
|
95
|
+
connect(data: PlayerUpdateVoiceState): Promise<UpdatePlayerData>;
|
|
96
|
+
/**
|
|
97
|
+
* Use this to switch channels
|
|
98
|
+
* @param channel The channel id of the channel you want to switch to
|
|
99
|
+
* @param options selfMute and selfDeaf options
|
|
100
|
+
*/
|
|
101
|
+
switchChannel(channel: string, options?: JoinOptions): any;
|
|
102
|
+
/**
|
|
103
|
+
* The manager that created the player
|
|
104
|
+
*/
|
|
105
|
+
get manager(): Manager;
|
|
106
|
+
}
|
|
107
|
+
export interface PlayerEvents {
|
|
108
|
+
event: [EventOP];
|
|
109
|
+
start: [Extract<EventOP, {
|
|
110
|
+
type: "TrackStartEvent";
|
|
111
|
+
}>];
|
|
112
|
+
end: [Extract<EventOP, {
|
|
113
|
+
type: "TrackEndEvent" | "TrackStuckEvent";
|
|
114
|
+
}>];
|
|
115
|
+
pause: [boolean];
|
|
116
|
+
seek: [number];
|
|
117
|
+
error: [Extract<EventOP, {
|
|
118
|
+
type: "TrackExceptionEvent" | "WebSocketClosedEvent";
|
|
119
|
+
}>];
|
|
120
|
+
warn: [string];
|
|
121
|
+
volume: [number];
|
|
122
|
+
playerUpdate: [PlayerUpdate];
|
|
123
|
+
filters: [Filters];
|
|
124
|
+
}
|
|
125
|
+
export interface Player {
|
|
126
|
+
addListener<E extends keyof PlayerEvents>(event: E, listener: (...args: PlayerEvents[E]) => any): this;
|
|
127
|
+
emit<E extends keyof PlayerEvents>(event: E, ...args: PlayerEvents[E]): boolean;
|
|
128
|
+
eventNames(): Array<keyof PlayerEvents>;
|
|
129
|
+
listenerCount(event: keyof PlayerEvents): number;
|
|
130
|
+
listeners(event: keyof PlayerEvents): Array<(...args: Array<any>) => any>;
|
|
131
|
+
off<E extends keyof PlayerEvents>(event: E, listener: (...args: PlayerEvents[E]) => any): this;
|
|
132
|
+
on<E extends keyof PlayerEvents>(event: E, listener: (...args: PlayerEvents[E]) => any): this;
|
|
133
|
+
once<E extends keyof PlayerEvents>(event: E, listener: (...args: PlayerEvents[E]) => any): this;
|
|
134
|
+
prependListener<E extends keyof PlayerEvents>(event: E, listener: (...args: PlayerEvents[E]) => any): this;
|
|
135
|
+
prependOnceListener<E extends keyof PlayerEvents>(event: E, listener: (...args: PlayerEvents[E]) => any): this;
|
|
136
|
+
rawListeners(event: keyof PlayerEvents): Array<(...args: Array<any>) => any>;
|
|
137
|
+
removeAllListeners(event?: keyof PlayerEvents): this;
|
|
138
|
+
removeListener<E extends keyof PlayerEvents>(event: E, listener: (...args: PlayerEvents[E]) => any): this;
|
|
139
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Player = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
const Rest_1 = require("./Rest");
|
|
6
|
+
/**
|
|
7
|
+
* The Player class, this handles everything to do with the guild sides of things, like playing, stoping, pausing, resuming etc
|
|
8
|
+
*/
|
|
9
|
+
class Player extends events_1.EventEmitter {
|
|
10
|
+
node;
|
|
11
|
+
id;
|
|
12
|
+
/**
|
|
13
|
+
* The PlayerState of this Player
|
|
14
|
+
*/
|
|
15
|
+
state = { filters: {} };
|
|
16
|
+
/**
|
|
17
|
+
* Whether or not the player is actually playing anything
|
|
18
|
+
*/
|
|
19
|
+
playing = false;
|
|
20
|
+
/**
|
|
21
|
+
* When the track started playing
|
|
22
|
+
*/
|
|
23
|
+
timestamp = null;
|
|
24
|
+
/**
|
|
25
|
+
* Whether or not the song that is playing is paused or not
|
|
26
|
+
*/
|
|
27
|
+
paused = false;
|
|
28
|
+
/**
|
|
29
|
+
* The current track in Lavalink's base64 string form
|
|
30
|
+
*/
|
|
31
|
+
track = null;
|
|
32
|
+
/**
|
|
33
|
+
* The voiceUpdateState of the player, used for swtiching nodes
|
|
34
|
+
*/
|
|
35
|
+
voiceUpdateState = null;
|
|
36
|
+
/**
|
|
37
|
+
* The constructor of the player
|
|
38
|
+
* @param node The Lavalink of the player
|
|
39
|
+
* @param id the id of the player, aka the guild id
|
|
40
|
+
*/
|
|
41
|
+
constructor(node, id) {
|
|
42
|
+
super();
|
|
43
|
+
this.node = node;
|
|
44
|
+
this.id = id;
|
|
45
|
+
this.on("event", data => {
|
|
46
|
+
switch (data.type) {
|
|
47
|
+
case "TrackStartEvent":
|
|
48
|
+
if (this.listenerCount("start"))
|
|
49
|
+
this.emit("start", data);
|
|
50
|
+
break;
|
|
51
|
+
case "TrackEndEvent":
|
|
52
|
+
if (data.reason !== "REPLACED")
|
|
53
|
+
this.playing = false;
|
|
54
|
+
this.track = null;
|
|
55
|
+
this.timestamp = null;
|
|
56
|
+
if (this.listenerCount("end"))
|
|
57
|
+
this.emit("end", data);
|
|
58
|
+
break;
|
|
59
|
+
case "TrackExceptionEvent":
|
|
60
|
+
if (this.listenerCount("error"))
|
|
61
|
+
this.emit("error", data);
|
|
62
|
+
break;
|
|
63
|
+
case "TrackStuckEvent":
|
|
64
|
+
this.stop();
|
|
65
|
+
if (this.listenerCount("end"))
|
|
66
|
+
this.emit("end", data);
|
|
67
|
+
break;
|
|
68
|
+
case "WebSocketClosedEvent":
|
|
69
|
+
if (this.listenerCount("error"))
|
|
70
|
+
this.emit("error", data);
|
|
71
|
+
break;
|
|
72
|
+
default:
|
|
73
|
+
if (this.listenerCount("warn"))
|
|
74
|
+
this.emit("warn", `Unexpected event type: ${data.type}`);
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
.on("playerUpdate", data => {
|
|
79
|
+
this.state = { filters: this.state.filters, ...data.state };
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Updates the current player on lavalink
|
|
84
|
+
* @param options Update options
|
|
85
|
+
* @param noReplace If the event should be dropped if there's a currently playing track should encodedTrack or identifier be present in options
|
|
86
|
+
*/
|
|
87
|
+
async update(options, noReplace = false) {
|
|
88
|
+
const d = await Rest_1.Rest.updatePlayer(this.node, this.id, options, noReplace);
|
|
89
|
+
if (d.track)
|
|
90
|
+
this.track = d.track.encoded;
|
|
91
|
+
return d;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Plays the specified song using the base64 string from lavalink
|
|
95
|
+
* @param track The base64 string of the song that you want to play
|
|
96
|
+
* @param options Play options
|
|
97
|
+
*/
|
|
98
|
+
async play(track, options) {
|
|
99
|
+
const noReplace = options ? options.noReplace : false;
|
|
100
|
+
if (options)
|
|
101
|
+
delete options.noReplace;
|
|
102
|
+
const d = await this.update(Object.assign({ encodedTrack: track }, options), noReplace);
|
|
103
|
+
this.playing = true;
|
|
104
|
+
this.timestamp = Date.now();
|
|
105
|
+
return d;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Stops the music, depending on how the end event is handled this will either stop
|
|
109
|
+
*/
|
|
110
|
+
async stop() {
|
|
111
|
+
const d = await this.update({ encodedTrack: null });
|
|
112
|
+
this.playing = false;
|
|
113
|
+
this.timestamp = null;
|
|
114
|
+
return d;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Pauses/Resumes the song depending on what is specified
|
|
118
|
+
* @param pause Whether or not to pause whats currently playing
|
|
119
|
+
*/
|
|
120
|
+
async pause(pause) {
|
|
121
|
+
const d = await this.update({ paused: pause });
|
|
122
|
+
this.paused = pause;
|
|
123
|
+
if (this.listenerCount("pause"))
|
|
124
|
+
this.emit("pause", pause);
|
|
125
|
+
return d;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Resumes the current song
|
|
129
|
+
*/
|
|
130
|
+
resume() {
|
|
131
|
+
return this.pause(false);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Changes the volume, only for the current song
|
|
135
|
+
* @param volume The volume as a float from 0.0 to 10.0. 1.0 is default.
|
|
136
|
+
*/
|
|
137
|
+
async volume(volume) {
|
|
138
|
+
const d = await this.update({ volume: volume * 100 });
|
|
139
|
+
if (this.listenerCount("volume"))
|
|
140
|
+
this.emit("volume", volume);
|
|
141
|
+
return d;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Seeks the current song to a certain position
|
|
145
|
+
* @param position Seeks the song to the position specified in milliseconds, use the duration of the song from lavalink to get the duration
|
|
146
|
+
*/
|
|
147
|
+
async seek(position) {
|
|
148
|
+
const d = await this.update({ position });
|
|
149
|
+
if (this.listenerCount("seek"))
|
|
150
|
+
this.emit("seek", position);
|
|
151
|
+
return d;
|
|
152
|
+
}
|
|
153
|
+
async filters(options) {
|
|
154
|
+
const d = await this.update({ filters: options });
|
|
155
|
+
this.state.filters = options;
|
|
156
|
+
if (this.listenerCount("filters"))
|
|
157
|
+
this.emit("filters", options);
|
|
158
|
+
return d;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Sets the equalizer of the current song, if you wanted to do something like bassboost
|
|
162
|
+
* @param bands The bands that you want lavalink to modify read [IMPLEMENTATION.md](https://github.com/freyacodes/Lavalink/blob/master/IMPLEMENTATION.md#outgoing-messages) for more information
|
|
163
|
+
*/
|
|
164
|
+
async equalizer(bands) {
|
|
165
|
+
const newFilters = Object.assign(this.state.filters, { equalizer: bands });
|
|
166
|
+
const d = await this.filters(newFilters);
|
|
167
|
+
return d;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Sends a destroy signal to lavalink, basically just a cleanup op for lavalink to clean its shit up
|
|
171
|
+
*/
|
|
172
|
+
async destroy() {
|
|
173
|
+
const d = await Rest_1.Rest.destroyPlayer(this.node, this.id);
|
|
174
|
+
if (d && d.error)
|
|
175
|
+
throw new Error(d.message);
|
|
176
|
+
return d;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Sends voiceUpdate information to lavalink so it can connect to discords voice servers properly
|
|
180
|
+
* @param data The data lavalink needs to connect and recieve data from discord
|
|
181
|
+
*/
|
|
182
|
+
connect(data) {
|
|
183
|
+
this.voiceUpdateState = data;
|
|
184
|
+
return this.update({ voice: { token: data.event.token, endpoint: data.event.endpoint, sessionId: data.sessionId } });
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Use this to switch channels
|
|
188
|
+
* @param channel The channel id of the channel you want to switch to
|
|
189
|
+
* @param options selfMute and selfDeaf options
|
|
190
|
+
*/
|
|
191
|
+
switchChannel(channel, options = {}) {
|
|
192
|
+
return this.manager.sendWS(this.id, channel, options);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* The manager that created the player
|
|
196
|
+
*/
|
|
197
|
+
get manager() {
|
|
198
|
+
return this.node.manager;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
exports.Player = Player;
|
|
202
|
+
//# sourceMappingURL=Player.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Player.js","sourceRoot":"","sources":["../../src/lib/Player.ts"],"names":[],"mappings":";;;AAAA,mCAAsC;AACtC,iCAA8B;AAM9B;;GAEG;AACH,MAAa,MAAO,SAAQ,qBAAY;IA+BV;IAA2B;IA9BrD;;OAEG;IACI,KAAK,GAAiD,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IAC7E;;OAEG;IACI,OAAO,GAAG,KAAK,CAAC;IACvB;;OAEG;IACI,SAAS,GAAkB,IAAI,CAAC;IACvC;;OA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AAI,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IACzH,CAAC;IAED;;;;OAIG;IACI,aAAa,CAAC,OAAe,EAAE,UAAuB,EAAE;QAC3D,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED;;OAEG;IACH,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;IAC7B,CAAC;CACJ;AA5LD,wBA4LC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { LavalinkNode } from "./LavalinkNode";
|
|
2
|
+
import type { TrackLoadingResult, DecodeTrackResult, DecodeTracksResult, GetLavalinkVersionResult, UpdateSessionResult, ErrorResponse, UpdatePlayerData, UpdatePlayerResult, DestroyPlayerResult } from "lavalink-types";
|
|
3
|
+
export declare class RestError extends Error {
|
|
4
|
+
json: ErrorResponse;
|
|
5
|
+
constructor(data: ErrorResponse);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A Rest helper for Lavalink
|
|
9
|
+
*/
|
|
10
|
+
export declare class Rest {
|
|
11
|
+
/**
|
|
12
|
+
* Private base request function
|
|
13
|
+
* @param node The lavalink node
|
|
14
|
+
* @param path Route starting with /
|
|
15
|
+
* @param init Request init if any
|
|
16
|
+
* @param requires Properties of the lavalink node the route requires
|
|
17
|
+
* @throws {RestError} If lavalink encounters an error
|
|
18
|
+
*/
|
|
19
|
+
private static baseRequest;
|
|
20
|
+
/**
|
|
21
|
+
* A helper for /v?/loadtracks endpoint
|
|
22
|
+
* @param node The LavalinkNode
|
|
23
|
+
* @param identifer The thing you want to load
|
|
24
|
+
* @throws {RestError} If lavalink encounters an error
|
|
25
|
+
*/
|
|
26
|
+
static load(node: LavalinkNode, identifer: string): Promise<TrackLoadingResult>;
|
|
27
|
+
/**
|
|
28
|
+
* A helper for /v?/decodetrack & /v?/decodetracks
|
|
29
|
+
* @param node The lavalink node
|
|
30
|
+
* @param track The track(s) you want to decode
|
|
31
|
+
* @throws {RestError} If lavalink encounters an error
|
|
32
|
+
*/
|
|
33
|
+
static decode(node: LavalinkNode, track: string): Promise<DecodeTrackResult>;
|
|
34
|
+
static decode(node: LavalinkNode, tracks: string[]): Promise<DecodeTracksResult>;
|
|
35
|
+
/**
|
|
36
|
+
* A helper for /version
|
|
37
|
+
* @param node The lavalink node
|
|
38
|
+
* @throws {RestError} If lavalink encounters an error
|
|
39
|
+
*/
|
|
40
|
+
static version(node: LavalinkNode): Promise<GetLavalinkVersionResult>;
|
|
41
|
+
/**
|
|
42
|
+
* A helper for PATCH /v?/sessions/:sessionId
|
|
43
|
+
* @param node The lavalink node
|
|
44
|
+
* @throws {RestError} If lavalink encounters an error
|
|
45
|
+
*/
|
|
46
|
+
static updateSession(node: LavalinkNode): Promise<UpdateSessionResult>;
|
|
47
|
+
/**
|
|
48
|
+
* A helper for PATCH /v?/sessions/:sessionId/players/:guildId
|
|
49
|
+
* @param node The lavalink node
|
|
50
|
+
* @param guildId The Id of the guild
|
|
51
|
+
* @param data The update data
|
|
52
|
+
* @param noReplace If the event should be dropped if there's a currently playing track
|
|
53
|
+
* @throws {RestError} If lavalink encounters an error
|
|
54
|
+
*/
|
|
55
|
+
static updatePlayer(node: LavalinkNode, guildId: string, data: UpdatePlayerData, noReplace?: boolean): Promise<UpdatePlayerResult>;
|
|
56
|
+
/**
|
|
57
|
+
* A helper for DELETE /v?/sessions/:sessionId/players/:guildId
|
|
58
|
+
* @param node The lavalink node
|
|
59
|
+
* @param guildId The Id of the guild
|
|
60
|
+
* @throws {RestError} If lavalink encounters an error
|
|
61
|
+
*/
|
|
62
|
+
static destroyPlayer(node: LavalinkNode, guildId: string): Promise<ErrorResponse | DestroyPlayerResult>;
|
|
63
|
+
}
|