refactor(Queue): Remove queue from createProgressBar
This commit is contained in:
parent
a9cbc9df01
commit
6e6bd432c0
3 changed files with 13 additions and 22 deletions
|
@ -2,7 +2,7 @@ import { Client, Collection, GuildResolvable, Snowflake, User, VoiceState } from
|
|||
import { TypedEmitter as EventEmitter } from "tiny-typed-emitter";
|
||||
import { Queue } from "./Structures/Queue";
|
||||
import { VoiceUtils } from "./VoiceInterface/VoiceUtils";
|
||||
import { PlayerEvents, PlayerOptions, QueryType, SearchOptions, DiscordPlayerInitOptions } from "./types/types";
|
||||
import { PlayerEvents, PlayerOptions, QueryType, SearchOptions, PlayerInitOptions } from "./types/types";
|
||||
import Track from "./Structures/Track";
|
||||
import { QueryResolver } from "./utils/QueryResolver";
|
||||
import YouTube from "youtube-sr";
|
||||
|
@ -19,7 +19,7 @@ const soundcloud = new SoundCloud();
|
|||
|
||||
class Player extends EventEmitter<PlayerEvents> {
|
||||
public readonly client: Client;
|
||||
public readonly options: DiscordPlayerInitOptions = {
|
||||
public readonly options: PlayerInitOptions = {
|
||||
autoRegisterExtractor: true,
|
||||
ytdlOptions: {}
|
||||
};
|
||||
|
@ -30,9 +30,9 @@ class Player extends EventEmitter<PlayerEvents> {
|
|||
/**
|
||||
* Creates new Discord Player
|
||||
* @param {Client} client The Discord Client
|
||||
* @param {DiscordPlayerInitOptions} [options={}] The player init options
|
||||
* @param {PlayerInitOptions} [options={}] The player init options
|
||||
*/
|
||||
constructor(client: Client, options: DiscordPlayerInitOptions = {}) {
|
||||
constructor(client: Client, options: PlayerInitOptions = {}) {
|
||||
super();
|
||||
|
||||
/**
|
||||
|
|
|
@ -522,20 +522,16 @@ class Queue<T = unknown> {
|
|||
|
||||
/**
|
||||
* Returns player stream timestamp
|
||||
* @param {boolean} [queue=false] If it should generate timestamp for the queue
|
||||
* @returns {PlayerTimestamp}
|
||||
*/
|
||||
getPlayerTimestamp(queue = false) {
|
||||
getPlayerTimestamp() {
|
||||
this.#watchDestroyed();
|
||||
const previousTracksTime = this.previousTracks.length > 0 ? this.previousTracks.reduce((p, c) => p + c.durationMS, 0) : 0;
|
||||
const currentStreamTime = queue ? previousTracksTime + this.streamTime : this.streamTime;
|
||||
const totalTracksTime = this.totalTime;
|
||||
const totalTime = queue ? previousTracksTime + totalTracksTime : this.current.durationMS;
|
||||
const currentStreamTime = this.streamTime;
|
||||
const totalTime = this.current.durationMS;
|
||||
|
||||
const currentTimecode = Util.buildTimeCode(Util.parseMS(currentStreamTime));
|
||||
const endTimecode = Util.buildTimeCode(Util.parseMS(totalTime));
|
||||
|
||||
// why
|
||||
return {
|
||||
current: currentTimecode,
|
||||
end: endTimecode,
|
||||
|
@ -548,15 +544,11 @@ class Queue<T = unknown> {
|
|||
* @param {PlayerProgressbarOptions} options The progress bar options
|
||||
* @returns {string}
|
||||
*/
|
||||
createProgressBar(options: PlayerProgressbarOptions = { timecodes: true, queue: false }) {
|
||||
createProgressBar(options: PlayerProgressbarOptions = { timecodes: true }) {
|
||||
this.#watchDestroyed();
|
||||
const previousTracksTime = this.previousTracks.length > 0 ? this.previousTracks.reduce((p, c) => p + c.durationMS, 0) : 0;
|
||||
const currentStreamTime = options.queue ? previousTracksTime + this.streamTime : this.streamTime;
|
||||
const totalTracksTime = this.totalTime;
|
||||
const totalTime = options.queue ? previousTracksTime + totalTracksTime : this.current.durationMS;
|
||||
const length = typeof options.length === "number" ? (options.length <= 0 || options.length === Infinity ? 15 : options.length) : 15;
|
||||
|
||||
const index = Math.round((currentStreamTime / totalTime) * length);
|
||||
const index = Math.round((this.streamTime / this.current.durationMS) * length);
|
||||
const indicator = typeof options.indicator === "string" && options.indicator.length > 0 ? options.indicator : "🔘";
|
||||
const line = typeof options.line === "string" && options.line.length > 0 ? options.line : "▬";
|
||||
|
||||
|
@ -564,14 +556,14 @@ class Queue<T = unknown> {
|
|||
const bar = line.repeat(length - 1).split("");
|
||||
bar.splice(index, 0, indicator);
|
||||
if (options.timecodes) {
|
||||
const timestamp = this.getPlayerTimestamp(options.queue);
|
||||
const timestamp = this.getPlayerTimestamp();
|
||||
return `${timestamp.current} ┃ ${bar.join("")} ┃ ${timestamp.end}`;
|
||||
} else {
|
||||
return `${bar.join("")}`;
|
||||
}
|
||||
} else {
|
||||
if (options.timecodes) {
|
||||
const timestamp = this.getPlayerTimestamp(options.queue);
|
||||
const timestamp = this.getPlayerTimestamp();
|
||||
return `${timestamp.current} ┃ ${indicator}${line.repeat(length - 1)} ┃ ${timestamp.end}`;
|
||||
} else {
|
||||
return `${indicator}${line.repeat(length - 1)}`;
|
||||
|
|
|
@ -113,7 +113,6 @@ export interface TimeData {
|
|||
*/
|
||||
export interface PlayerProgressbarOptions {
|
||||
timecodes?: boolean;
|
||||
queue?: boolean;
|
||||
length?: number;
|
||||
line?: string;
|
||||
indicator?: string;
|
||||
|
@ -449,11 +448,11 @@ export interface PlaylistJSON {
|
|||
}
|
||||
|
||||
/**
|
||||
* @typedef {object} DiscordPlayerInitOptions
|
||||
* @typedef {object} PlayerInitOptions
|
||||
* @property {boolean} [autoRegisterExtractor=true] If it should automatically register `@discord-player/extractor`
|
||||
* @property {YTDLDownloadOptions} [ytdlOptions={}] The options passed to `ytdl-core`
|
||||
*/
|
||||
export interface DiscordPlayerInitOptions {
|
||||
export interface PlayerInitOptions {
|
||||
autoRegisterExtractor?: boolean;
|
||||
ytdlOptions?: downloadOptions;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue