From c505b177adce3445da3cf68f905029bc19bb6089 Mon Sep 17 00:00:00 2001 From: Snowflake107 Date: Sat, 17 Apr 2021 19:56:18 +0545 Subject: [PATCH] move default player options to constants --- src/Player.ts | 21 +++++++++++++++------ src/utils/Constants.ts | 12 ++++++++++++ src/utils/Util.ts | 14 +------------- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/Player.ts b/src/Player.ts index baefe80..9bdd4e5 100644 --- a/src/Player.ts +++ b/src/Player.ts @@ -1,11 +1,17 @@ import { EventEmitter } from 'events'; import { Client, Collection, Snowflake, Collector, Message, VoiceChannel, VoiceState } from 'discord.js'; -import { LyricsData, PlayerOptions, PlayerProgressbarOptions, PlayerStats, QueueFilters } from './types/types'; +import { + LyricsData, + PlayerOptions as PlayerOptionsType, + PlayerProgressbarOptions, + PlayerStats, + QueueFilters +} from './types/types'; import Util from './utils/Util'; import AudioFilters from './utils/AudioFilters'; import { Queue } from './Structures/Queue'; import { Track } from './Structures/Track'; -import { PlayerErrorEventCodes, PlayerEvents } from './utils/Constants'; +import { PlayerErrorEventCodes, PlayerEvents, PlayerOptions } from './utils/Constants'; import PlayerError from './utils/PlayerError'; import ytdl from 'discord-ytdl-core'; import { ExtractorModel } from './Structures/ExtractorModel'; @@ -27,7 +33,7 @@ export class Player extends EventEmitter { * The discord client that instantiated this player */ public client!: Client; - public options: PlayerOptions; + public options: PlayerOptionsType; public filters: typeof AudioFilters; /** @@ -47,7 +53,7 @@ export class Player extends EventEmitter { * @param client The discord.js client * @param options Player options */ - constructor(client: Client, options?: PlayerOptions) { + constructor(client: Client, options?: PlayerOptionsType) { super(); Object.defineProperty(this, 'client', { @@ -58,7 +64,7 @@ export class Player extends EventEmitter { /** * The player options */ - this.options = Object.assign({}, Util.DefaultPlayerOptions, options ?? {}); + this.options = Object.assign({}, PlayerOptions, options ?? {}); // check FFmpeg void Util.alertFFmpeg(); @@ -895,7 +901,10 @@ export class Player extends EventEmitter { return { uptime: this.client.uptime, connections: this.client.voice.connections.size, - users: this.client.voice.connections.reduce((a, c) => a + c.channel.members.filter(a => a.user.id !== this.client.user.id).size, 0), + users: this.client.voice.connections.reduce( + (a, c) => a + c.channel.members.filter((a) => a.user.id !== this.client.user.id).size, + 0 + ), queues: this.queues.size, extractors: this.Extractors.size, versions: { diff --git a/src/utils/Constants.ts b/src/utils/Constants.ts index 7b075ed..ef5eb1b 100644 --- a/src/utils/Constants.ts +++ b/src/utils/Constants.ts @@ -1,3 +1,5 @@ +import { PlayerOptions as DP_OPTIONS } from '../types/types'; + export const PlayerEvents = { BOT_DISCONNECT: 'botDisconnect', CHANNEL_EMPTY: 'channelEmpty', @@ -26,3 +28,13 @@ export const PlayerErrorEventCodes = { VIDEO_UNAVAILABLE: 'VideoUnavailable', MUSIC_STARTING: 'MusicStarting' }; + +export const PlayerOptions: DP_OPTIONS = { + leaveOnEnd: true, + leaveOnStop: true, + leaveOnEmpty: true, + leaveOnEmptyCooldown: 0, + autoSelfDeaf: true, + enableLive: false, + ytdlDownloadOptions: {} +}; diff --git a/src/utils/Util.ts b/src/utils/Util.ts index abf5b08..9a6eb6e 100644 --- a/src/utils/Util.ts +++ b/src/utils/Util.ts @@ -1,4 +1,4 @@ -import { PlayerOptions, QueryType } from '../types/types'; +import { QueryType } from '../types/types'; import { FFmpeg } from 'prism-media'; import YouTube from 'youtube-sr'; import { Track } from '../Structures/Track'; @@ -19,18 +19,6 @@ export class Util { throw new Error(`The ${this.constructor.name} class is static and cannot be instantiated!`); } - static get DefaultPlayerOptions() { - return { - leaveOnEnd: true, - leaveOnStop: true, - leaveOnEmpty: true, - leaveOnEmptyCooldown: 0, - autoSelfDeaf: true, - enableLive: false, - ytdlDownloadOptions: {} - } as PlayerOptions; - } - static getFFmpegVersion(force?: boolean) { try { const info = FFmpeg.getInfo(Boolean(force));