From 0a2c2c2de88327cb18eb547cc23de3bdd4f81141 Mon Sep 17 00:00:00 2001 From: Snowflake Date: Sat, 20 Feb 2021 19:57:43 +0545 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20fix=20discord=20links=20(#288)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Player.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Player.js b/src/Player.js index 4391bab..87530b6 100644 --- a/src/Player.js +++ b/src/Player.js @@ -205,9 +205,10 @@ class Player extends EventEmitter { * @param {Discord.Message} message * @param {string} query * @param {boolean} firstResult + * @param {boolean} isAttachment * @returns {Promise} */ - _searchTracks (message, query, firstResult) { + _searchTracks (message, query, firstResult, isAttachment) { return new Promise(async (resolve) => { let tracks = [] let updatedQuery = null @@ -315,7 +316,7 @@ class Player extends EventEmitter { }) tracks.push(track) - } else if (queryType === 'attachment') { + } else if (!!isAttachment || queryType === 'attachment') { const data = await DiscordExtractor.getInfo(query).catch(() => {}) if (!data || !(data.format.startsWith('audio/') || data.format.startsWith('video/'))) return this.emit('noResults', message, query) @@ -327,7 +328,7 @@ class Player extends EventEmitter { description: '', views: 0, author: { - name: 'Media_Attachment' + name: 'Media Attachment' } }, message.author, this) @@ -679,7 +680,7 @@ class Player extends EventEmitter { case 'soundcloud': return await Client.search(query, 'track').catch(() => {}) || [] default: - return ytsr.search(query, { type: 'video' }).catch(() => {}) || [] + return await ytsr.search(query, { type: 'video' }).catch(() => {}) || [] } } @@ -688,12 +689,13 @@ class Player extends EventEmitter { * @param {Discord.Message} message Discord `message` * @param {String|Track} query Search query or a valid `Track` object. * @param {boolean} firstResult Whether the bot should play the first song found on youtube with the given query + * @param {boolean} [isAttachment=false] If it should play it as attachment * @returns {Promise} * * @example * client.player.play(message, "Despacito", true); */ - async play (message, query, firstResult = false) { + async play (message, query, firstResult = false, isAttachment = false) { if (this._cooldownsTimeout.has(`end_${message.guild.id}`)) { clearTimeout(this._cooldownsTimeout.get(`end_${message.guild.id}`)) this._cooldownsTimeout.delete(`end_${message.guild.id}`) @@ -704,7 +706,7 @@ class Player extends EventEmitter { // clean query query = query.replace(/<(.+)>/g, '$1') - if (this.util.isYTPlaylistLink(query)) { + if (!this.util.isDiscordAttachment(query) && !isAttachment && this.util.isYTPlaylistLink(query)) { return this._handlePlaylist(message, query) } if (this.util.isSpotifyPLLink(query)) { @@ -736,7 +738,7 @@ class Player extends EventEmitter { } }, message.author, this) } else { - trackToPlay = await this._searchTracks(message, query, firstResult) + trackToPlay = await this._searchTracks(message, query, firstResult, !!isAttachment || this.util.isDiscordAttachment(query)) } if (trackToPlay) { if (this.isPlaying(message)) {