fix discord links (#288)

This commit is contained in:
Snowflake 2021-02-20 19:57:43 +05:45 committed by GitHub
parent e603461e73
commit 0a2c2c2de8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -205,9 +205,10 @@ class Player extends EventEmitter {
* @param {Discord.Message} message * @param {Discord.Message} message
* @param {string} query * @param {string} query
* @param {boolean} firstResult * @param {boolean} firstResult
* @param {boolean} isAttachment
* @returns {Promise<Track>} * @returns {Promise<Track>}
*/ */
_searchTracks (message, query, firstResult) { _searchTracks (message, query, firstResult, isAttachment) {
return new Promise(async (resolve) => { return new Promise(async (resolve) => {
let tracks = [] let tracks = []
let updatedQuery = null let updatedQuery = null
@ -315,7 +316,7 @@ class Player extends EventEmitter {
}) })
tracks.push(track) tracks.push(track)
} else if (queryType === 'attachment') { } else if (!!isAttachment || queryType === 'attachment') {
const data = await DiscordExtractor.getInfo(query).catch(() => {}) const data = await DiscordExtractor.getInfo(query).catch(() => {})
if (!data || !(data.format.startsWith('audio/') || data.format.startsWith('video/'))) return this.emit('noResults', message, query) 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: '', description: '',
views: 0, views: 0,
author: { author: {
name: 'Media_Attachment' name: 'Media Attachment'
} }
}, message.author, this) }, message.author, this)
@ -679,7 +680,7 @@ class Player extends EventEmitter {
case 'soundcloud': case 'soundcloud':
return await Client.search(query, 'track').catch(() => {}) || [] return await Client.search(query, 'track').catch(() => {}) || []
default: 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 {Discord.Message} message Discord `message`
* @param {String|Track} query Search query or a valid `Track` object. * @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} 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<void>} * @returns {Promise<void>}
* *
* @example * @example
* client.player.play(message, "Despacito", true); * 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}`)) { if (this._cooldownsTimeout.has(`end_${message.guild.id}`)) {
clearTimeout(this._cooldownsTimeout.get(`end_${message.guild.id}`)) clearTimeout(this._cooldownsTimeout.get(`end_${message.guild.id}`))
this._cooldownsTimeout.delete(`end_${message.guild.id}`) this._cooldownsTimeout.delete(`end_${message.guild.id}`)
@ -704,7 +706,7 @@ class Player extends EventEmitter {
// clean query // clean query
query = query.replace(/<(.+)>/g, '$1') 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) return this._handlePlaylist(message, query)
} }
if (this.util.isSpotifyPLLink(query)) { if (this.util.isSpotifyPLLink(query)) {
@ -736,7 +738,7 @@ class Player extends EventEmitter {
} }
}, message.author, this) }, message.author, this)
} else { } else {
trackToPlay = await this._searchTracks(message, query, firstResult) trackToPlay = await this._searchTracks(message, query, firstResult, !!isAttachment || this.util.isDiscordAttachment(query))
} }
if (trackToPlay) { if (trackToPlay) {
if (this.isPlaying(message)) { if (this.isPlaying(message)) {