lavalink-client 2.2.2 → 2.3.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 +95 -1
- package/dist/cjs/index.d.ts +8 -1
- package/dist/cjs/index.js +8 -1
- package/dist/cjs/structures/Constants.d.ts +40 -0
- package/dist/cjs/structures/Constants.js +244 -0
- package/dist/cjs/structures/CustomSearches/BandCampSearch.d.ts +2 -2
- package/dist/cjs/structures/Filters.d.ts +2 -217
- package/dist/cjs/structures/Filters.js +8 -232
- package/dist/cjs/structures/LavalinkManager.d.ts +31 -166
- package/dist/cjs/structures/LavalinkManager.js +59 -7
- package/dist/cjs/structures/LavalinkManagerStatics.d.ts +1 -1
- package/dist/cjs/structures/Node.d.ts +15 -156
- package/dist/cjs/structures/Node.js +131 -49
- package/dist/cjs/structures/NodeManager.d.ts +54 -52
- package/dist/cjs/structures/NodeManager.js +74 -4
- package/dist/cjs/structures/Player.d.ts +31 -124
- package/dist/cjs/structures/Player.js +77 -43
- package/dist/cjs/structures/Queue.d.ts +66 -42
- package/dist/cjs/structures/Queue.js +69 -11
- package/dist/cjs/structures/Types/Filters.d.ts +190 -0
- package/dist/cjs/structures/Types/Manager.d.ts +184 -0
- package/dist/cjs/structures/Types/Manager.js +2 -0
- package/dist/cjs/structures/Types/Node.d.ts +216 -0
- package/dist/cjs/structures/Types/Node.js +2 -0
- package/dist/cjs/structures/Types/Player.d.ts +108 -0
- package/dist/cjs/structures/Types/Player.js +2 -0
- package/dist/cjs/structures/Types/Queue.d.ts +34 -0
- package/dist/cjs/structures/Types/Queue.js +2 -0
- package/dist/cjs/structures/{Track.d.ts → Types/Track.d.ts} +3 -2
- package/dist/{structures → cjs/structures/Types}/Track.js +2 -2
- package/dist/cjs/structures/Types/Utils.d.ts +367 -0
- package/dist/cjs/structures/Types/Utils.js +2 -0
- package/dist/cjs/structures/Utils.d.ts +13 -369
- package/dist/cjs/structures/Utils.js +35 -14
- package/dist/esm/index.d.ts +8 -1
- package/dist/esm/index.js +8 -1
- package/dist/esm/structures/Constants.d.ts +40 -0
- package/dist/esm/structures/Constants.js +241 -0
- package/dist/esm/structures/CustomSearches/BandCampSearch.d.ts +2 -2
- package/dist/esm/structures/Filters.d.ts +2 -217
- package/dist/esm/structures/Filters.js +3 -227
- package/dist/esm/structures/LavalinkManager.d.ts +31 -166
- package/dist/esm/structures/LavalinkManager.js +57 -5
- package/dist/esm/structures/LavalinkManagerStatics.d.ts +1 -1
- package/dist/esm/structures/Node.d.ts +15 -156
- package/dist/esm/structures/Node.js +122 -40
- package/dist/esm/structures/NodeManager.d.ts +54 -52
- package/dist/esm/structures/NodeManager.js +71 -1
- package/dist/esm/structures/Player.d.ts +31 -124
- package/dist/esm/structures/Player.js +76 -42
- package/dist/esm/structures/Queue.d.ts +66 -42
- package/dist/esm/structures/Queue.js +69 -11
- package/dist/esm/structures/Types/Filters.d.ts +190 -0
- package/dist/esm/structures/Types/Manager.d.ts +184 -0
- package/dist/esm/structures/Types/Manager.js +1 -0
- package/dist/esm/structures/Types/Node.d.ts +216 -0
- package/dist/esm/structures/Types/Node.js +1 -0
- package/dist/esm/structures/Types/Player.d.ts +108 -0
- package/dist/esm/structures/Types/Player.js +1 -0
- package/dist/esm/structures/Types/Queue.d.ts +34 -0
- package/dist/esm/structures/Types/Queue.js +1 -0
- package/dist/esm/structures/{Track.d.ts → Types/Track.d.ts} +3 -2
- package/dist/esm/structures/Types/Track.js +1 -0
- package/dist/esm/structures/Types/Utils.d.ts +367 -0
- package/dist/esm/structures/Types/Utils.js +1 -0
- package/dist/esm/structures/Utils.d.ts +13 -369
- package/dist/esm/structures/Utils.js +35 -14
- package/dist/types/index.d.ts +8 -1
- package/dist/types/structures/Constants.d.ts +40 -0
- package/dist/types/structures/CustomSearches/BandCampSearch.d.ts +2 -2
- package/dist/types/structures/Filters.d.ts +2 -217
- package/dist/types/structures/LavalinkManager.d.ts +31 -166
- package/dist/types/structures/LavalinkManagerStatics.d.ts +1 -1
- package/dist/types/structures/Node.d.ts +15 -156
- package/dist/types/structures/NodeManager.d.ts +54 -52
- package/dist/types/structures/Player.d.ts +31 -124
- package/dist/types/structures/Queue.d.ts +66 -42
- package/dist/types/structures/Types/Filters.d.ts +190 -0
- package/dist/types/structures/Types/Manager.d.ts +184 -0
- package/dist/types/structures/Types/Node.d.ts +216 -0
- package/dist/types/structures/Types/Player.d.ts +108 -0
- package/dist/types/structures/Types/Queue.d.ts +34 -0
- package/dist/types/structures/{Track.d.ts → Types/Track.d.ts} +3 -2
- package/dist/types/structures/Types/Utils.d.ts +367 -0
- package/dist/types/structures/Utils.d.ts +13 -369
- package/package.json +1 -1
- package/dist/index.d.ts +0 -10
- package/dist/index.js +0 -13
- package/dist/structures/Filters.d.ts +0 -230
- package/dist/structures/Filters.js +0 -472
- package/dist/structures/LavalinkManager.d.ts +0 -47
- package/dist/structures/LavalinkManager.js +0 -36
- package/dist/structures/LavalinkManagerStatics.d.ts +0 -3
- package/dist/structures/LavalinkManagerStatics.js +0 -76
- package/dist/structures/Node.d.ts +0 -171
- package/dist/structures/Node.js +0 -462
- package/dist/structures/NodeManager.d.ts +0 -58
- package/dist/structures/NodeManager.js +0 -25
- package/dist/structures/Player.d.ts +0 -101
- package/dist/structures/Player.js +0 -232
- package/dist/structures/PlayerManager.d.ts +0 -62
- package/dist/structures/PlayerManager.js +0 -26
- package/dist/structures/Queue.d.ts +0 -93
- package/dist/structures/Queue.js +0 -160
- package/dist/structures/QueueManager.d.ts +0 -77
- package/dist/structures/QueueManager.js +0 -74
- package/dist/structures/Track.d.ts +0 -27
- package/dist/structures/Utils.d.ts +0 -183
- package/dist/structures/Utils.js +0 -43
- /package/dist/cjs/structures/{Track.js → Types/Filters.js} +0 -0
- /package/dist/esm/structures/{Track.js → Types/Filters.js} +0 -0
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NodeManager = void 0;
|
|
4
|
-
const stream_1 = require("stream");
|
|
5
|
-
const Node_1 = require("./Node");
|
|
6
|
-
class NodeManager extends stream_1.EventEmitter {
|
|
7
|
-
nodes;
|
|
8
|
-
constructor(LavalinkManager) {
|
|
9
|
-
super();
|
|
10
|
-
this.LavalinkManager = LavalinkManager;
|
|
11
|
-
}
|
|
12
|
-
createNode(options) {
|
|
13
|
-
if (this.nodes.has(options.id || options.host))
|
|
14
|
-
return this.nodes.get(options.id || options.host);
|
|
15
|
-
const newNode = new Node_1.LavalinkNode(options, this);
|
|
16
|
-
this.nodes.set(newNode.id, newNode);
|
|
17
|
-
return newNode;
|
|
18
|
-
}
|
|
19
|
-
get leastUsedNodes() {
|
|
20
|
-
return [...this.nodes.values()].filter(v => v);
|
|
21
|
-
}
|
|
22
|
-
deleteNode(options) {
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.NodeManager = NodeManager;
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { FilterManager, LavalinkFilterData } from "./Filters";
|
|
2
|
-
import { LavalinkNode } from "./Node";
|
|
3
|
-
import { PlayerManager } from "./PlayerManager";
|
|
4
|
-
import { Queue } from "./Queue";
|
|
5
|
-
import { Track } from "./Track";
|
|
6
|
-
import { LavalinkPlayerVoiceOptions, SearchPlatform, SearchResult } from "./Utils";
|
|
7
|
-
export type RepeatMode = "queue" | "track" | "off";
|
|
8
|
-
export interface PlayerOptions {
|
|
9
|
-
guildId: string;
|
|
10
|
-
voiceChannelId: string;
|
|
11
|
-
volume?: number;
|
|
12
|
-
vcRegion?: string;
|
|
13
|
-
selfDeaf?: boolean;
|
|
14
|
-
selfMute?: boolean;
|
|
15
|
-
textChannelId?: string;
|
|
16
|
-
node?: Node | string;
|
|
17
|
-
instaUpdateFiltersFix?: boolean;
|
|
18
|
-
applyVolumeAsFilter?: boolean;
|
|
19
|
-
}
|
|
20
|
-
export interface PlayOptions {
|
|
21
|
-
/** Which Track to play | don't provide, if it should pick from the Queue */
|
|
22
|
-
track?: Track;
|
|
23
|
-
/** Encoded Track to use, instead of the queue system... */
|
|
24
|
-
encodedTrack?: string | null;
|
|
25
|
-
/** Encoded Track to use&search, instead of the queue system (yt only)... */
|
|
26
|
-
identifier?: string;
|
|
27
|
-
/** The position to start the track. */
|
|
28
|
-
position?: number;
|
|
29
|
-
/** The position to end the track. */
|
|
30
|
-
endTime?: number;
|
|
31
|
-
/** Whether to not replace the track if a play payload is sent. */
|
|
32
|
-
noReplace?: boolean;
|
|
33
|
-
/** If to start "paused" */
|
|
34
|
-
paused?: boolean;
|
|
35
|
-
/** The Volume to start with */
|
|
36
|
-
volume?: number;
|
|
37
|
-
/** The Lavalink Filters to use | only with the new REST API */
|
|
38
|
-
filters?: Partial<LavalinkFilterData>;
|
|
39
|
-
voice?: LavalinkPlayerVoiceOptions;
|
|
40
|
-
}
|
|
41
|
-
export interface Player {
|
|
42
|
-
filterManager: FilterManager;
|
|
43
|
-
playerManager: PlayerManager;
|
|
44
|
-
options: PlayerOptions;
|
|
45
|
-
node: LavalinkNode;
|
|
46
|
-
queue: Queue;
|
|
47
|
-
}
|
|
48
|
-
export declare class Player {
|
|
49
|
-
guildId: string;
|
|
50
|
-
voiceChannelId: string | null;
|
|
51
|
-
textChannelId: string | null;
|
|
52
|
-
playing: boolean;
|
|
53
|
-
paused: boolean;
|
|
54
|
-
repeatMode: RepeatMode;
|
|
55
|
-
ping: number;
|
|
56
|
-
wsPing: number;
|
|
57
|
-
volume: number;
|
|
58
|
-
lavalinkVolume: number;
|
|
59
|
-
position: number;
|
|
60
|
-
/** When the player was created [Timestamp] (from lavalink) */
|
|
61
|
-
createdTimeStamp: number;
|
|
62
|
-
/** If lavalink says it's connected or not */
|
|
63
|
-
connected: boolean | undefined;
|
|
64
|
-
voice: LavalinkPlayerVoiceOptions;
|
|
65
|
-
private readonly data;
|
|
66
|
-
/**
|
|
67
|
-
* Set custom data.
|
|
68
|
-
* @param key
|
|
69
|
-
* @param value
|
|
70
|
-
*/
|
|
71
|
-
set(key: string, value: unknown): void;
|
|
72
|
-
/**
|
|
73
|
-
* Get custom data.
|
|
74
|
-
* @param key
|
|
75
|
-
*/
|
|
76
|
-
get<T>(key: string): T;
|
|
77
|
-
clearData(): void;
|
|
78
|
-
getAllData(): Record<string, unknown>;
|
|
79
|
-
constructor(options: PlayerOptions, playerManager: PlayerManager);
|
|
80
|
-
play(options?: Partial<PlayOptions>): Promise<void>;
|
|
81
|
-
setVolume(volume: number, ignoreVolumeDecrementer?: boolean): Promise<void>;
|
|
82
|
-
search(query: {
|
|
83
|
-
query: string;
|
|
84
|
-
source: SearchPlatform;
|
|
85
|
-
}, requestUser: unknown): Promise<SearchResult>;
|
|
86
|
-
pause(): Promise<void>;
|
|
87
|
-
resume(): Promise<void>;
|
|
88
|
-
seek(position: number): Promise<any>;
|
|
89
|
-
setRepeatMode(repeatMode: RepeatMode): Promise<void>;
|
|
90
|
-
/**
|
|
91
|
-
* Skip a Song (on Lavalink it's called "STOP")
|
|
92
|
-
* @param amount provide the index of the next track to skip to
|
|
93
|
-
*/
|
|
94
|
-
skip(skipTo?: number): Promise<boolean>;
|
|
95
|
-
connect(): Promise<void>;
|
|
96
|
-
disconnect(): Promise<void>;
|
|
97
|
-
/**
|
|
98
|
-
* Destroy the player
|
|
99
|
-
*/
|
|
100
|
-
destroy(disconnect?: boolean): Promise<void>;
|
|
101
|
-
}
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Player = void 0;
|
|
4
|
-
const Filters_1 = require("./Filters");
|
|
5
|
-
const LavalinkManagerStatics_1 = require("./LavalinkManagerStatics");
|
|
6
|
-
const Queue_1 = require("./Queue");
|
|
7
|
-
class Player {
|
|
8
|
-
// All properties
|
|
9
|
-
guildId;
|
|
10
|
-
voiceChannelId = null;
|
|
11
|
-
textChannelId = null;
|
|
12
|
-
playing = false;
|
|
13
|
-
paused = false;
|
|
14
|
-
repeatMode = "off";
|
|
15
|
-
ping = 0;
|
|
16
|
-
wsPing = 0;
|
|
17
|
-
volume = 100;
|
|
18
|
-
lavalinkVolume = 100;
|
|
19
|
-
position = 0;
|
|
20
|
-
/** When the player was created [Timestamp] (from lavalink) */
|
|
21
|
-
createdTimeStamp;
|
|
22
|
-
/** If lavalink says it's connected or not */
|
|
23
|
-
connected = false;
|
|
24
|
-
voice;
|
|
25
|
-
data = {};
|
|
26
|
-
/**
|
|
27
|
-
* Set custom data.
|
|
28
|
-
* @param key
|
|
29
|
-
* @param value
|
|
30
|
-
*/
|
|
31
|
-
set(key, value) {
|
|
32
|
-
this.data[key] = value;
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Get custom data.
|
|
37
|
-
* @param key
|
|
38
|
-
*/
|
|
39
|
-
get(key) { return this.data[key]; }
|
|
40
|
-
clearData() {
|
|
41
|
-
const toKeep = Object.keys(this.data).filter(v => v.startsWith("internal_"));
|
|
42
|
-
for (const key in this.data) {
|
|
43
|
-
if (toKeep.includes(key))
|
|
44
|
-
continue;
|
|
45
|
-
delete this.data[key];
|
|
46
|
-
}
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
getAllData() { return Object.fromEntries(Object.entries(this.data).filter(v => !v[0].startsWith("internal_"))); }
|
|
50
|
-
// constructor
|
|
51
|
-
constructor(options, playerManager) {
|
|
52
|
-
this.options = options;
|
|
53
|
-
this.filterManager = new Filters_1.FilterManager(this);
|
|
54
|
-
this.playerManager = playerManager;
|
|
55
|
-
this.voiceChannelId = this.options.voiceChannelId;
|
|
56
|
-
this.textChannelId = this.options.textChannelId || null;
|
|
57
|
-
this.node = this.playerManager.LavalinkManager.nodeManager.leastUsedNodes.filter(v => options.vcRegion ? v.options?.regions?.includes(options.vcRegion) : true)[0] || this.playerManager.LavalinkManager.nodeManager.leastUsedNodes[0] || null;
|
|
58
|
-
if (!this.node)
|
|
59
|
-
throw new Error("No available Node was found, please add a LavalinkNode to the Manager via Manager.NodeManager#createNode");
|
|
60
|
-
if (this.playerManager.LavalinkManager.options.playerOptions.volumeDecrementer)
|
|
61
|
-
this.volume *= this.playerManager.LavalinkManager.options.playerOptions.volumeDecrementer;
|
|
62
|
-
this.playerManager.emit("create", this);
|
|
63
|
-
if (typeof options.volume === "number" && !isNaN(options.volume))
|
|
64
|
-
this.setVolume(options.volume);
|
|
65
|
-
this.queue = new Queue_1.Queue({}, this.guildId, new Queue_1.QueueSaver(this.playerManager.LavalinkManager.options.queueStore, this.playerManager.LavalinkManager.options.queueOptions));
|
|
66
|
-
}
|
|
67
|
-
// all functions
|
|
68
|
-
async play(options) {
|
|
69
|
-
const track = options.track || this.queue.currentTrack;
|
|
70
|
-
if (!track)
|
|
71
|
-
throw new Error(`There is no Track in the Queue, nor provided in the PlayOptions`);
|
|
72
|
-
if (typeof options.volume === "number" && !isNaN(options.volume)) {
|
|
73
|
-
this.volume = Math.max(Math.min(options.volume, 500), 0);
|
|
74
|
-
let vol = Number(this.volume);
|
|
75
|
-
if (this.playerManager.LavalinkManager.options.playerOptions.volumeDecrementer)
|
|
76
|
-
vol *= this.playerManager.LavalinkManager.options.playerOptions.volumeDecrementer;
|
|
77
|
-
this.lavalinkVolume = Math.floor(vol * 100) / 100;
|
|
78
|
-
options.volume = vol;
|
|
79
|
-
}
|
|
80
|
-
this.set("lastposition", this.position);
|
|
81
|
-
const now = performance.now();
|
|
82
|
-
await this.node.updatePlayer({
|
|
83
|
-
guildId: this.guildId,
|
|
84
|
-
noReplace: options.noReplace ?? false,
|
|
85
|
-
playerOptions: {
|
|
86
|
-
encodedTrack: track.encodedTrack,
|
|
87
|
-
volume: this.volume,
|
|
88
|
-
position: 0,
|
|
89
|
-
...options
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
this.ping = Math.round((performance.now() - now) / 10) / 100;
|
|
93
|
-
}
|
|
94
|
-
async setVolume(volume, ignoreVolumeDecrementer = false) {
|
|
95
|
-
volume = Number(volume);
|
|
96
|
-
if (isNaN(volume))
|
|
97
|
-
throw new TypeError("Volume must be a number.");
|
|
98
|
-
this.volume = Math.max(Math.min(volume, 500), 0);
|
|
99
|
-
volume = Number(this.volume);
|
|
100
|
-
if (this.playerManager.LavalinkManager.options.playerOptions.volumeDecrementer && !ignoreVolumeDecrementer)
|
|
101
|
-
volume *= this.playerManager.LavalinkManager.options.playerOptions.volumeDecrementer;
|
|
102
|
-
this.lavalinkVolume = Math.floor(volume * 100) / 100;
|
|
103
|
-
const now = performance.now();
|
|
104
|
-
if (this.playerManager.LavalinkManager.options.playerOptions.applyVolumeAsFilter) {
|
|
105
|
-
await this.node.updatePlayer({ guildId: this.guildId, playerOptions: { filters: { volume: volume / 100 } } });
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
await this.node.updatePlayer({ guildId: this.guildId, playerOptions: { volume } });
|
|
109
|
-
}
|
|
110
|
-
this.ping = Math.round((performance.now() - now) / 10) / 100;
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
async search(query, requestUser) {
|
|
114
|
-
const _query = typeof query === "string" ? query : query.query;
|
|
115
|
-
const _source = LavalinkManagerStatics_1.DEFAULT_SOURCES[query.source ?? this.playerManager.LavalinkManager.options.playerOptions.defaultSearchPlatform] ?? query.source ?? this.playerManager.LavalinkManager.options.playerOptions.defaultSearchPlatform;
|
|
116
|
-
const srcSearch = !/^https?:\/\//.test(_query) ? `${_source}:` : "";
|
|
117
|
-
const res = await this.node.makeRequest(`/loadtracks?identifier=${srcSearch}${encodeURIComponent(_query)}`);
|
|
118
|
-
console.log("DEBUG LOG - RESPONSE", res);
|
|
119
|
-
const resTracks = res.loadType === "playlist" ? res.data?.tracks : res.loadType === "track" ? [res.data] : res.loadType === "search" ? Array.isArray(res.data) ? res.data : [res.data] : [];
|
|
120
|
-
const response = {
|
|
121
|
-
loadType: res.loadType,
|
|
122
|
-
exception: res.loadType === "error" ? res.data : null,
|
|
123
|
-
pluginInfo: res.pluginInfo || {},
|
|
124
|
-
playlist: res.loadType === "playlist" ? {
|
|
125
|
-
name: res.data.info?.name || res.data.pluginInfo?.name || null,
|
|
126
|
-
author: res.data.info?.author || res.data.pluginInfo?.author || null,
|
|
127
|
-
thumbnail: (res.data.info?.artworkUrl) || (res.data.pluginInfo?.artworkUrl) || ((typeof res.data?.info?.selectedTrack !== "number" || res.data?.info?.selectedTrack === -1) ? null : resTracks[res.data?.info?.selectedTrack] ? (resTracks[res.data?.info?.selectedTrack]?.info?.artworkUrl || resTracks[res.data?.info?.selectedTrack]?.info?.pluginInfo?.artworkUrl) : null) || null,
|
|
128
|
-
uri: res.data.info?.url || res.data.info?.uri || res.data.info?.link || res.data.pluginInfo?.url || res.data.pluginInfo?.uri || res.data.pluginInfo?.link || null,
|
|
129
|
-
selectedTrack: typeof res.data?.info?.selectedTrack !== "number" || res.data?.info?.selectedTrack === -1 ? null : resTracks[res.data?.info?.selectedTrack] ? this.playerManager.LavalinkManager.utilManager.buildTrack(resTracks[res.data?.info?.selectedTrack], requestUser) : null,
|
|
130
|
-
duration: resTracks.length ? resTracks.reduce((acc, cur) => acc + (cur?.info?.duration || 0), 0) : 0,
|
|
131
|
-
} : null,
|
|
132
|
-
tracks: resTracks.length ? resTracks.map(t => this.playerManager.LavalinkManager.utilManager.buildTrack(t, requestUser)) : []
|
|
133
|
-
};
|
|
134
|
-
return response;
|
|
135
|
-
}
|
|
136
|
-
async pause() {
|
|
137
|
-
if (this.paused && !this.playing)
|
|
138
|
-
throw new Error("Player is already paused - not able to pause.");
|
|
139
|
-
this.paused = true;
|
|
140
|
-
const now = performance.now();
|
|
141
|
-
await this.node.updatePlayer({ guildId: this.guildId, playerOptions: { paused: true } });
|
|
142
|
-
this.ping = Math.round((performance.now() - now) / 10) / 100;
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
async resume() {
|
|
146
|
-
if (!this.paused)
|
|
147
|
-
throw new Error("Player isn't paused - not able to resume.");
|
|
148
|
-
this.paused = false;
|
|
149
|
-
const now = performance.now();
|
|
150
|
-
await this.node.updatePlayer({ guildId: this.guildId, playerOptions: { paused: false } });
|
|
151
|
-
this.ping = Math.round((performance.now() - now) / 10) / 100;
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
async seek(position) {
|
|
155
|
-
if (!this.queue.currentTrack)
|
|
156
|
-
return undefined;
|
|
157
|
-
position = Number(position);
|
|
158
|
-
if (isNaN(position))
|
|
159
|
-
throw new RangeError("Position must be a number.");
|
|
160
|
-
if (!this.queue.currentTrack.info.isSeekable || this.queue.currentTrack.info.isStream)
|
|
161
|
-
throw new RangeError("Current Track is not seekable / a stream");
|
|
162
|
-
if (position < 0 || position > this.queue.currentTrack.info.duration)
|
|
163
|
-
position = Math.max(Math.min(position, this.queue.currentTrack.info.duration), 0);
|
|
164
|
-
this.position = position;
|
|
165
|
-
this.set("internal_lastposition", this.position);
|
|
166
|
-
const now = performance.now();
|
|
167
|
-
await this.node.updatePlayer({ guildId: this.guildId, playerOptions: { position } });
|
|
168
|
-
this.ping = Math.round((performance.now() - now) / 10) / 100;
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
async setRepeatMode(repeatMode) {
|
|
172
|
-
if (!["off", "track", "queue"].includes(repeatMode))
|
|
173
|
-
throw new RangeError("Repeatmode must be either 'off', 'track', or 'queue'");
|
|
174
|
-
this.repeatMode = repeatMode;
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Skip a Song (on Lavalink it's called "STOP")
|
|
179
|
-
* @param amount provide the index of the next track to skip to
|
|
180
|
-
*/
|
|
181
|
-
async skip(skipTo = 0) {
|
|
182
|
-
if (typeof skipTo === "number" && skipTo > 1) {
|
|
183
|
-
if (skipTo > this.queue.size)
|
|
184
|
-
throw new RangeError("Can't skip more than the queue size");
|
|
185
|
-
this.queue.splice(0, skipTo - 1);
|
|
186
|
-
}
|
|
187
|
-
const now = performance.now();
|
|
188
|
-
await this.node.updatePlayer({ guildId: this.guildId, playerOptions: { encodedTrack: null } });
|
|
189
|
-
this.ping = Math.round((performance.now() - now) / 10) / 100;
|
|
190
|
-
return true;
|
|
191
|
-
}
|
|
192
|
-
async connect() {
|
|
193
|
-
if (!this.options.voiceChannelId)
|
|
194
|
-
throw new RangeError("No Voice Channel id has been set.");
|
|
195
|
-
await this.playerManager.LavalinkManager.options.sendToShard(this.guildId, {
|
|
196
|
-
op: 4,
|
|
197
|
-
d: {
|
|
198
|
-
guild_id: this.guildId,
|
|
199
|
-
channel_id: this.options.voiceChannelId,
|
|
200
|
-
self_mute: this.options.selfMute ?? false,
|
|
201
|
-
self_deaf: this.options.selfDeaf ?? true,
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
async disconnect() {
|
|
207
|
-
if (!this.options.voiceChannelId)
|
|
208
|
-
throw new RangeError("No Voice Channel id has been set.");
|
|
209
|
-
await this.playerManager.LavalinkManager.options.sendToShard(this.guildId, {
|
|
210
|
-
op: 4,
|
|
211
|
-
d: {
|
|
212
|
-
guild_id: this.guildId,
|
|
213
|
-
channel_id: null,
|
|
214
|
-
self_mute: false,
|
|
215
|
-
self_deaf: false,
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
this.voiceChannelId = null;
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Destroy the player
|
|
223
|
-
*/
|
|
224
|
-
async destroy(disconnect = true) {
|
|
225
|
-
if (disconnect)
|
|
226
|
-
await this.disconnect();
|
|
227
|
-
await this.node.destroyPlayer(this.guildId);
|
|
228
|
-
this.playerManager.emit("destroy", this);
|
|
229
|
-
this.playerManager.deletePlayer(this.guildId);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
exports.Player = Player;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { EventEmitter } from "stream";
|
|
3
|
-
import { Player, PlayerOptions } from "./Player";
|
|
4
|
-
import { LavalinkManager } from "./LavalinkManager";
|
|
5
|
-
import { Track } from "./Track";
|
|
6
|
-
import { TrackEndEvent, TrackExceptionEvent, TrackStartEvent, TrackStuckEvent, WebSocketClosedEvent } from "./Utils";
|
|
7
|
-
interface PlayerManagerEvents {
|
|
8
|
-
/**
|
|
9
|
-
* Emitted when a Player is created.
|
|
10
|
-
* @event Manager.playerManager#create
|
|
11
|
-
*/
|
|
12
|
-
"create": (player: Player) => void;
|
|
13
|
-
/**
|
|
14
|
-
* Emitted when a Track started playing.
|
|
15
|
-
* @event Manager.playerManager#trackStart
|
|
16
|
-
*/
|
|
17
|
-
"trackStart": (player: Player, track: Track, payload: TrackStartEvent) => void;
|
|
18
|
-
/**
|
|
19
|
-
* Emitted when a Track finished.
|
|
20
|
-
* @event Manager.playerManager#trackEnd
|
|
21
|
-
*/
|
|
22
|
-
"trackEnd": (player: Player, track: Track, payload: TrackEndEvent) => void;
|
|
23
|
-
/**
|
|
24
|
-
* Emitted when a Track finished.
|
|
25
|
-
* @event Manager.playerManager#trackStuck
|
|
26
|
-
*/
|
|
27
|
-
"trackStuck": (player: Player, track: Track, payload: TrackStuckEvent) => void;
|
|
28
|
-
/**
|
|
29
|
-
* Emitted when a Track finished.
|
|
30
|
-
* @event Manager.playerManager#trackError
|
|
31
|
-
*/
|
|
32
|
-
"trackError": (player: Player, track: Track, payload: TrackExceptionEvent) => void;
|
|
33
|
-
/**
|
|
34
|
-
* Emitted when a Track finished.
|
|
35
|
-
* @event Manager.playerManager#queueEnd
|
|
36
|
-
*/
|
|
37
|
-
"queueEnd": (player: Player, track: Track, payload: TrackEndEvent | TrackStuckEvent) => void;
|
|
38
|
-
/**
|
|
39
|
-
* Emitted when a Node-Socket got closed for a specific Player.
|
|
40
|
-
* @event Manager.playerManager#socketClosed
|
|
41
|
-
*/
|
|
42
|
-
"socketClosed": (player: Player, payload: WebSocketClosedEvent) => void;
|
|
43
|
-
/**
|
|
44
|
-
* Emitted when a Player get's destroyed
|
|
45
|
-
* @event Manager.playerManager#destroy
|
|
46
|
-
*/
|
|
47
|
-
"destroy": (player: Player) => void;
|
|
48
|
-
}
|
|
49
|
-
export interface PlayerManager {
|
|
50
|
-
on<U extends keyof PlayerManagerEvents>(event: U, listener: PlayerManagerEvents[U]): this;
|
|
51
|
-
emit<U extends keyof PlayerManagerEvents>(event: U, ...args: Parameters<PlayerManagerEvents[U]>): boolean;
|
|
52
|
-
/** @private */
|
|
53
|
-
LavalinkManager: LavalinkManager;
|
|
54
|
-
}
|
|
55
|
-
export declare class PlayerManager extends EventEmitter {
|
|
56
|
-
private players;
|
|
57
|
-
constructor(LavalinkManager: LavalinkManager);
|
|
58
|
-
createPlayer(options: PlayerOptions): Player;
|
|
59
|
-
getPlayer(guildId: string): Player;
|
|
60
|
-
deletePlayer(guildId: string): boolean;
|
|
61
|
-
}
|
|
62
|
-
export {};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PlayerManager = void 0;
|
|
4
|
-
const stream_1 = require("stream");
|
|
5
|
-
const Player_1 = require("./Player");
|
|
6
|
-
class PlayerManager extends stream_1.EventEmitter {
|
|
7
|
-
players;
|
|
8
|
-
constructor(LavalinkManager) {
|
|
9
|
-
super();
|
|
10
|
-
this.LavalinkManager = LavalinkManager;
|
|
11
|
-
}
|
|
12
|
-
createPlayer(options) {
|
|
13
|
-
if (this.players.has(options.guildId))
|
|
14
|
-
return this.players.get(options.guildId);
|
|
15
|
-
const newPlayer = new Player_1.Player(options, this);
|
|
16
|
-
this.players.set(newPlayer.guildId, newPlayer);
|
|
17
|
-
return newPlayer;
|
|
18
|
-
}
|
|
19
|
-
getPlayer(guildId) {
|
|
20
|
-
return this.players.get(guildId);
|
|
21
|
-
}
|
|
22
|
-
deletePlayer(guildId) {
|
|
23
|
-
return this.players.delete(guildId);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.PlayerManager = PlayerManager;
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { Track } from "./Track";
|
|
2
|
-
export interface StoredQueue {
|
|
3
|
-
currentTrack: Track | null;
|
|
4
|
-
previousTracks: Track[];
|
|
5
|
-
nextTracks: Track[];
|
|
6
|
-
}
|
|
7
|
-
export interface QueueStoreManager extends Record<any, any> {
|
|
8
|
-
/** @async get a Value */
|
|
9
|
-
get: (key: unknown) => any;
|
|
10
|
-
/** @async Set a value inside a key */
|
|
11
|
-
set: (key: unknown, value: unknown) => any;
|
|
12
|
-
/** @async Delete a Database Value based of it's key */
|
|
13
|
-
delete: (key: unknown) => any;
|
|
14
|
-
/** @async Transform the value(s) inside of the QueueStoreManager */
|
|
15
|
-
stringify: (value: unknown) => any;
|
|
16
|
-
/** @async Parse the saved value back to the Queue */
|
|
17
|
-
parse: (value: unknown) => Queue;
|
|
18
|
-
}
|
|
19
|
-
export interface ManagerQueueOptions {
|
|
20
|
-
maxPreviousTracks: number;
|
|
21
|
-
}
|
|
22
|
-
export interface QueueSaver {
|
|
23
|
-
/** @private */
|
|
24
|
-
_: QueueStoreManager;
|
|
25
|
-
/** @private */
|
|
26
|
-
options: ManagerQueueOptions;
|
|
27
|
-
}
|
|
28
|
-
export declare class QueueSaver {
|
|
29
|
-
constructor(QueueStoreManager: QueueStoreManager, options: ManagerQueueOptions);
|
|
30
|
-
get(key: string): Promise<Queue>;
|
|
31
|
-
delete(key: string): Promise<any>;
|
|
32
|
-
set(key: string, value: any): Promise<any>;
|
|
33
|
-
}
|
|
34
|
-
export declare class DefaultQueueStore {
|
|
35
|
-
private data;
|
|
36
|
-
constructor();
|
|
37
|
-
get(key: any): any;
|
|
38
|
-
set(key: any, value: any): Map<any, any>;
|
|
39
|
-
delete(key: any): boolean;
|
|
40
|
-
stringify(value: any): any;
|
|
41
|
-
parse(value: any): any;
|
|
42
|
-
}
|
|
43
|
-
export declare class Queue {
|
|
44
|
-
private readonly _nextTracks;
|
|
45
|
-
private readonly _previousTracks;
|
|
46
|
-
private _currentTrack;
|
|
47
|
-
private readonly _guildId;
|
|
48
|
-
private readonly _QueueSaver;
|
|
49
|
-
constructor(data?: Partial<StoredQueue>, guildId?: string, QueueSaver?: QueueSaver);
|
|
50
|
-
isTrack(data: Track): boolean;
|
|
51
|
-
/** The Current Playing Track */
|
|
52
|
-
get currentTrack(): Track;
|
|
53
|
-
/** All Previous Track(s) [with the limited amount] */
|
|
54
|
-
get previousTracks(): Track[];
|
|
55
|
-
/** All Upcoming Track(s) */
|
|
56
|
-
get nextTracks(): Track[];
|
|
57
|
-
/** The Size of the upcoming Track(s) */
|
|
58
|
-
get size(): number;
|
|
59
|
-
/** The Size of the previous Track(s) */
|
|
60
|
-
get previousSize(): number;
|
|
61
|
-
/**
|
|
62
|
-
* @returns The Queue, but in a raw State, which allows easier handling for the QueueStoreManager
|
|
63
|
-
*/
|
|
64
|
-
getStored(): StoredQueue;
|
|
65
|
-
/**
|
|
66
|
-
* Add a Track to the Queue, and after saved in the "db" it returns the amount of the Tracks
|
|
67
|
-
* @param Track
|
|
68
|
-
* @param index At what position to add the Track
|
|
69
|
-
* @returns Queue-Size (for the next Tracks)
|
|
70
|
-
*/
|
|
71
|
-
add(TrackOrTracks: Track | Track[], index?: number): Promise<number | Track | Track[]>;
|
|
72
|
-
/**
|
|
73
|
-
*
|
|
74
|
-
* @param index Where to remove the Track
|
|
75
|
-
* @param amount How many Tracks to remove?
|
|
76
|
-
* @param TrackOrTracks Want to Add more Tracks?
|
|
77
|
-
*/
|
|
78
|
-
splice(index: number, amount: number, TrackOrTracks?: Track | Track[]): Promise<Track | Track[]>;
|
|
79
|
-
/**
|
|
80
|
-
* Add a Track to the Previous Track list, and after saved in the "db" it returns the amount of the previous Tracks
|
|
81
|
-
* @param Track
|
|
82
|
-
* @returns PreviousTracksSize
|
|
83
|
-
*/
|
|
84
|
-
addPrevious(Track: Track): Promise<number>;
|
|
85
|
-
/**
|
|
86
|
-
* Add a Track to the Previous Track list, and after saved in the "db" it returns the amount of the previous Tracks
|
|
87
|
-
* @param Track
|
|
88
|
-
* @returns PreviousTracksSize
|
|
89
|
-
*/
|
|
90
|
-
setCurrent(Track: Track | null): Promise<Track>;
|
|
91
|
-
/** @private @hidden */
|
|
92
|
-
_trackEnd(addBackToQueue?: boolean): Promise<Track>;
|
|
93
|
-
}
|