Compare commits

...

10 commits

Author SHA1 Message Date
Jonny_Bro (Nikita)
6f189cc523 v5.3.14
Waiting for proper fix...
2023-03-15 23:39:47 +05:00
Jonny_Bro (Nikita)
d7ce7acb22 v5.3.13 - 1 minute connection bug is fixed!
Update @discordjs/voice to 0.15.0 or @latest
2023-03-14 13:32:09 +05:00
Jonny_Bro (Nikita)
5dc2774e0f v5.3.12
Temporary fix for voice connection issues
2023-03-02 22:10:25 +05:00
Jonny_Bro (Nikita)
2f9c48b927 rule for formatter 2023-03-01 23:48:36 +05:00
Jonny_Bro (Nikita)
83c6179e1e format with tabs 2023-03-01 23:48:04 +05:00
JonnyBro
241a22b5d1 pretty 2023-02-22 13:48:29 +05:00
JonnyBro
ca53b6da0c v5.3.11
Somewhat working Spotify support
2023-02-22 13:47:18 +05:00
JonnyBro
641ef8ee85 v5.3.10
fixed current track to not add twice to previousTracks
fixed bot disconnection on member move
Thanks PR's from original repo!
2023-01-04 00:22:41 +05:00
JonnyBro
5d57f6589a pretty 2022-10-31 14:16:46 +05:00
JonnyBro
e2fad021d6 v5.3.9 2022-10-31 14:16:33 +05:00
18 changed files with 2514 additions and 2476 deletions

View file

@ -17,6 +17,7 @@
"@typescript-eslint/no-explicit-any": "error", "@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/ban-ts-comment": "error", "@typescript-eslint/ban-ts-comment": "error",
"semi": "error", "semi": "error",
"no-console": "error" "no-console": "error",
"no-mixed-spaces-and-tabs": "off"
} }
} }

View file

@ -3,5 +3,6 @@
"trailingComma": "none", "trailingComma": "none",
"singleQuote": false, "singleQuote": false,
"tabWidth": 4, "tabWidth": 4,
"useTabs": true,
"semi": true "semi": true
} }

View file

@ -1,6 +1,6 @@
{ {
"name": "discord-player-play-dl", "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", "description": "Complete framework to facilitate music commands using discord.js and play-dl",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",

View file

@ -142,6 +142,27 @@ class Player extends EventEmitter<PlayerEvents> {
queue._cooldownsTimeout.set(`empty_${oldState.guild.id}`, timeout); 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}`);
}
}
}
} }
/** /**

View file

@ -101,7 +101,7 @@ class Queue<T = unknown> {
leaveOnStop: true, leaveOnStop: true,
leaveOnEmpty: true, leaveOnEmpty: true,
leaveOnEmptyCooldown: 1000, leaveOnEmptyCooldown: 1000,
autoSelfDeaf: true, autoSelfDeaf: false,
initialVolume: 100, initialVolume: 100,
bufferingTimeout: 3000, bufferingTimeout: 3000,
disableVolume: false disableVolume: false
@ -192,10 +192,10 @@ class Queue<T = unknown> {
if (this.options.leaveOnEnd) this.destroy(); if (this.options.leaveOnEnd) this.destroy();
this.player.emit("queueEnd", this); this.player.emit("queueEnd", this);
} else if (!this.tracks.length && this.repeatMode === QueueRepeatMode.AUTOPLAY) { } else if (!this.tracks.length && this.repeatMode === QueueRepeatMode.AUTOPLAY) {
this._handleAutoplay(Util.last(this.previousTracks)); this._handleAutoplay(this.current);
} else { } else {
if (this.repeatMode === QueueRepeatMode.TRACK) return void this.play(Util.last(this.previousTracks), { immediate: true }); if (this.repeatMode === QueueRepeatMode.TRACK) return void this.play(this.current, { immediate: true });
if (this.repeatMode === QueueRepeatMode.QUEUE) this.tracks.push(Util.last(this.previousTracks)); if (this.repeatMode === QueueRepeatMode.QUEUE) this.tracks.push(this.current);
const nextTrack = this.tracks.shift(); const nextTrack = this.tracks.shift();
this.play(nextTrack, { immediate: true }); this.play(nextTrack, { immediate: true });
return; return;
@ -420,7 +420,7 @@ class Queue<T = unknown> {
*/ */
async back() { async back() {
if (this.#watchDestroyed()) return; 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); if (!prev) throw new PlayerError("Could not find previous track", ErrorStatusCode.TRACK_NOT_FOUND);
return await this.play(prev, { immediate: true }); return await this.play(prev, { immediate: true });
@ -575,7 +575,7 @@ class Queue<T = unknown> {
if (this.#watchDestroyed()) return; if (this.#watchDestroyed()) return;
const length = typeof options.length === "number" ? (options.length <= 0 || options.length === Infinity ? 15 : options.length) : 15; 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 indicator = typeof options.indicator === "string" && options.indicator.length > 0 ? options.indicator : "🔘";
const line = typeof options.line === "string" && options.line.length > 0 ? options.line : "▬"; 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"); this.player.emit("debug", this, "Received play request");
if (!options.filtersUpdate) { if (!options.filtersUpdate) this.previousTracks = this.previousTracks.filter((x) => x.id !== track.id);
this.previousTracks = this.previousTracks.filter((x) => x.id !== track.id);
this.previousTracks.push(track);
}
let stream = null; let stream = null;
const hasCustomDownloader = typeof this.onBeforeCreateStream === "function"; const hasCustomDownloader = typeof this.onBeforeCreateStream === "function";
if (["youtube", "spotify", "soundcloud"].includes(track.raw.source)) { 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; const url = track.raw.source === "spotify" ? track.raw.engine : track.url;
if (!url) return void this.play(this.tracks.shift(), { immediate: true }); if (!url) return void this.play(this.tracks.shift(), { immediate: true });
if (hasCustomDownloader) { if (hasCustomDownloader) {
stream = (await this.onBeforeCreateStream(track, "youtube", this)) || null; stream = (await this.onBeforeCreateStream(track, spotifyResolved ? "youtube" : track.raw.source, this)) || null;
} }
if (!stream) { if (!stream) {
@ -643,12 +649,7 @@ class Queue<T = unknown> {
} }
} else { } else {
const arbitraryStream = (hasCustomDownloader && (await this.onBeforeCreateStream(track, track.raw.source || track.raw.engine, this))) || null; const arbitraryStream = (hasCustomDownloader && (await this.onBeforeCreateStream(track, track.raw.source || track.raw.engine, this))) || null;
stream = stream = arbitraryStream ? await track.raw.engine.downloadProgressive() : typeof track.raw.engine === "function" ? await track.raw.engine() : track.raw.engine;
arbitraryStream
? await track.raw.engine.downloadProgressive()
: typeof track.raw.engine === "function"
? await track.raw.engine()
: track.raw.engine;
} }
const ffmpegStream = createFFmpegStream(stream, { const ffmpegStream = createFFmpegStream(stream, {

View file

@ -9,7 +9,8 @@ import {
StreamType, StreamType,
VoiceConnection, VoiceConnection,
VoiceConnectionStatus, VoiceConnectionStatus,
VoiceConnectionDisconnectReason VoiceConnectionDisconnectReason,
VoiceConnectionState
} from "@discordjs/voice"; } from "@discordjs/voice";
import { StageChannel, VoiceChannel } from "discord.js"; import { StageChannel, VoiceChannel } from "discord.js";
import { Duplex, Readable } from "stream"; import { Duplex, Readable } from "stream";
@ -68,7 +69,20 @@ class StreamDispatcher extends EventEmitter<VoiceEvents> {
*/ */
this.paused = false; 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.status === VoiceConnectionStatus.Disconnected) {
if (newState.reason === VoiceConnectionDisconnectReason.WebSocketClose && newState.closeCode === 4014) { if (newState.reason === VoiceConnectionDisconnectReason.WebSocketClose && newState.closeCode === 4014) {
try { try {

View file

@ -130,7 +130,7 @@ export interface PlayerProgressbarOptions {
* @property {boolean} [leaveOnStop=true] If it should leave on stop * @property {boolean} [leaveOnStop=true] If it should leave on stop
* @property {boolean} [leaveOnEmpty=true] If it should leave on empty * @property {boolean} [leaveOnEmpty=true] If it should leave on empty
* @property {number} [leaveOnEmptyCooldown=1000] The cooldown in ms * @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} [initialVolume=100] The initial player volume
* @property {number} [bufferingTimeout=3000] Buffering timeout for the stream * @property {number} [bufferingTimeout=3000] Buffering timeout for the stream
* @property {boolean} [disableVolume=false] If player should disable inline volume * @property {boolean} [disableVolume=false] If player should disable inline volume