Compare commits
10 commits
0ab06128ac
...
6f189cc523
Author | SHA1 | Date | |
---|---|---|---|
|
6f189cc523 | ||
|
d7ce7acb22 | ||
|
5dc2774e0f | ||
|
2f9c48b927 | ||
|
83c6179e1e | ||
|
241a22b5d1 | ||
|
ca53b6da0c | ||
|
641ef8ee85 | ||
|
5d57f6589a | ||
|
e2fad021d6 |
18 changed files with 2514 additions and 2476 deletions
|
@ -17,6 +17,7 @@
|
|||
"@typescript-eslint/no-explicit-any": "error",
|
||||
"@typescript-eslint/ban-ts-comment": "error",
|
||||
"semi": "error",
|
||||
"no-console": "error"
|
||||
"no-console": "error",
|
||||
"no-mixed-spaces-and-tabs": "off"
|
||||
}
|
||||
}
|
|
@ -3,5 +3,6 @@
|
|||
"trailingComma": "none",
|
||||
"singleQuote": false,
|
||||
"tabWidth": 4,
|
||||
"useTabs": true,
|
||||
"semi": true
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "discord-player-play-dl",
|
||||
"version": "5.3.8",
|
||||
"version": "5.3.14",
|
||||
"description": "Complete framework to facilitate music commands using discord.js and play-dl",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
|
|
@ -142,6 +142,27 @@ class Player extends EventEmitter<PlayerEvents> {
|
|||
queue._cooldownsTimeout.set(`empty_${oldState.guild.id}`, timeout);
|
||||
}
|
||||
}
|
||||
|
||||
if (queue.connection && oldState.channelId && newState.channelId && oldState.channelId !== newState.channelId && newState.member.id != newState.guild.members.me.id) {
|
||||
if (newState.channelId !== queue.connection.channel.id) {
|
||||
if (!Util.isVoiceEmpty(queue.connection.channel)) return;
|
||||
if (queue._cooldownsTimeout.has(`empty_${oldState.guild.id}`)) return;
|
||||
const timeout = setTimeout(() => {
|
||||
if (!Util.isVoiceEmpty(queue.connection.channel)) return;
|
||||
if (!this.queues.has(queue.guild.id)) return;
|
||||
if (queue.options.leaveOnEmpty) queue.destroy(true);
|
||||
this.emit("channelEmpty", queue);
|
||||
}, queue.options.leaveOnEmptyCooldown || 0).unref();
|
||||
queue._cooldownsTimeout.set(`empty_${oldState.guild.id}`, timeout);
|
||||
} else {
|
||||
const emptyTimeout = queue._cooldownsTimeout.get(`empty_${oldState.guild.id}`);
|
||||
const channelEmpty = Util.isVoiceEmpty(queue.connection.channel);
|
||||
if (!channelEmpty && emptyTimeout) {
|
||||
clearTimeout(emptyTimeout);
|
||||
queue._cooldownsTimeout.delete(`empty_${oldState.guild.id}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -101,7 +101,7 @@ class Queue<T = unknown> {
|
|||
leaveOnStop: true,
|
||||
leaveOnEmpty: true,
|
||||
leaveOnEmptyCooldown: 1000,
|
||||
autoSelfDeaf: true,
|
||||
autoSelfDeaf: false,
|
||||
initialVolume: 100,
|
||||
bufferingTimeout: 3000,
|
||||
disableVolume: false
|
||||
|
@ -192,10 +192,10 @@ class Queue<T = unknown> {
|
|||
if (this.options.leaveOnEnd) this.destroy();
|
||||
this.player.emit("queueEnd", this);
|
||||
} else if (!this.tracks.length && this.repeatMode === QueueRepeatMode.AUTOPLAY) {
|
||||
this._handleAutoplay(Util.last(this.previousTracks));
|
||||
this._handleAutoplay(this.current);
|
||||
} else {
|
||||
if (this.repeatMode === QueueRepeatMode.TRACK) return void this.play(Util.last(this.previousTracks), { immediate: true });
|
||||
if (this.repeatMode === QueueRepeatMode.QUEUE) this.tracks.push(Util.last(this.previousTracks));
|
||||
if (this.repeatMode === QueueRepeatMode.TRACK) return void this.play(this.current, { immediate: true });
|
||||
if (this.repeatMode === QueueRepeatMode.QUEUE) this.tracks.push(this.current);
|
||||
const nextTrack = this.tracks.shift();
|
||||
this.play(nextTrack, { immediate: true });
|
||||
return;
|
||||
|
@ -420,7 +420,7 @@ class Queue<T = unknown> {
|
|||
*/
|
||||
async back() {
|
||||
if (this.#watchDestroyed()) return;
|
||||
const prev = this.previousTracks[this.previousTracks.length - 2]; // because last item is the current track
|
||||
const prev = this.previousTracks[this.previousTracks.length - 1];
|
||||
if (!prev) throw new PlayerError("Could not find previous track", ErrorStatusCode.TRACK_NOT_FOUND);
|
||||
|
||||
return await this.play(prev, { immediate: true });
|
||||
|
@ -575,7 +575,7 @@ class Queue<T = unknown> {
|
|||
if (this.#watchDestroyed()) return;
|
||||
const length = typeof options.length === "number" ? (options.length <= 0 || options.length === Infinity ? 15 : options.length) : 15;
|
||||
|
||||
const index = Math.round((this.streamTime / this.current.durationMS) * length);
|
||||
const index = Math.floor((this.streamTime / this.current.durationMS) * length);
|
||||
const indicator = typeof options.indicator === "string" && options.indicator.length > 0 ? options.indicator : "🔘";
|
||||
const line = typeof options.line === "string" && options.line.length > 0 ? options.line : "▬";
|
||||
|
||||
|
@ -622,20 +622,26 @@ class Queue<T = unknown> {
|
|||
|
||||
this.player.emit("debug", this, "Received play request");
|
||||
|
||||
if (!options.filtersUpdate) {
|
||||
this.previousTracks = this.previousTracks.filter((x) => x.id !== track.id);
|
||||
this.previousTracks.push(track);
|
||||
}
|
||||
if (!options.filtersUpdate) this.previousTracks = this.previousTracks.filter((x) => x.id !== track.id);
|
||||
|
||||
let stream = null;
|
||||
const hasCustomDownloader = typeof this.onBeforeCreateStream === "function";
|
||||
|
||||
if (["youtube", "spotify", "soundcloud"].includes(track.raw.source)) {
|
||||
let spotifyResolved = false;
|
||||
if (track.raw.source === "spotify" && !track.raw.engine) {
|
||||
track.raw.engine = await play
|
||||
.search(`${track.author} ${track.title}`, { limit: 5 })
|
||||
.then((res) => res[0].url)
|
||||
.catch(Util.noop);
|
||||
spotifyResolved = true;
|
||||
}
|
||||
|
||||
const url = track.raw.source === "spotify" ? track.raw.engine : track.url;
|
||||
if (!url) return void this.play(this.tracks.shift(), { immediate: true });
|
||||
|
||||
if (hasCustomDownloader) {
|
||||
stream = (await this.onBeforeCreateStream(track, "youtube", this)) || null;
|
||||
stream = (await this.onBeforeCreateStream(track, spotifyResolved ? "youtube" : track.raw.source, this)) || null;
|
||||
}
|
||||
|
||||
if (!stream) {
|
||||
|
@ -643,12 +649,7 @@ class Queue<T = unknown> {
|
|||
}
|
||||
} else {
|
||||
const arbitraryStream = (hasCustomDownloader && (await this.onBeforeCreateStream(track, track.raw.source || track.raw.engine, this))) || null;
|
||||
stream =
|
||||
arbitraryStream
|
||||
? await track.raw.engine.downloadProgressive()
|
||||
: typeof track.raw.engine === "function"
|
||||
? await track.raw.engine()
|
||||
: track.raw.engine;
|
||||
stream = arbitraryStream ? await track.raw.engine.downloadProgressive() : typeof track.raw.engine === "function" ? await track.raw.engine() : track.raw.engine;
|
||||
}
|
||||
|
||||
const ffmpegStream = createFFmpegStream(stream, {
|
||||
|
|
|
@ -9,7 +9,8 @@ import {
|
|||
StreamType,
|
||||
VoiceConnection,
|
||||
VoiceConnectionStatus,
|
||||
VoiceConnectionDisconnectReason
|
||||
VoiceConnectionDisconnectReason,
|
||||
VoiceConnectionState
|
||||
} from "@discordjs/voice";
|
||||
import { StageChannel, VoiceChannel } from "discord.js";
|
||||
import { Duplex, Readable } from "stream";
|
||||
|
@ -68,7 +69,20 @@ class StreamDispatcher extends EventEmitter<VoiceEvents> {
|
|||
*/
|
||||
this.paused = false;
|
||||
|
||||
this.voiceConnection.on("stateChange", async (_, newState) => {
|
||||
this.voiceConnection.on("stateChange", async (oldState, newState) => {
|
||||
// oh no, fix no work
|
||||
const oldNetworking = Reflect.get(oldState, "networking");
|
||||
const newNetworking = Reflect.get(newState, "networking");
|
||||
|
||||
const networkStateChangeHandler = (_: VoiceConnectionState, newNetworkState: VoiceConnectionState) => {
|
||||
const newUdp = Reflect.get(newNetworkState, "udp");
|
||||
clearInterval(newUdp?.keepAliveInterval);
|
||||
};
|
||||
|
||||
oldNetworking?.off("stateChange", networkStateChangeHandler);
|
||||
newNetworking?.on("stateChange", networkStateChangeHandler);
|
||||
// temp fix end
|
||||
|
||||
if (newState.status === VoiceConnectionStatus.Disconnected) {
|
||||
if (newState.reason === VoiceConnectionDisconnectReason.WebSocketClose && newState.closeCode === 4014) {
|
||||
try {
|
||||
|
|
|
@ -130,7 +130,7 @@ export interface PlayerProgressbarOptions {
|
|||
* @property {boolean} [leaveOnStop=true] If it should leave on stop
|
||||
* @property {boolean} [leaveOnEmpty=true] If it should leave on empty
|
||||
* @property {number} [leaveOnEmptyCooldown=1000] The cooldown in ms
|
||||
* @property {boolean} [autoSelfDeaf=true] If it should set the bot in deaf mode
|
||||
* @property {boolean} [autoSelfDeaf=false] If it should set the bot in deaf mode
|
||||
* @property {number} [initialVolume=100] The initial player volume
|
||||
* @property {number} [bufferingTimeout=3000] Buffering timeout for the stream
|
||||
* @property {boolean} [disableVolume=false] If player should disable inline volume
|
||||
|
|
Loading…
Reference in a new issue