track data

This commit is contained in:
Snowflake107 2021-04-05 12:30:55 +05:45
parent b52e86f160
commit 1be07e4703
2 changed files with 21 additions and 3 deletions

View file

@ -1,5 +1,6 @@
import Player from '../Player'; import Player from '../Player';
import { User } from 'discord.js'; import { User } from 'discord.js';
import { TrackData } from "../types/Track";
export default class Track { export default class Track {
public player!: Player; public player!: Player;
@ -12,8 +13,9 @@ export default class Track {
public views!: number; public views!: number;
public requestedBy!: User; public requestedBy!: User;
public fromPlaylist!: boolean; public fromPlaylist!: boolean;
public raw!: TrackData;
constructor(player: Player, data: any) { constructor(player: Player, data: TrackData) {
/** /**
* The player that instantiated this Track * The player that instantiated this Track
*/ */
@ -22,15 +24,18 @@ export default class Track {
void this._patch(data); void this._patch(data);
} }
private _patch(data: any) { private _patch(data: TrackData) {
this.title = data.title ?? ''; this.title = data.title ?? '';
this.description = data.description ?? ''; this.description = data.description ?? '';
this.author = data.author ?? ''; this.author = data.author ?? '';
this.url = data.url ?? ''; this.url = data.url ?? '';
this.thumbnail = typeof data.thumbnail === 'object' ? data.thumbnail.url : data.thumbnail; this.thumbnail = data.thumbnail ?? '';
this.duration = data.duration ?? ''; this.duration = data.duration ?? '';
this.views = data.views ?? 0; this.views = data.views ?? 0;
this.requestedBy = data.requestedBy; this.requestedBy = data.requestedBy;
this.fromPlaylist = Boolean(data.fromPlaylist); this.fromPlaylist = Boolean(data.fromPlaylist);
// raw
Object.defineProperty(this, "raw", { get: () => data, enumerable: false });
} }
} }

13
src/types/Track.ts Normal file
View file

@ -0,0 +1,13 @@
import { User } from "discord.js";
export interface TrackData {
title: string;
description: string;
author: string;
url: string;
thumbnail: string;
duration: string;
views: number;
requestedBy: User;
fromPlaylist: boolean;
}