fix: autoplay
This commit is contained in:
parent
ed92e332ab
commit
a0b04d7a62
3 changed files with 21 additions and 17 deletions
|
@ -15,6 +15,7 @@
|
||||||
"@typescript-eslint/explicit-module-boundary-types": "off",
|
"@typescript-eslint/explicit-module-boundary-types": "off",
|
||||||
"@typescript-eslint/no-unused-vars": "error",
|
"@typescript-eslint/no-unused-vars": "error",
|
||||||
"@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"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -196,7 +196,7 @@ class Player extends EventEmitter<PlayerEvents> {
|
||||||
case QueryType.YOUTUBE_SEARCH: {
|
case QueryType.YOUTUBE_SEARCH: {
|
||||||
const videos = await YouTube.search(query, {
|
const videos = await YouTube.search(query, {
|
||||||
type: "video"
|
type: "video"
|
||||||
}).catch(Util.noop); // eslint-disable-line @typescript-eslint/no-empty-function
|
}).catch(Util.noop);
|
||||||
if (!videos) return { playlist: null, tracks: [] };
|
if (!videos) return { playlist: null, tracks: [] };
|
||||||
|
|
||||||
const tracks = videos.map((m) => {
|
const tracks = videos.map((m) => {
|
||||||
|
@ -224,7 +224,7 @@ class Player extends EventEmitter<PlayerEvents> {
|
||||||
const res: Track[] = [];
|
const res: Track[] = [];
|
||||||
|
|
||||||
for (const r of result) {
|
for (const r of result) {
|
||||||
const trackInfo = await soundcloud.getSongInfo(r.url).catch(Util.noop); // eslint-disable-line @typescript-eslint/no-empty-function
|
const trackInfo = await soundcloud.getSongInfo(r.url).catch(Util.noop);
|
||||||
if (!trackInfo) continue;
|
if (!trackInfo) continue;
|
||||||
|
|
||||||
const track = new Track(this, {
|
const track = new Track(this, {
|
||||||
|
@ -246,7 +246,7 @@ class Player extends EventEmitter<PlayerEvents> {
|
||||||
return { playlist: null, tracks: res };
|
return { playlist: null, tracks: res };
|
||||||
}
|
}
|
||||||
case QueryType.SPOTIFY_SONG: {
|
case QueryType.SPOTIFY_SONG: {
|
||||||
const spotifyData = await Spotify.getData(query).catch(Util.noop); // eslint-disable-line @typescript-eslint/no-empty-function
|
const spotifyData = await Spotify.getData(query).catch(Util.noop);
|
||||||
if (!spotifyData) return { playlist: null, tracks: [] };
|
if (!spotifyData) return { playlist: null, tracks: [] };
|
||||||
const spotifyTrack = new Track(this, {
|
const spotifyTrack = new Track(this, {
|
||||||
title: spotifyData.name,
|
title: spotifyData.name,
|
||||||
|
@ -267,7 +267,7 @@ class Player extends EventEmitter<PlayerEvents> {
|
||||||
}
|
}
|
||||||
case QueryType.SPOTIFY_PLAYLIST:
|
case QueryType.SPOTIFY_PLAYLIST:
|
||||||
case QueryType.SPOTIFY_ALBUM: {
|
case QueryType.SPOTIFY_ALBUM: {
|
||||||
const spotifyPlaylist = await Spotify.getData(query).catch(Util.noop); // eslint-disable-line @typescript-eslint/no-empty-function
|
const spotifyPlaylist = await Spotify.getData(query).catch(Util.noop);
|
||||||
if (!spotifyPlaylist) return { playlist: null, tracks: [] };
|
if (!spotifyPlaylist) return { playlist: null, tracks: [] };
|
||||||
|
|
||||||
const playlist = new Playlist(this, {
|
const playlist = new Playlist(this, {
|
||||||
|
@ -333,7 +333,7 @@ class Player extends EventEmitter<PlayerEvents> {
|
||||||
return { playlist: playlist, tracks: playlist.tracks };
|
return { playlist: playlist, tracks: playlist.tracks };
|
||||||
}
|
}
|
||||||
case QueryType.SOUNDCLOUD_PLAYLIST: {
|
case QueryType.SOUNDCLOUD_PLAYLIST: {
|
||||||
const data = await SoundCloud.getPlaylist(query).catch(Util.noop); // eslint-disable-line @typescript-eslint/no-empty-function
|
const data = await SoundCloud.getPlaylist(query).catch(Util.noop);
|
||||||
if (!data) return { playlist: null, tracks: [] };
|
if (!data) return { playlist: null, tracks: [] };
|
||||||
|
|
||||||
const res = new Playlist(this, {
|
const res = new Playlist(this, {
|
||||||
|
@ -372,11 +372,11 @@ class Player extends EventEmitter<PlayerEvents> {
|
||||||
return { playlist: res, tracks: res.tracks };
|
return { playlist: res, tracks: res.tracks };
|
||||||
}
|
}
|
||||||
case QueryType.YOUTUBE_PLAYLIST: {
|
case QueryType.YOUTUBE_PLAYLIST: {
|
||||||
const ytpl = await YouTube.getPlaylist(query).catch(Util.noop); // eslint-disable-line @typescript-eslint/no-empty-function
|
const ytpl = await YouTube.getPlaylist(query).catch(Util.noop);
|
||||||
if (!ytpl) return { playlist: null, tracks: [] };
|
if (!ytpl) return { playlist: null, tracks: [] };
|
||||||
|
|
||||||
// @todo: better way of handling large playlists
|
// @todo: better way of handling large playlists
|
||||||
await ytpl.fetch().catch(Util.noop); // eslint-disable-line @typescript-eslint/no-empty-function
|
await ytpl.fetch().catch(Util.noop);
|
||||||
|
|
||||||
const playlist: Playlist = new Playlist(this, {
|
const playlist: Playlist = new Playlist(this, {
|
||||||
title: ytpl.title,
|
title: ytpl.title,
|
||||||
|
|
|
@ -134,7 +134,10 @@ class Queue<T = unknown> {
|
||||||
});
|
});
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
|
|
||||||
if (channel.type === "stage") await channel.guild.me.voice.setRequestToSpeak(true).catch(Util.noop); // eslint-disable-line @typescript-eslint/no-empty-function
|
if (channel.type === "stage") {
|
||||||
|
await channel.guild.me.voice.setRequestToSpeak(true).catch(Util.noop);
|
||||||
|
await channel.guild.me.voice.setSuppressed(false).catch(Util.noop);
|
||||||
|
}
|
||||||
|
|
||||||
this.connection.on("error", (err) => this.player.emit("connectionError", this, err));
|
this.connection.on("error", (err) => this.player.emit("connectionError", this, err));
|
||||||
this.connection.on("debug", (msg) => this.player.emit("debug", this, msg));
|
this.connection.on("debug", (msg) => this.player.emit("debug", this, msg));
|
||||||
|
@ -409,6 +412,7 @@ class Queue<T = unknown> {
|
||||||
|
|
||||||
if (!options.filtersUpdate) {
|
if (!options.filtersUpdate) {
|
||||||
this.previousTracks = this.previousTracks.filter((x) => x._trackID !== track._trackID);
|
this.previousTracks = this.previousTracks.filter((x) => x._trackID !== track._trackID);
|
||||||
|
this.previousTracks.push(track);
|
||||||
}
|
}
|
||||||
|
|
||||||
let stream;
|
let stream;
|
||||||
|
@ -471,10 +475,9 @@ class Queue<T = unknown> {
|
||||||
if (this.options.leaveOnEnd) this.destroy();
|
if (this.options.leaveOnEnd) this.destroy();
|
||||||
return void this.player.emit("queueEnd", this);
|
return void this.player.emit("queueEnd", this);
|
||||||
}
|
}
|
||||||
const info = await ytdl
|
const info = await YouTube.getVideo(track.url)
|
||||||
.getInfo(track.url)
|
.then((x) => x.videos[0])
|
||||||
.then((x) => x.related_videos[0])
|
.catch(Util.noop);
|
||||||
.catch(Util.noop); // eslint-disable-line @typescript-eslint/no-empty-function
|
|
||||||
if (!info) {
|
if (!info) {
|
||||||
if (this.options.leaveOnEnd) this.destroy();
|
if (this.options.leaveOnEnd) this.destroy();
|
||||||
return void this.player.emit("queueEnd", this);
|
return void this.player.emit("queueEnd", this);
|
||||||
|
@ -483,11 +486,11 @@ class Queue<T = unknown> {
|
||||||
const nextTrack = new Track(this.player, {
|
const nextTrack = new Track(this.player, {
|
||||||
title: info.title,
|
title: info.title,
|
||||||
url: `https://www.youtube.com/watch?v=${info.id}`,
|
url: `https://www.youtube.com/watch?v=${info.id}`,
|
||||||
duration: info.length_seconds ? Util.buildTimeCode(Util.parseMS(info.length_seconds * 1000)) : "0:00",
|
duration: info.durationFormatted ? Util.buildTimeCode(Util.parseMS(info.duration * 1000)) : "0:00",
|
||||||
description: "",
|
description: "",
|
||||||
thumbnail: Util.last(info.thumbnails).url,
|
thumbnail: typeof info.thumbnail === "string" ? info.thumbnail : info.thumbnail.url,
|
||||||
views: parseInt(info.view_count.replace(/[^0-9]/g, "")),
|
views: info.views,
|
||||||
author: typeof info.author === "string" ? info.author : info.author.name,
|
author: info.channel.name,
|
||||||
requestedBy: track.requestedBy,
|
requestedBy: track.requestedBy,
|
||||||
source: "youtube"
|
source: "youtube"
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue