hoshimi 0.3.1 → 0.3.5
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/index.d.mts +2088 -1920
- package/dist/index.d.ts +2088 -1920
- package/dist/index.js +306 -116
- package/dist/index.mjs +306 -116
- package/package.json +9 -1
package/dist/index.js
CHANGED
|
@@ -165,6 +165,7 @@ var Events = /* @__PURE__ */ ((Events2) => {
|
|
|
165
165
|
Events2["PlayerCreate"] = "playerCreate";
|
|
166
166
|
Events2["PlayerUpdate"] = "playerUpdate";
|
|
167
167
|
Events2["PlayerDestroy"] = "playerDestroy";
|
|
168
|
+
Events2["PlayerError"] = "playerError";
|
|
168
169
|
Events2["TrackStart"] = "trackStart";
|
|
169
170
|
Events2["TrackEnd"] = "trackEnd";
|
|
170
171
|
Events2["TrackStuck"] = "trackStuck";
|
|
@@ -184,6 +185,8 @@ var DestroyReasons = /* @__PURE__ */ ((DestroyReasons2) => {
|
|
|
184
185
|
DestroyReasons2["NodeDisconnected"] = "Player-NodeDisconnected";
|
|
185
186
|
DestroyReasons2["NodeDestroy"] = "Player-NodeDestroy";
|
|
186
187
|
DestroyReasons2["VoiceChannelDeleted"] = "Player-VoiceChannelDeleted";
|
|
188
|
+
DestroyReasons2["VoiceChannelLeft"] = "Player-VoiceChannelLeft";
|
|
189
|
+
DestroyReasons2["ReconnectFailed"] = "Player-ReconnectFailed";
|
|
187
190
|
return DestroyReasons2;
|
|
188
191
|
})(DestroyReasons || {});
|
|
189
192
|
|
|
@@ -371,7 +374,7 @@ var Track = class {
|
|
|
371
374
|
pluginInfo;
|
|
372
375
|
/**
|
|
373
376
|
* The track user data.
|
|
374
|
-
* @type {
|
|
377
|
+
* @type {TrackUserData}
|
|
375
378
|
*/
|
|
376
379
|
userData;
|
|
377
380
|
/**
|
|
@@ -441,7 +444,7 @@ var UnresolvedTrack = class {
|
|
|
441
444
|
pluginInfo;
|
|
442
445
|
/**
|
|
443
446
|
* The track user data.
|
|
444
|
-
* @type {
|
|
447
|
+
* @type {TrackUserData | undefined}
|
|
445
448
|
*/
|
|
446
449
|
userData;
|
|
447
450
|
/**
|
|
@@ -469,7 +472,7 @@ var UnresolvedTrack = class {
|
|
|
469
472
|
constructor(track, requester) {
|
|
470
473
|
this.info = track.info;
|
|
471
474
|
this.encoded = track.encoded;
|
|
472
|
-
this.requester = requester;
|
|
475
|
+
this.requester = requester ?? {};
|
|
473
476
|
this.pluginInfo = track.pluginInfo;
|
|
474
477
|
this.userData = track.userData ?? {};
|
|
475
478
|
}
|
|
@@ -531,12 +534,20 @@ var UnresolvedTrack = class {
|
|
|
531
534
|
// package.json
|
|
532
535
|
var package_default = {
|
|
533
536
|
name: "hoshimi",
|
|
534
|
-
version: "0.3.
|
|
537
|
+
version: "0.3.5",
|
|
535
538
|
description: "A lavalink@v4 client easy to use, up-to-date and all ears.",
|
|
536
539
|
main: "./dist/index.js",
|
|
537
540
|
module: "./dist/index.mjs",
|
|
538
541
|
types: "./dist/index.d.ts",
|
|
539
|
-
packageManager: "pnpm@10.
|
|
542
|
+
packageManager: "pnpm@10.27.0+sha512.72d699da16b1179c14ba9e64dc71c9a40988cbdc65c264cb0e489db7de917f20dcf4d64d8723625f2969ba52d4b7e2a1170682d9ac2a5dcaeaab732b7e16f04a",
|
|
543
|
+
exports: {
|
|
544
|
+
".": {
|
|
545
|
+
types: "./dist/index.d.ts",
|
|
546
|
+
require: "./dist/index.js",
|
|
547
|
+
import: "./dist/index.mjs",
|
|
548
|
+
default: "./dist/index.js"
|
|
549
|
+
}
|
|
550
|
+
},
|
|
540
551
|
files: [
|
|
541
552
|
"dist"
|
|
542
553
|
],
|
|
@@ -572,8 +583,8 @@ var package_default = {
|
|
|
572
583
|
author: "Ganyu Studios",
|
|
573
584
|
license: "MIT",
|
|
574
585
|
devDependencies: {
|
|
575
|
-
"@biomejs/biome": "^2.3.
|
|
576
|
-
"@types/node": "^
|
|
586
|
+
"@biomejs/biome": "^2.3.11",
|
|
587
|
+
"@types/node": "^25.0.3",
|
|
577
588
|
"@types/ws": "^8.18.1",
|
|
578
589
|
husky: "^9.1.7",
|
|
579
590
|
"lint-staged": "^16.2.7",
|
|
@@ -761,7 +772,7 @@ function validateManagerOptions(options) {
|
|
|
761
772
|
throw new OptionError("The manager option 'options.nodes' must be a valid array of nodes and atleast one valid node.");
|
|
762
773
|
if (typeof options.sendPayload !== "function")
|
|
763
774
|
throw new OptionError("The manager option 'options.sendPayload' must be a vaid function.");
|
|
764
|
-
if (typeof options.queueOptions !== "undefined" && typeof options.queueOptions.
|
|
775
|
+
if (typeof options.queueOptions !== "undefined" && typeof options.queueOptions.maxHistory !== "number")
|
|
765
776
|
throw new OptionError("The manager option 'options.queueOptions.maxPreviousTracks' must be a number.");
|
|
766
777
|
if (typeof options.queueOptions !== "undefined" && typeof options.queueOptions.autoplayFn !== "function")
|
|
767
778
|
throw new OptionError("The manager option 'options.queueOptions.autoplayFn' must be a function.");
|
|
@@ -818,7 +829,15 @@ function validatePlayerData(data) {
|
|
|
818
829
|
player.playing = !data.playerOptions.paused;
|
|
819
830
|
}
|
|
820
831
|
if (typeof data.playerOptions.volume === "number") player.volume = data.playerOptions.volume;
|
|
821
|
-
if (typeof data.playerOptions.position === "number")
|
|
832
|
+
if (typeof data.playerOptions.position === "number") {
|
|
833
|
+
player.lastPosition = data.playerOptions.position;
|
|
834
|
+
player.lastPositionUpdate = Date.now();
|
|
835
|
+
}
|
|
836
|
+
if (typeof data.playerOptions.filters === "object") {
|
|
837
|
+
const timescale = Object.freeze({ ...player.filterManager.data.timescale });
|
|
838
|
+
Object.assign(player.filterManager.data, data.playerOptions.filters);
|
|
839
|
+
player.filterManager.check(timescale);
|
|
840
|
+
}
|
|
822
841
|
}
|
|
823
842
|
}
|
|
824
843
|
function validateNodePlugins(node, plugins) {
|
|
@@ -843,9 +862,11 @@ function validateEngine(type) {
|
|
|
843
862
|
}
|
|
844
863
|
function validateTrack(player, track) {
|
|
845
864
|
if (!track) return Promise.resolve(null);
|
|
846
|
-
|
|
865
|
+
const requesterFn2 = player.manager.options.playerOptions.requesterFn;
|
|
866
|
+
if (isTrack(track)) return Promise.resolve(new Track(track, requesterFn2(track.requester)));
|
|
847
867
|
if (!isUnresolvedTrack(track)) throw new ResolveError("The track is not a valid unresolved track.");
|
|
848
|
-
if (!track.resolve || typeof track.resolve !== "function")
|
|
868
|
+
if (!track.resolve || typeof track.resolve !== "function")
|
|
869
|
+
return new UnresolvedTrack(track, requesterFn2(track.requester)).resolve(player);
|
|
849
870
|
return track.resolve(player);
|
|
850
871
|
}
|
|
851
872
|
var isTrack = (track) => {
|
|
@@ -877,6 +898,9 @@ function stringify(value, space) {
|
|
|
877
898
|
space
|
|
878
899
|
);
|
|
879
900
|
}
|
|
901
|
+
function requesterFn(requester) {
|
|
902
|
+
return requester;
|
|
903
|
+
}
|
|
880
904
|
function isNode(options) {
|
|
881
905
|
return typeof options.host === "string" && typeof options.port === "number" && typeof options.password === "string" && (typeof options.id === "string" || typeof options.id === "undefined") && (typeof options.secure === "boolean" || typeof options.secure === "undefined") && (typeof options.sessionId === "string" || typeof options.sessionId === "undefined") && (typeof options.retryAmount === "number" || typeof options.retryAmount === "undefined") && (typeof options.retryDelay === "number" || typeof options.retryDelay === "undefined");
|
|
882
906
|
}
|
|
@@ -1375,8 +1399,8 @@ async function onEnd() {
|
|
|
1375
1399
|
(x) => x.info.identifier === this.queue.current.info.identifier && x.info.title === this.queue.current.info.title
|
|
1376
1400
|
)) {
|
|
1377
1401
|
this.queue.history.unshift(this.queue.current);
|
|
1378
|
-
if (this.queue.history.length > this.manager.options.queueOptions.
|
|
1379
|
-
this.queue.history.splice(this.manager.options.queueOptions.
|
|
1402
|
+
if (this.queue.history.length > this.manager.options.queueOptions.maxHistory)
|
|
1403
|
+
this.queue.history.splice(this.manager.options.queueOptions.maxHistory, this.queue.history.length);
|
|
1380
1404
|
await this.queue.utils.save();
|
|
1381
1405
|
this.manager.emit(
|
|
1382
1406
|
"debug" /* Debug */,
|
|
@@ -1386,7 +1410,7 @@ async function onEnd() {
|
|
|
1386
1410
|
}
|
|
1387
1411
|
if (this.loop === 1 /* Track */ && this.queue.current) this.queue.unshift(this.queue.current);
|
|
1388
1412
|
if (this.loop === 2 /* Queue */ && this.queue.current) this.queue.add(this.queue.current);
|
|
1389
|
-
if (!this.queue.current) this.queue.current = await validateTrack(this, this.queue.shift());
|
|
1413
|
+
if (!this.queue.current) this.queue.current = await validateTrack(this, await this.queue.shift());
|
|
1390
1414
|
await this.queue.utils.save();
|
|
1391
1415
|
return;
|
|
1392
1416
|
}
|
|
@@ -1492,7 +1516,8 @@ async function playerUpdate(payload) {
|
|
|
1492
1516
|
player.ping = payload.state.ping;
|
|
1493
1517
|
player.connected = payload.state.connected;
|
|
1494
1518
|
player.createdTimestamp = payload.state.time;
|
|
1495
|
-
player.
|
|
1519
|
+
player.lastPosition = payload.state.position || 0;
|
|
1520
|
+
player.lastPositionUpdate = Date.now();
|
|
1496
1521
|
this.nodeManager.manager.emit("playerUpdate" /* PlayerUpdate */, player, oldPlayer, payload);
|
|
1497
1522
|
this.nodeManager.manager.emit(
|
|
1498
1523
|
"debug" /* Debug */,
|
|
@@ -1532,6 +1557,43 @@ async function socketClosed(payload) {
|
|
|
1532
1557
|
`[Player] -> [Socket] The socket has closed: ${this.guildId} | Payload: ${stringify(payload)}`
|
|
1533
1558
|
);
|
|
1534
1559
|
}
|
|
1560
|
+
async function resumeByLibrary(players) {
|
|
1561
|
+
this.nodeManager.manager.emit("debug" /* Debug */, 2 /* Node */, `[Socket] -> [${this.id}]: Resuming session by library...`);
|
|
1562
|
+
for (const player of players) {
|
|
1563
|
+
try {
|
|
1564
|
+
if (!player.playing && !player.paused && !player.queue.totalSize) {
|
|
1565
|
+
this.nodeManager.manager.emit(
|
|
1566
|
+
"debug" /* Debug */,
|
|
1567
|
+
2 /* Node */,
|
|
1568
|
+
`[Player] -> [Resume] Destroyed player for guild ${player.guildId} due to empty queue.`
|
|
1569
|
+
);
|
|
1570
|
+
await player.destroy();
|
|
1571
|
+
return;
|
|
1572
|
+
}
|
|
1573
|
+
const track = player.queue.current;
|
|
1574
|
+
await player.node.updatePlayer({
|
|
1575
|
+
guildId: player.guildId,
|
|
1576
|
+
playerOptions: { voice: player.voice }
|
|
1577
|
+
});
|
|
1578
|
+
await player.connect();
|
|
1579
|
+
await player.queue.utils.sync(false, true);
|
|
1580
|
+
if (track)
|
|
1581
|
+
await player.play({
|
|
1582
|
+
track,
|
|
1583
|
+
noReplace: false,
|
|
1584
|
+
position: player.lastPosition,
|
|
1585
|
+
paused: player.paused
|
|
1586
|
+
});
|
|
1587
|
+
} catch (error) {
|
|
1588
|
+
this.nodeManager.manager.emit("nodeError" /* NodeError */, this, error);
|
|
1589
|
+
}
|
|
1590
|
+
this.nodeManager.manager.emit(
|
|
1591
|
+
"debug" /* Debug */,
|
|
1592
|
+
2 /* Node */,
|
|
1593
|
+
`[Player] -> [Resume] Resumed player for guild ${player.guildId} using the library.`
|
|
1594
|
+
);
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1535
1597
|
|
|
1536
1598
|
// src/util/events/websocket.ts
|
|
1537
1599
|
function onOpen(res) {
|
|
@@ -1604,34 +1666,37 @@ async function onMessage(message) {
|
|
|
1604
1666
|
this.sessionId = payload.sessionId;
|
|
1605
1667
|
this.session.resuming = payload.resumed;
|
|
1606
1668
|
if (payload.resumed) {
|
|
1607
|
-
const
|
|
1669
|
+
const players2 = await this.rest.request({
|
|
1608
1670
|
endpoint: `/sessions/${payload.sessionId}/players`
|
|
1609
1671
|
}) ?? [];
|
|
1610
1672
|
const timeout = this.nodeManager.manager.options.nodeOptions.resumeTimeout;
|
|
1611
|
-
this.nodeManager.manager.emit("nodeResumed" /* NodeResumed */, this,
|
|
1673
|
+
this.nodeManager.manager.emit("nodeResumed" /* NodeResumed */, this, players2, payload);
|
|
1612
1674
|
this.nodeManager.manager.emit(
|
|
1613
1675
|
"debug" /* Debug */,
|
|
1614
1676
|
2 /* Node */,
|
|
1615
|
-
`[Socket] <- [${this.id}]: Resumed session. | Session id: ${payload.sessionId} | Players: ${
|
|
1677
|
+
`[Socket] <- [${this.id}]: Resumed session. | Session id: ${payload.sessionId} | Players: ${players2.length} | Resumed: ${payload.resumed} | Timeout: ${timeout}ms`
|
|
1616
1678
|
);
|
|
1617
1679
|
}
|
|
1680
|
+
const players = this.nodeManager.manager.players.filter((p) => p.node.id === this.id);
|
|
1681
|
+
const isLibrary = this.nodeManager.manager.options.nodeOptions.resumeByLibrary;
|
|
1682
|
+
if (!payload.resumed && isLibrary && players.length) await resumeByLibrary.call(this, players);
|
|
1618
1683
|
this.info = await this.rest.request({ endpoint: "/info" });
|
|
1619
|
-
this.nodeManager.manager.emit(
|
|
1620
|
-
"debug" /* Debug */,
|
|
1621
|
-
2 /* Node */,
|
|
1622
|
-
`[Socket] <- [${this.id}]: Received ready event. | Session id: ${payload.sessionId} | Resumed: ${payload.resumed}`
|
|
1623
|
-
);
|
|
1624
|
-
this.nodeManager.manager.emit("nodeReady" /* NodeReady */, this, this.retryAmount, payload);
|
|
1625
1684
|
const isResumable = this.nodeManager.manager.options.nodeOptions.resumable;
|
|
1626
1685
|
if (isResumable) {
|
|
1627
1686
|
const timeout = this.nodeManager.manager.options.nodeOptions.resumeTimeout;
|
|
1628
1687
|
this.nodeManager.manager.emit(
|
|
1629
1688
|
"debug" /* Debug */,
|
|
1630
1689
|
2 /* Node */,
|
|
1631
|
-
`[Socket] -> [${this.id}]:
|
|
1690
|
+
`[Socket] -> [${this.id}]: Setting timeout to resume session. | Timeout: ${timeout}ms`
|
|
1632
1691
|
);
|
|
1633
1692
|
await this.updateSession(isResumable, timeout);
|
|
1634
1693
|
}
|
|
1694
|
+
this.nodeManager.manager.emit(
|
|
1695
|
+
"debug" /* Debug */,
|
|
1696
|
+
2 /* Node */,
|
|
1697
|
+
`[Socket] <- [${this.id}]: Received ready event. | Session id: ${payload.sessionId} | Resumed: ${payload.resumed}`
|
|
1698
|
+
);
|
|
1699
|
+
this.nodeManager.manager.emit("nodeReady" /* NodeReady */, this, this.retryAmount, payload);
|
|
1635
1700
|
}
|
|
1636
1701
|
break;
|
|
1637
1702
|
case "event" /* Event */: {
|
|
@@ -3005,6 +3070,13 @@ var FilterManager = class {
|
|
|
3005
3070
|
this.filters.timescale = !this.filters.timescale;
|
|
3006
3071
|
return this.apply();
|
|
3007
3072
|
}
|
|
3073
|
+
/**
|
|
3074
|
+
* Convert the filter settings to a JSON object.
|
|
3075
|
+
* @returns {FilterSettings} The filter settings as a JSON object.
|
|
3076
|
+
*/
|
|
3077
|
+
toJSON() {
|
|
3078
|
+
return { ...this.data };
|
|
3079
|
+
}
|
|
3008
3080
|
};
|
|
3009
3081
|
|
|
3010
3082
|
// src/classes/player/Storage.ts
|
|
@@ -3197,10 +3269,23 @@ var Player = class {
|
|
|
3197
3269
|
*/
|
|
3198
3270
|
createdTimestamp = 0;
|
|
3199
3271
|
/**
|
|
3200
|
-
* The position
|
|
3272
|
+
* The last position received from Lavalink.
|
|
3201
3273
|
* @type {number}
|
|
3202
3274
|
*/
|
|
3203
|
-
|
|
3275
|
+
lastPosition = 0;
|
|
3276
|
+
/**
|
|
3277
|
+
* The timestamp when the last position change update happened.
|
|
3278
|
+
* @type {number | null}
|
|
3279
|
+
*/
|
|
3280
|
+
lastPositionUpdate = null;
|
|
3281
|
+
/**
|
|
3282
|
+
* The current calculated position of the player.
|
|
3283
|
+
* @type {number}
|
|
3284
|
+
* @readonly
|
|
3285
|
+
*/
|
|
3286
|
+
get position() {
|
|
3287
|
+
return this.lastPosition + (this.lastPositionUpdate ? Date.now() - this.lastPositionUpdate : 0);
|
|
3288
|
+
}
|
|
3204
3289
|
/**
|
|
3205
3290
|
* The voice connection details.
|
|
3206
3291
|
* @type {PlayerVoice}
|
|
@@ -3322,6 +3407,8 @@ var Player = class {
|
|
|
3322
3407
|
if (typeof position !== "number" || Number.isNaN(position) || position < 0)
|
|
3323
3408
|
throw new PlayerError("Position must be a positive number.");
|
|
3324
3409
|
this.manager.emit("debug" /* Debug */, 3 /* Player */, `[Player] -> [Seek] Seeking to ${position} for guild: ${this.guildId}`);
|
|
3410
|
+
this.lastPosition = position;
|
|
3411
|
+
this.lastPositionUpdate = Date.now();
|
|
3325
3412
|
await this.updatePlayer({ playerOptions: { position } });
|
|
3326
3413
|
}
|
|
3327
3414
|
/**
|
|
@@ -3336,15 +3423,7 @@ var Player = class {
|
|
|
3336
3423
|
*/
|
|
3337
3424
|
async disconnect() {
|
|
3338
3425
|
if (!this.voiceId) return this;
|
|
3339
|
-
await this.
|
|
3340
|
-
op: 4,
|
|
3341
|
-
d: {
|
|
3342
|
-
guild_id: this.guildId,
|
|
3343
|
-
channel_id: null,
|
|
3344
|
-
self_deaf: this.selfDeaf,
|
|
3345
|
-
self_mute: this.selfMute
|
|
3346
|
-
}
|
|
3347
|
-
});
|
|
3426
|
+
await this.setVoice({ voiceId: null });
|
|
3348
3427
|
this.manager.emit("debug" /* Debug */, 3 /* Player */, `[Player] -> [Disconnect] Player disconnected for guild: ${this.guildId}`);
|
|
3349
3428
|
this.connected = false;
|
|
3350
3429
|
return this;
|
|
@@ -3390,15 +3469,20 @@ var Player = class {
|
|
|
3390
3469
|
async play(options = {}) {
|
|
3391
3470
|
if (typeof options !== "object") throw new PlayerError("The play options must be an object.");
|
|
3392
3471
|
if (options.track) this.queue.current = await validateTrack(this, options.track);
|
|
3393
|
-
else if (!this.queue.current) this.queue.current = await validateTrack(this, this.queue.shift());
|
|
3472
|
+
else if (!this.queue.current) this.queue.current = await validateTrack(this, await this.queue.shift());
|
|
3394
3473
|
if (!this.queue.current) throw new PlayerError("No track to play.");
|
|
3395
3474
|
if (!isTrack(this.queue.current) && !isUnresolvedTrack(this.queue.current))
|
|
3396
3475
|
throw new PlayerError("The track must be a valid Track or UnresolvedTrack instance.");
|
|
3397
3476
|
this.manager.emit("debug" /* Debug */, 3 /* Player */, `[Player] -> [Play] A new track is playing: ${this.queue.current.info.title}`);
|
|
3477
|
+
const position = options.position ?? 0;
|
|
3478
|
+
this.lastPosition = position;
|
|
3479
|
+
this.lastPositionUpdate = Date.now();
|
|
3398
3480
|
await this.updatePlayer({
|
|
3399
3481
|
noReplace: options.noReplace,
|
|
3400
3482
|
playerOptions: {
|
|
3401
3483
|
...options,
|
|
3484
|
+
position,
|
|
3485
|
+
// Ensure position is sent to Lavalink
|
|
3402
3486
|
track: {
|
|
3403
3487
|
userData: this.queue.current.userData,
|
|
3404
3488
|
encoded: this.queue.current.encoded
|
|
@@ -3418,15 +3502,7 @@ var Player = class {
|
|
|
3418
3502
|
*/
|
|
3419
3503
|
async connect() {
|
|
3420
3504
|
if (!this.voiceId) return this;
|
|
3421
|
-
await this.
|
|
3422
|
-
op: 4,
|
|
3423
|
-
d: {
|
|
3424
|
-
guild_id: this.guildId,
|
|
3425
|
-
channel_id: this.voiceId,
|
|
3426
|
-
self_deaf: this.selfDeaf,
|
|
3427
|
-
self_mute: this.selfMute
|
|
3428
|
-
}
|
|
3429
|
-
});
|
|
3505
|
+
await this.setVoice();
|
|
3430
3506
|
this.manager.emit("debug" /* Debug */, 3 /* Player */, `[Player] -> [Connect] Player connected for guild: ${this.guildId}`);
|
|
3431
3507
|
this.connected = true;
|
|
3432
3508
|
return this;
|
|
@@ -3448,7 +3524,8 @@ var Player = class {
|
|
|
3448
3524
|
this.manager.emit("debug" /* Debug */, 3 /* Player */, `[Player] -> [Stop] Player stopped for guild: ${this.guildId}`);
|
|
3449
3525
|
this.playing = false;
|
|
3450
3526
|
this.paused = false;
|
|
3451
|
-
this.
|
|
3527
|
+
this.lastPosition = 0;
|
|
3528
|
+
this.lastPositionUpdate = null;
|
|
3452
3529
|
this.queue.current = null;
|
|
3453
3530
|
return;
|
|
3454
3531
|
}
|
|
@@ -3468,6 +3545,12 @@ var Player = class {
|
|
|
3468
3545
|
3 /* Player */,
|
|
3469
3546
|
`[Player] -> [Pause] Player is now ${paused ? "paused" : "resumed"} for guild: ${this.guildId}`
|
|
3470
3547
|
);
|
|
3548
|
+
if (paused) {
|
|
3549
|
+
this.lastPositionUpdate = null;
|
|
3550
|
+
} else {
|
|
3551
|
+
this.lastPosition = this.position;
|
|
3552
|
+
this.lastPositionUpdate = Date.now();
|
|
3553
|
+
}
|
|
3471
3554
|
await this.updatePlayer({ playerOptions: { paused } });
|
|
3472
3555
|
return paused;
|
|
3473
3556
|
}
|
|
@@ -3518,7 +3601,7 @@ var Player = class {
|
|
|
3518
3601
|
}
|
|
3519
3602
|
/**
|
|
3520
3603
|
* Set the voice of the player.
|
|
3521
|
-
* @param {
|
|
3604
|
+
* @param {NullableVoiceChannelUpdate} options The voice state to set.
|
|
3522
3605
|
* @returns {Promise<void>}
|
|
3523
3606
|
* @example
|
|
3524
3607
|
* ```ts
|
|
@@ -3526,27 +3609,17 @@ var Player = class {
|
|
|
3526
3609
|
* player.setVoice({ voiceId: "newVoiceId" });
|
|
3527
3610
|
* ```
|
|
3528
3611
|
*/
|
|
3529
|
-
async setVoice(
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
this.options.voiceId = voice.voiceId;
|
|
3534
|
-
}
|
|
3535
|
-
if (voice.selfDeaf) {
|
|
3536
|
-
this.selfDeaf = voice.selfDeaf;
|
|
3537
|
-
this.options.selfDeaf = voice.selfDeaf;
|
|
3538
|
-
}
|
|
3539
|
-
if (voice.selfMute) {
|
|
3540
|
-
this.selfMute = voice.selfMute;
|
|
3541
|
-
this.options.selfMute = voice.selfMute;
|
|
3542
|
-
}
|
|
3612
|
+
async setVoice(options = {}) {
|
|
3613
|
+
options.voiceId ??= this.voiceId;
|
|
3614
|
+
options.selfDeaf ??= this.selfDeaf;
|
|
3615
|
+
options.selfMute ??= this.selfMute;
|
|
3543
3616
|
await this.manager.options.sendPayload(this.guildId, {
|
|
3544
3617
|
op: 4,
|
|
3545
3618
|
d: {
|
|
3546
3619
|
guild_id: this.guildId,
|
|
3547
|
-
self_deaf:
|
|
3548
|
-
self_mute:
|
|
3549
|
-
channel_id:
|
|
3620
|
+
self_deaf: options.selfDeaf,
|
|
3621
|
+
self_mute: options.selfMute,
|
|
3622
|
+
channel_id: options.voiceId ?? null
|
|
3550
3623
|
}
|
|
3551
3624
|
});
|
|
3552
3625
|
this.manager.emit(
|
|
@@ -3635,6 +3708,13 @@ var Player = class {
|
|
|
3635
3708
|
selfDeaf: this.selfDeaf,
|
|
3636
3709
|
options: this.options,
|
|
3637
3710
|
voice: this.voice,
|
|
3711
|
+
textId: this.textId,
|
|
3712
|
+
lastPosition: this.lastPosition,
|
|
3713
|
+
lastPositionUpdate: this.lastPositionUpdate,
|
|
3714
|
+
position: this.position,
|
|
3715
|
+
createdTimestamp: this.createdTimestamp,
|
|
3716
|
+
ping: this.ping,
|
|
3717
|
+
filters: this.filterManager.toJSON(),
|
|
3638
3718
|
queue: this.queue.toJSON(),
|
|
3639
3719
|
node: this.node.toJSON()
|
|
3640
3720
|
};
|
|
@@ -3756,16 +3836,15 @@ var QueueUtils = class {
|
|
|
3756
3836
|
* ```
|
|
3757
3837
|
*/
|
|
3758
3838
|
save() {
|
|
3759
|
-
const max = this.options.
|
|
3839
|
+
const max = this.options.maxHistory;
|
|
3760
3840
|
const length = this.queue.tracks.length;
|
|
3761
|
-
const json = this.queue.toJSON();
|
|
3762
3841
|
if (length > max) this.queue.history.splice(0, length - max);
|
|
3763
3842
|
this.queue.player.manager.emit(
|
|
3764
3843
|
"debug" /* Debug */,
|
|
3765
3844
|
5 /* Queue */,
|
|
3766
|
-
`[Queue] -> [Adapter] Saving queue for ${this.queue.player.guildId} | Object: ${stringify(
|
|
3845
|
+
`[Queue] -> [Adapter] Saving queue for ${this.queue.player.guildId} | Object: ${stringify(this.queue.toJSON())}`
|
|
3767
3846
|
);
|
|
3768
|
-
return this.store.set(this.queue.player.guildId,
|
|
3847
|
+
return this.store.set(this.queue.player.guildId, this.queue.toJSON());
|
|
3769
3848
|
}
|
|
3770
3849
|
/**
|
|
3771
3850
|
*
|
|
@@ -3931,25 +4010,50 @@ var Queue = class {
|
|
|
3931
4010
|
isEmpty() {
|
|
3932
4011
|
return this.size === 0;
|
|
3933
4012
|
}
|
|
4013
|
+
/**
|
|
4014
|
+
*
|
|
4015
|
+
* Build a track from a Lavalink track or unresolved Lavalink track.
|
|
4016
|
+
* @param {LavalinkTrack | UnresolvedLavalinkTrack} track The track to build.
|
|
4017
|
+
* @param {TrackRequester} requester The requester of the track.
|
|
4018
|
+
* @returns {Promise<Track>} The built track.
|
|
4019
|
+
* @example
|
|
4020
|
+
* ```ts
|
|
4021
|
+
* const queue = player.queue;
|
|
4022
|
+
* const lavalinkTrack = {...} // some lavalink track
|
|
4023
|
+
* const track = await queue.build(lavalinkTrack, author);
|
|
4024
|
+
*
|
|
4025
|
+
* console.log(track.info.title); // The title of the track
|
|
4026
|
+
* ```
|
|
4027
|
+
*/
|
|
4028
|
+
async build(track, requester) {
|
|
4029
|
+
const requesterFn2 = this.player.manager.options.playerOptions.requesterFn;
|
|
4030
|
+
if (isUnresolvedTrack(track)) return new UnresolvedTrack(track, requesterFn2(requester)).resolve(this.player);
|
|
4031
|
+
if (isTrack(track)) return new Track(track, requesterFn2(requester));
|
|
4032
|
+
return track;
|
|
4033
|
+
}
|
|
3934
4034
|
/**
|
|
3935
4035
|
*
|
|
3936
4036
|
* Get the previous track of the queue.
|
|
3937
4037
|
* @param {boolean} [remove=false] Whether to remove the track from the previous queue.
|
|
3938
|
-
* @returns {Track | null} The previous track of the queue.
|
|
4038
|
+
* @returns {Promise<Track | null>} The previous track of the queue.
|
|
3939
4039
|
* @example
|
|
3940
4040
|
* ```ts
|
|
3941
4041
|
* const queue = player.queue;
|
|
3942
4042
|
*
|
|
3943
|
-
* console.log(queue.previous()); // null
|
|
4043
|
+
* console.log(await queue.previous()); // null
|
|
3944
4044
|
* queue.add(track);
|
|
3945
4045
|
* queue.add(track2);
|
|
3946
4046
|
*
|
|
3947
|
-
* console.log(queue.previous()); // track
|
|
3948
|
-
* console.log(queue.previous(true)); // track and remove it from the previous tracks
|
|
4047
|
+
* console.log(await queue.previous()); // track
|
|
4048
|
+
* console.log(await queue.previous(true)); // track and remove it from the previous tracks
|
|
3949
4049
|
* ```
|
|
3950
4050
|
*/
|
|
3951
|
-
previous(remove = false) {
|
|
3952
|
-
if (remove)
|
|
4051
|
+
async previous(remove = false) {
|
|
4052
|
+
if (remove) {
|
|
4053
|
+
const track = this.history.shift() ?? null;
|
|
4054
|
+
if (track) await this.utils.save();
|
|
4055
|
+
return track;
|
|
4056
|
+
}
|
|
3953
4057
|
return this.history[0] ?? null;
|
|
3954
4058
|
}
|
|
3955
4059
|
/**
|
|
@@ -3957,94 +4061,98 @@ var Queue = class {
|
|
|
3957
4061
|
* Add a track or tracks to the queue.
|
|
3958
4062
|
* @param {Track | Track[]} track The track or tracks to add.
|
|
3959
4063
|
* @param {number} [position] The position to add the track or tracks.
|
|
3960
|
-
* @returns {this} The queue instance.
|
|
4064
|
+
* @returns {Promise<this>} The queue instance.
|
|
3961
4065
|
* @example
|
|
3962
4066
|
* ```ts
|
|
3963
4067
|
* const queue = player.queue;
|
|
3964
4068
|
*
|
|
3965
4069
|
* console.log(queue.size); // 0
|
|
3966
4070
|
*
|
|
3967
|
-
* queue.add(track);
|
|
4071
|
+
* await queue.add(track);
|
|
3968
4072
|
* console.log(queue.size); // 1
|
|
3969
4073
|
*
|
|
3970
|
-
* queue.add([track1, track2]);
|
|
4074
|
+
* await queue.add([track1, track2]);
|
|
3971
4075
|
* console.log(queue.size); // 3
|
|
3972
4076
|
*
|
|
3973
|
-
* queue.add(track3, 1);
|
|
4077
|
+
* await queue.add(track3, 1);
|
|
3974
4078
|
* console.log(queue.size); // 4
|
|
3975
4079
|
* console.log(queue.tracks); // [track1, track3, track2, track]
|
|
3976
4080
|
* ```
|
|
3977
4081
|
*/
|
|
3978
|
-
add(track, position) {
|
|
4082
|
+
async add(track, position) {
|
|
3979
4083
|
const tracks = Array.isArray(track) ? track : [track];
|
|
3980
4084
|
if (typeof position === "number" && position >= 0 && position < this.tracks.length) return this.splice(position, 0, ...tracks);
|
|
3981
4085
|
this.tracks.push(...tracks);
|
|
3982
4086
|
this.player.manager.emit("queueUpdate" /* QueueUpdate */, this.player, this);
|
|
3983
4087
|
this.player.manager.emit("debug" /* Debug */, 5 /* Queue */, `[Queue] -> [Add] Added ${this.tracks.length} tracks to the queue.`);
|
|
4088
|
+
await this.utils.save();
|
|
3984
4089
|
return this;
|
|
3985
4090
|
}
|
|
3986
4091
|
/**
|
|
3987
4092
|
*
|
|
3988
4093
|
* Get the first track of the queue.
|
|
3989
|
-
* @returns {HoshimiTrack | null} The first track of the queue.
|
|
4094
|
+
* @returns {Promise<HoshimiTrack | null>} The first track of the queue.
|
|
3990
4095
|
* @example
|
|
3991
4096
|
* ```ts
|
|
3992
4097
|
* const queue = player.queue;
|
|
3993
4098
|
*
|
|
3994
|
-
* console.log(queue.shift()); // null
|
|
3995
|
-
* queue.add(track);
|
|
4099
|
+
* console.log(await queue.shift()); // null
|
|
4100
|
+
* await queue.add(track);
|
|
3996
4101
|
*
|
|
3997
|
-
* console.log(queue.shift()); // track
|
|
3998
|
-
* queue.add(track2);
|
|
4102
|
+
* console.log(await queue.shift()); // track
|
|
4103
|
+
* await queue.add(track2);
|
|
3999
4104
|
* ```
|
|
4000
4105
|
*/
|
|
4001
|
-
shift() {
|
|
4002
|
-
|
|
4106
|
+
async shift() {
|
|
4107
|
+
const track = this.tracks.shift() ?? null;
|
|
4108
|
+
if (track) await this.utils.save();
|
|
4109
|
+
return track;
|
|
4003
4110
|
}
|
|
4004
4111
|
/**
|
|
4005
4112
|
*
|
|
4006
4113
|
* Add tracks to the beginning of the queue.
|
|
4007
4114
|
* @param {Track[]} tracks The tracks to add.
|
|
4008
|
-
* @returns {this} The queue instance.
|
|
4115
|
+
* @returns {Promise<this>} The queue instance.
|
|
4009
4116
|
* @example
|
|
4010
4117
|
* ```ts
|
|
4011
4118
|
* const queue = player.queue;
|
|
4012
4119
|
*
|
|
4013
4120
|
* console.log(queue.size); // 0
|
|
4014
|
-
* queue.unshift(track);
|
|
4121
|
+
* await queue.unshift(track);
|
|
4015
4122
|
*
|
|
4016
4123
|
* console.log(queue.size); // 1
|
|
4017
|
-
* queue.unshift(
|
|
4124
|
+
* await queue.unshift(track1, track2);
|
|
4018
4125
|
*
|
|
4019
4126
|
* console.log(queue.size); // 3
|
|
4020
4127
|
* console.log(queue.tracks); // [track1, track2, track]
|
|
4021
4128
|
* ```
|
|
4022
4129
|
*/
|
|
4023
|
-
unshift(...tracks) {
|
|
4130
|
+
async unshift(...tracks) {
|
|
4024
4131
|
this.tracks.unshift(...tracks);
|
|
4025
4132
|
this.player.manager.emit("debug" /* Debug */, 5 /* Queue */, `[Queue] -> [Unshift] Added ${this.tracks.length} tracks to the queue.`);
|
|
4133
|
+
await this.utils.save();
|
|
4026
4134
|
return this;
|
|
4027
4135
|
}
|
|
4028
4136
|
/**
|
|
4029
4137
|
*
|
|
4030
4138
|
* Shuffle the queue.
|
|
4031
|
-
* @returns {this} The queue instance.
|
|
4139
|
+
* @returns {Promise<this>} The queue instance.
|
|
4032
4140
|
* @example
|
|
4033
4141
|
* ```ts
|
|
4034
4142
|
* const queue = player.queue;
|
|
4035
4143
|
*
|
|
4036
4144
|
* console.log(queue.size); // 0
|
|
4037
|
-
* queue.add(track);
|
|
4038
|
-
* queue.add(
|
|
4145
|
+
* await queue.add(track);
|
|
4146
|
+
* await queue.add(track1, track2);
|
|
4039
4147
|
*
|
|
4040
4148
|
* console.log(queue.size); // 3
|
|
4041
4149
|
* console.log(queue.tracks); // [track, track1, track2]
|
|
4042
4150
|
*
|
|
4043
|
-
* queue.shuffle();
|
|
4151
|
+
* await queue.shuffle();
|
|
4044
4152
|
* console.log(queue.tracks); // [track2, track, track1]
|
|
4045
4153
|
* ```
|
|
4046
4154
|
*/
|
|
4047
|
-
shuffle() {
|
|
4155
|
+
async shuffle() {
|
|
4048
4156
|
if (this.size <= 1) return this;
|
|
4049
4157
|
if (this.size === 2) [this.tracks[0], this.tracks[1]] = [this.tracks[1], this.tracks[0]];
|
|
4050
4158
|
else {
|
|
@@ -4055,31 +4163,33 @@ var Queue = class {
|
|
|
4055
4163
|
}
|
|
4056
4164
|
this.player.manager.emit("queueUpdate" /* QueueUpdate */, this.player, this);
|
|
4057
4165
|
this.player.manager.emit("debug" /* Debug */, 5 /* Queue */, "[Queue] -> [Shuffle] Shuffled the queue.");
|
|
4166
|
+
await this.utils.save();
|
|
4058
4167
|
return this;
|
|
4059
4168
|
}
|
|
4060
4169
|
/**
|
|
4061
4170
|
*
|
|
4062
4171
|
* Clear the queue.
|
|
4063
|
-
* @returns {this} The queue instance.
|
|
4172
|
+
* @returns {Promise<this>} The queue instance.
|
|
4064
4173
|
* @example
|
|
4065
4174
|
* ```ts
|
|
4066
4175
|
* const queue = player.queue;
|
|
4067
4176
|
*
|
|
4068
4177
|
* console.log(queue.size); // 0
|
|
4069
|
-
* queue.add(track);
|
|
4070
|
-
* queue.add(
|
|
4178
|
+
* await queue.add(track);
|
|
4179
|
+
* await queue.add(track1, track2);
|
|
4071
4180
|
*
|
|
4072
4181
|
* console.log(queue.size); // 3
|
|
4073
|
-
* queue.clear();
|
|
4182
|
+
* await queue.clear();
|
|
4074
4183
|
* console.log(queue.size); // 0
|
|
4075
4184
|
* ```
|
|
4076
4185
|
*/
|
|
4077
|
-
clear() {
|
|
4186
|
+
async clear() {
|
|
4078
4187
|
this.tracks = [];
|
|
4079
4188
|
this.history = [];
|
|
4080
4189
|
this.current = null;
|
|
4081
4190
|
this.player.manager.emit("queueUpdate" /* QueueUpdate */, this.player, this);
|
|
4082
4191
|
this.player.manager.emit("debug" /* Debug */, 5 /* Queue */, "[Queue] -> [Clear] Cleared the queue.");
|
|
4192
|
+
await this.utils.save();
|
|
4083
4193
|
return this;
|
|
4084
4194
|
}
|
|
4085
4195
|
/**
|
|
@@ -4087,15 +4197,16 @@ var Queue = class {
|
|
|
4087
4197
|
* Move a track to a specific position in the queue.
|
|
4088
4198
|
* @param {Track} track The track to move.
|
|
4089
4199
|
* @param {number} to The position to move.
|
|
4090
|
-
* @returns {this} The queue instance.
|
|
4200
|
+
* @returns {Promise<this>} The queue instance.
|
|
4091
4201
|
*/
|
|
4092
|
-
move(track, to) {
|
|
4202
|
+
async move(track, to) {
|
|
4093
4203
|
const index = this.tracks.indexOf(track);
|
|
4094
4204
|
if (index === -1) return this;
|
|
4095
|
-
this.splice(index, 1);
|
|
4096
|
-
this.add(track, to - 1);
|
|
4205
|
+
await this.splice(index, 1);
|
|
4206
|
+
await this.add(track, to - 1);
|
|
4097
4207
|
this.player.manager.emit("queueUpdate" /* QueueUpdate */, this.player, this);
|
|
4098
4208
|
this.player.manager.emit("debug" /* Debug */, 5 /* Queue */, `[Queue] -> [Move] Moved track ${track.info.title} to position ${to}.`);
|
|
4209
|
+
await this.utils.save();
|
|
4099
4210
|
return this;
|
|
4100
4211
|
}
|
|
4101
4212
|
/**
|
|
@@ -4104,14 +4215,15 @@ var Queue = class {
|
|
|
4104
4215
|
* @param {number} start The start index.
|
|
4105
4216
|
* @param {number} deleteCount The number of tracks to delete.
|
|
4106
4217
|
* @param {Track | Track[]} [tracks] The tracks to add.
|
|
4107
|
-
* @returns {this} The queue instance.
|
|
4218
|
+
* @returns {Promise<this>} The queue instance.
|
|
4108
4219
|
*/
|
|
4109
|
-
splice(start, deleteCount, tracks) {
|
|
4110
|
-
if (!this.size && tracks) this.add(tracks);
|
|
4220
|
+
async splice(start, deleteCount, tracks) {
|
|
4221
|
+
if (!this.size && tracks) await this.add(tracks);
|
|
4111
4222
|
if (tracks) this.tracks.splice(start, deleteCount, ...Array.isArray(tracks) ? tracks : [tracks]);
|
|
4112
4223
|
else this.tracks.splice(start, deleteCount);
|
|
4113
4224
|
this.player.manager.emit("queueUpdate" /* QueueUpdate */, this.player, this);
|
|
4114
4225
|
this.player.manager.emit("debug" /* Debug */, 5 /* Queue */, `[Queue] -> [Splice] Removed ${deleteCount} tracks from the queue.`);
|
|
4226
|
+
await this.utils.save();
|
|
4115
4227
|
return this;
|
|
4116
4228
|
}
|
|
4117
4229
|
/**
|
|
@@ -4120,7 +4232,7 @@ var Queue = class {
|
|
|
4120
4232
|
* @returns {QueueJson} The queue JSON object.
|
|
4121
4233
|
*/
|
|
4122
4234
|
toJSON() {
|
|
4123
|
-
const max = this.player.manager.options.queueOptions.
|
|
4235
|
+
const max = this.player.manager.options.queueOptions.maxHistory;
|
|
4124
4236
|
if (this.history.length > max) this.history.splice(max, this.history.length);
|
|
4125
4237
|
return {
|
|
4126
4238
|
tracks: this.tracks,
|
|
@@ -4286,10 +4398,24 @@ var Hoshimi = class extends import_node_events.EventEmitter {
|
|
|
4286
4398
|
* resumeByLibrary: false,
|
|
4287
4399
|
* },
|
|
4288
4400
|
* queueOptions: {
|
|
4289
|
-
*
|
|
4290
|
-
*
|
|
4291
|
-
*
|
|
4401
|
+
* maxHistory: 25,
|
|
4402
|
+
* autoplayFn: autoplayFn,
|
|
4403
|
+
* autoPlay: false,
|
|
4404
|
+
* storage: new MemoryAdapter(),
|
|
4405
|
+
* requesterFn: defaultRequesterFn,
|
|
4292
4406
|
* },
|
|
4407
|
+
* playerOptions: {
|
|
4408
|
+
* onDisconnect: {
|
|
4409
|
+
* autoDestroy: false,
|
|
4410
|
+
* autoReconnect: false,
|
|
4411
|
+
* autoQueue: false,
|
|
4412
|
+
* },
|
|
4413
|
+
* onError: {
|
|
4414
|
+
* autoDestroy: false,
|
|
4415
|
+
* autoSkip: false,
|
|
4416
|
+
* autoStop: false,
|
|
4417
|
+
* },
|
|
4418
|
+
* },
|
|
4293
4419
|
* });
|
|
4294
4420
|
*
|
|
4295
4421
|
* console.log(manager); // The manager instance
|
|
@@ -4311,11 +4437,24 @@ var Hoshimi = class extends import_node_events.EventEmitter {
|
|
|
4311
4437
|
resumeTimeout: options.nodeOptions?.resumeTimeout ?? 1e4
|
|
4312
4438
|
},
|
|
4313
4439
|
queueOptions: {
|
|
4314
|
-
|
|
4440
|
+
maxHistory: options.queueOptions?.maxHistory ?? 25,
|
|
4315
4441
|
autoplayFn: options.queueOptions?.autoplayFn ?? autoplayFn,
|
|
4316
4442
|
autoPlay: options.queueOptions?.autoPlay ?? false,
|
|
4317
4443
|
storage: options.queueOptions?.storage ?? new MemoryAdapter()
|
|
4318
4444
|
},
|
|
4445
|
+
playerOptions: {
|
|
4446
|
+
requesterFn: options.playerOptions?.requesterFn ?? requesterFn,
|
|
4447
|
+
onDisconnect: {
|
|
4448
|
+
autoDestroy: options.playerOptions?.onDisconnect?.autoDestroy ?? false,
|
|
4449
|
+
autoReconnect: options.playerOptions?.onDisconnect?.autoReconnect ?? true,
|
|
4450
|
+
autoQueue: options.playerOptions?.onDisconnect?.autoQueue ?? false
|
|
4451
|
+
},
|
|
4452
|
+
onError: {
|
|
4453
|
+
autoDestroy: options.playerOptions?.onError?.autoDestroy ?? false,
|
|
4454
|
+
autoSkip: options.playerOptions?.onError?.autoSkip ?? false,
|
|
4455
|
+
autoStop: options.playerOptions?.onError?.autoStop ?? false
|
|
4456
|
+
}
|
|
4457
|
+
},
|
|
4319
4458
|
client: {
|
|
4320
4459
|
id: options.client?.id ?? "",
|
|
4321
4460
|
username: options.client?.username ?? "hoshimi-client"
|
|
@@ -4452,6 +4591,56 @@ var Hoshimi = class extends import_node_events.EventEmitter {
|
|
|
4452
4591
|
);
|
|
4453
4592
|
return;
|
|
4454
4593
|
}
|
|
4594
|
+
if ("channel_id" in data && typeof data.channel_id === "string") {
|
|
4595
|
+
if (data.channel_id !== player.voiceId) {
|
|
4596
|
+
this.emit(
|
|
4597
|
+
"debug" /* Debug */,
|
|
4598
|
+
3 /* Player */,
|
|
4599
|
+
`[Player] -> [Voice] Updating the voice channel for: ${data.guild_id} | Old: ${player.voiceId} | New: ${data.channel_id}`
|
|
4600
|
+
);
|
|
4601
|
+
player.voice.sessionId = data.session_id ?? player.voice.sessionId;
|
|
4602
|
+
player.voiceId = data.channel_id;
|
|
4603
|
+
player.options.voiceId = data.channel_id;
|
|
4604
|
+
if (!player.connected) await player.connect();
|
|
4605
|
+
return;
|
|
4606
|
+
}
|
|
4607
|
+
} else {
|
|
4608
|
+
this.emit("debug" /* Debug */, 3 /* Player */, `[Player] -> [Voice] The channel id is missing for: ${data.guild_id}`);
|
|
4609
|
+
const { autoDestroy, autoReconnect, autoQueue } = this.options.playerOptions.onDisconnect;
|
|
4610
|
+
if (autoDestroy) {
|
|
4611
|
+
await player.destroy("Player-VoiceChannelLeft" /* VoiceChannelLeft */);
|
|
4612
|
+
return;
|
|
4613
|
+
}
|
|
4614
|
+
if (autoReconnect) {
|
|
4615
|
+
try {
|
|
4616
|
+
const position = player.position;
|
|
4617
|
+
const paused = player.paused;
|
|
4618
|
+
this.emit(
|
|
4619
|
+
"debug" /* Debug */,
|
|
4620
|
+
3 /* Player */,
|
|
4621
|
+
`[Player] -> [Voice] Attempting to reconnect the player for: ${data.guild_id}`
|
|
4622
|
+
);
|
|
4623
|
+
if (autoQueue && player.queue.current && !player.queue.isEmpty()) await player.connect();
|
|
4624
|
+
if (player.queue.current) return player.play({ track: player.queue.current, paused, position });
|
|
4625
|
+
if (!player.queue.isEmpty()) return player.play({ paused });
|
|
4626
|
+
this.emit(
|
|
4627
|
+
"debug" /* Debug */,
|
|
4628
|
+
3 /* Player */,
|
|
4629
|
+
`[Player] -> [Voice] No tracks to play after reconnect for: ${data.guild_id}`
|
|
4630
|
+
);
|
|
4631
|
+
} catch (error) {
|
|
4632
|
+
this.emit("playerError" /* PlayerError */, player, error);
|
|
4633
|
+
await player.destroy("Player-ReconnectFailed" /* ReconnectFailed */);
|
|
4634
|
+
}
|
|
4635
|
+
}
|
|
4636
|
+
player.voiceId = void 0;
|
|
4637
|
+
player.voice = {
|
|
4638
|
+
endpoint: null,
|
|
4639
|
+
sessionId: null,
|
|
4640
|
+
token: null
|
|
4641
|
+
};
|
|
4642
|
+
return;
|
|
4643
|
+
}
|
|
4455
4644
|
this.emit("debug" /* Debug */, 3 /* Player */, `[Player] -> [Voice] The player voice is missing for: ${data.guild_id}`);
|
|
4456
4645
|
}
|
|
4457
4646
|
break;
|
|
@@ -4561,6 +4750,7 @@ var Hoshimi = class extends import_node_events.EventEmitter {
|
|
|
4561
4750
|
1 /* Manager */,
|
|
4562
4751
|
`[Manager] -> [Search] Searching for: ${options.query} (${options.engine ?? "unknown"}) | Result: ${stringify(res)}`
|
|
4563
4752
|
);
|
|
4753
|
+
const requesterFn2 = this.options.playerOptions.requesterFn;
|
|
4564
4754
|
switch (res.loadType) {
|
|
4565
4755
|
case "empty" /* Empty */: {
|
|
4566
4756
|
return {
|
|
@@ -4586,7 +4776,7 @@ var Hoshimi = class extends import_node_events.EventEmitter {
|
|
|
4586
4776
|
exception: null,
|
|
4587
4777
|
playlist: res.data,
|
|
4588
4778
|
pluginInfo: res.data.pluginInfo,
|
|
4589
|
-
tracks: res.data.tracks.map((t) => new Track(t, options.requester))
|
|
4779
|
+
tracks: res.data.tracks.map((t) => new Track(t, requesterFn2(options.requester)))
|
|
4590
4780
|
};
|
|
4591
4781
|
}
|
|
4592
4782
|
case "search" /* Search */: {
|
|
@@ -4595,7 +4785,7 @@ var Hoshimi = class extends import_node_events.EventEmitter {
|
|
|
4595
4785
|
exception: null,
|
|
4596
4786
|
playlist: null,
|
|
4597
4787
|
pluginInfo: null,
|
|
4598
|
-
tracks: res.data.map((t) => new Track(t, options.requester))
|
|
4788
|
+
tracks: res.data.map((t) => new Track(t, requesterFn2(options.requester)))
|
|
4599
4789
|
};
|
|
4600
4790
|
}
|
|
4601
4791
|
case "track" /* Track */: {
|
|
@@ -4604,7 +4794,7 @@ var Hoshimi = class extends import_node_events.EventEmitter {
|
|
|
4604
4794
|
exception: null,
|
|
4605
4795
|
playlist: null,
|
|
4606
4796
|
pluginInfo: res.data.pluginInfo,
|
|
4607
|
-
tracks: [new Track(res.data, options.requester)]
|
|
4797
|
+
tracks: [new Track(res.data, requesterFn2(options.requester))]
|
|
4608
4798
|
};
|
|
4609
4799
|
}
|
|
4610
4800
|
}
|