🐛 Fixed author and duration undefined errors (#141)

This commit is contained in:
Paweł Lidwin 2020-11-08 14:17:14 +01:00 committed by GitHub
parent a6adc0e41f
commit 7657ffedef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,7 +11,7 @@ class Track {
* @param {Discord.User | null} user The user who requested the track
* @param {Player} player
*/
constructor (videoData, user, player) {
constructor(videoData, user, player) {
/**
* The player instantiating the track
* @type {Player}
@ -31,17 +31,24 @@ class Track {
* The video duration (formatted).
* @type {string}
*/
this.duration = videoData.durationFormatted
this.duration =
videoData.durationFormatted ||
`${Math.floor(parseInt(videoData.videoDetails.lengthSeconds) / 60)}:${
parseInt(videoData.videoDetails.lengthSeconds) % 60
}`
/**
* The video description
* @type {string}
*/
this.description = videoData.description
this.description = videoData.description;
/**
* The video thumbnail
* @type {string}
*/
this.thumbnail = typeof videoData.thumbnail === 'object' ? videoData.thumbnail.url : videoData.thumbnail
this.thumbnail =
typeof videoData.thumbnail === "object"
? videoData.thumbnail.url
: videoData.thumbnail
/**
* The video views
* @type {?number}
@ -51,7 +58,9 @@ class Track {
* The video channel
* @type {string}
*/
this.author = videoData.channel.name
this.author = videoData.channel
? videoData.channel.name
: videoData.author.name
/**
* The user who requested the track
* @type {Discord.User?}
@ -68,7 +77,7 @@ class Track {
* The queue in which the track is
* @type {Queue}
*/
get queue () {
get queue() {
return this.player.queues.find((queue) => queue.tracks.includes(this))
}
@ -76,15 +85,16 @@ class Track {
* The track duration
* @type {number}
*/
get durationMS () {
const args = this.duration.split(':')
get durationMS() {
const args = this.duration.split(":")
if (args.length === 3) {
return parseInt(args[0]) * 60 * 60 * 1000 +
return (
parseInt(args[0]) * 60 * 60 * 1000 +
parseInt(args[1]) * 60 * 1000 +
parseInt(args[2]) * 1000
);
} else if (args.length === 2) {
return parseInt(args[0]) * 60 * 1000 +
parseInt(args[1]) * 1000
return parseInt(args[0]) * 60 * 1000 + parseInt(args[1]) * 1000
} else {
return parseInt(args[0]) * 1000
}