remove comments and stuff

This commit is contained in:
Snowflake107 2021-05-01 13:50:12 +05:45
parent 12190c8fa3
commit 6bba82864c
7 changed files with 6 additions and 496 deletions

View file

@ -1,48 +1,13 @@
import { EventEmitter } from 'events';
import { Client, Collection, Snowflake, Collector, Message } from 'discord.js';
import {
PlayerOptions as PlayerOptionsType,
} from './types/types';
import { Client } from 'discord.js';
import Util from './utils/Util';
import AudioFilters from './utils/AudioFilters';
import { Queue } from './Structures/Queue';
import { ExtractorModel } from './Structures/ExtractorModel';
/**
* The Player class
* @extends {EventEmitter}
*/
export class Player extends EventEmitter {
public client: Client;
public options: PlayerOptionsType;
public filters: typeof AudioFilters;
/**
* The collection of queues in this player
* @type {DiscordCollection<Queue>}
*/
public queues = new Collection<Snowflake, Queue>();
/**
* The extractor model collection
* @type {DiscordCollection<ExtractorModel>}
*/
public Extractors = new Collection<string, ExtractorModel>();
/**
* Creates new Player instance
* @param {DiscordClient} client The discord.js client
* @param {PlayerOptions} options Player options
*/
constructor(client: Client, options?: PlayerOptionsType) {
constructor(client: Client) {
super();
/**
* The discord client that instantiated this player
* @name Player#client
* @type {DiscordClient}
* @readonly
*/
Object.defineProperty(this, 'client', {
value: client,
enumerable: false
@ -55,236 +20,4 @@ export class Player extends EventEmitter {
}
export default Player;
/**
* Emitted when a track starts
* @event Player#trackStart
* @param {DiscordMessage} message The message
* @param {Track} track The track
* @param {Queue} queue The queue
*/
/**
* Emitted when a playlist is started
* @event Player#queueCreate
* @param {DiscordMessage} message The message
* @param {Queue} queue The queue
*/
/**
* Emitted when the bot is awaiting search results
* @event Player#searchResults
* @param {DiscordMessage} message The message
* @param {String} query The query
* @param {Track[]} tracks The tracks
* @param {DiscordCollector} collector The collector
*/
/**
* Emitted when the user has sent an invalid response for search results
* @event Player#searchInvalidResponse
* @param {DiscordMessage} message The message
* @param {String} query The query
* @param {Track[]} tracks The tracks
* @param {String} invalidResponse The `invalidResponse` string
* @param {DiscordCollector} collector The collector
*/
/**
* Emitted when the bot has stopped awaiting search results (timeout)
* @event Player#searchCancel
* @param {DiscordMessage} message The message
* @param {String} query The query
* @param {Track[]} tracks The tracks
*/
/**
* Emitted when the bot can't find related results to the query
* @event Player#noResults
* @param {DiscordMessage} message The message
* @param {String} query The query
*/
/**
* Emitted when the bot is disconnected from the channel
* @event Player#botDisconnect
* @param {DiscordMessage} message The message
*/
/**
* Emitted when the channel of the bot is empty
* @event Player#channelEmpty
* @param {DiscordMessage} message The message
* @param {Queue} queue The queue
*/
/**
* Emitted when the queue of the server is ended
* @event Player#queueEnd
* @param {DiscordMessage} message The message
* @param {Queue} queue The queue
*/
/**
* Emitted when a track is added to the queue
* @event Player#trackAdd
* @param {DiscordMessage} message The message
* @param {Queue} queue The queue
* @param {Track} track The track
*/
/**
* Emitted when a playlist is added to the queue
* @event Player#playlistAdd
* @param {DiscordMessage} message The message
* @param {Queue} queue The queue
* @param {Object} playlist The playlist
*/
/**
* Emitted when an error is triggered
* @event Player#error
* @param {String} error It can be `NotConnected`, `UnableToJoin`, `NotPlaying`, `ParseError`, `LiveVideo` or `VideoUnavailable`.
* @param {DiscordMessage} message The message
*/
/**
* Emitted when discord-player attempts to parse playlist contents (mostly soundcloud playlists)
* @event Player#playlistParseStart
* @param {Object} playlist Raw playlist (unparsed)
* @param {DiscordMessage} message The message
*/
/**
* Emitted when discord-player finishes parsing playlist contents (mostly soundcloud playlists)
* @event Player#playlistParseEnd
* @param {Object} playlist The playlist data (parsed)
* @param {DiscordMessage} message The message
*/
/**
* @typedef {Object} PlayerOptions
* @property {Boolean} [leaveOnEnd=false] If it should leave on queue end
* @property {Number} [leaveOnEndCooldown=0] Time in ms to wait before executing `leaveOnEnd`
* @property {Boolean} [leaveOnStop=false] If it should leave on stop command
* @property {Boolean} [leaveOnEmpty=false] If it should leave on empty voice channel
* @property {Number} [leaveOnEmptyCooldown=0] Time in ms to wait before executing `leaveOnEmpty`
* @property {Boolean} [autoSelfDeaf=false] If it should set the client to `self deaf` mode on joining
* @property {Boolean} [enableLive=false] If it should enable live videos support
* @property {YTDLDownloadOptions} [ytdlDownloadOptions={}] The download options passed to `ytdl-core`
* @property {Boolean} [useSafeSearch=false] If it should use `safe search` method for youtube searches
* @property {Boolean} [disableAutoRegister=false] If it should disable auto-registeration of `@discord-player/extractor`
*/
/**
* The type of Track source, either:
* * `soundcloud` - a stream from SoundCloud
* * `youtube` - a stream from YouTube
* * `arbitrary` - arbitrary stream
* @typedef {String} TrackSource
*/
/**
* @typedef {Object} TrackData
* @property {String} title The title
* @property {String} description The description
* @property {String} author The author
* @property {String} url The url
* @property {String} duration The duration
* @property {Number} views The view count
* @property {DiscordUser} requestedBy The user who requested this track
* @property {Boolean} fromPlaylist If this track came from a playlist
* @property {TrackSource} [source] The track source
* @property {string|Readable} [engine] The stream engine
* @property {Boolean} [live=false] If this track is livestream instance
*/
/**
* @typedef {Object} QueueFilters
* The FFmpeg Filters
*/
/**
* The query type, either:
* * `soundcloud_track` - a SoundCloud Track
* * `soundcloud_playlist` - a SoundCloud Playlist
* * `spotify_song` - a Spotify Song
* * `spotify_album` - a Spotify album
* * `spotify_playlist` - a Spotify playlist
* * `youtube_video` - a YouTube video
* * `youtube_playlist` - a YouTube playlist
* * `vimeo` - a Vimeo link
* * `facebook` - a Facebook link
* * `reverbnation` - a Reverbnation link
* * `attachment` - an attachment link
* * `youtube_search` - a YouTube search keyword
* @typedef {String} QueryType The query type
*/
/**
* @typedef {Object} ExtractorModelData
* @property {String} title The title
* @property {Number} duration The duration in ms
* @property {String} thumbnail The thumbnail url
* @property {string|Readable} engine The audio engine
* @property {Number} views The views count of this stream
* @property {String} author The author
* @property {String} description The description
* @property {String} url The url
* @property {String} [version='0.0.0'] The extractor version
* @property {Boolean} [important=false] Mark as important
*/
/**
* @typedef {Object} PlayerProgressbarOptions
* @property {Boolean} [timecodes] If it should return progres bar with time codes
* @property {Boolean} [queue] if it should return the progress bar of the whole queue
* @property {Number} [length] The length of progress bar to build
*/
/**
* @typedef {Object} LyricsData
* @property {String} title The title of the lyrics
* @property {Number} id The song id
* @property {String} thumbnail The thumbnail
* @property {String} image The image
* @property {String} url The url
* @property {Object} artist The artust info
* @property {String} [artist.name] The name of the artist
* @property {Number} [artist.id] The ID of the artist
* @property {String} [artist.url] The profile link of the artist
* @property {String} [artist.image] The artist image url
* @property {String?} lyrics The lyrics
*/
/**
* @typedef {Object} PlayerStats
* @property {Number} uptime The uptime in ms
* @property {Number} connections The number of connections
* @property {Number} users The number of users
* @property {Number} queues The number of queues
* @property {Number} extractors The number of custom extractors registered
* @property {Object} versions The versions metadata
* @property {String} [versions.ffmpeg] The ffmpeg version
* @property {String} [versions.node] The node version
* @property {String} [versions.v8] The v8 JavaScript engine version
* @property {Object} system The system data
* @property {String} [system.arch] The system arch
* @property {String} [system.platform] The system platform
* @property {Number} [system.cpu] The cpu count
* @property {Object} [system.memory] The memory info
* @property {String} [system.memory.total] The total memory
* @property {String} [system.memory.usage] The memory usage
* @property {String} [system.memory.rss] The memory usage in RSS
* @property {String} [system.memory.arrayBuffers] The memory usage in ArrayBuffers
* @property {Number} [system.uptime] The system uptime
*/
/**
* @typedef {Object} TimeData
* @property {Number} days The time in days
* @property {Number} hours The time in hours
* @property {Number} minutes The time in minutes
* @property {Number} seconds The time in seconds
*/
export default Player;

View file

@ -24,104 +24,37 @@ export class Queue extends EventEmitter {
public additionalStreamTime: number;
public firstMessage: Message;
/**
* If autoplay is enabled in this queue
* @type {boolean}
*/
public autoPlay = false;
/**
* Queue constructor
* @param {Player} player The player that instantiated this Queue
* @param {DiscordMessage} message The message object
*/
constructor(player: Player, message: Message) {
super();
/**
* The player that instantiated this Queue
* @name Queue#player
* @type {Player}
* @readonly
*/
Object.defineProperty(this, 'player', { value: player, enumerable: false });
/**
* ID of the guild assigned to this queue
* @type {DiscordSnowflake}
*/
this.guildID = message.guild.id;
/**
* The voice connection of this queue
* @type {DiscordVoiceConnection}
*/
this.voiceConnection = null;
/**
* Tracks of this queue
* @type {Track[]}
*/
this.tracks = [];
/**
* Previous tracks of this queue
* @type {Track[]}
*/
this.previousTracks = [];
/**
* If the player of this queue is stopped
* @type {boolean}
*/
this.stopped = false;
/**
* If last track was skipped
* @type {boolean}
*/
this.lastSkipped = false;
/**
* Queue volume
* @type {Number}
*/
this.volume = 100;
/**
* If the player of this queue is paused
* @type {boolean}
*/
this.paused = Boolean(this.voiceConnection?.dispatcher?.paused);
/**
* If repeat mode is enabled in this queue
* @type {boolean}
*/
this.repeatMode = false;
/**
* If loop mode is enabled in this queue
* @type {boolean}
*/
this.loopMode = false;
/**
* The additional calculated stream time
* @type {Number}
*/
this.additionalStreamTime = 0;
/**
* The initial message object
* @type {DiscordMessage}
*/
this.firstMessage = message;
/**
* The audio filters in this queue
* @type {QueueFilters}
*/
this.filters = {};
Object.keys(AudioFilters).forEach((fn) => {
@ -129,52 +62,28 @@ export class Queue extends EventEmitter {
});
}
/**
* Currently playing track
* @type {Track}
* @readonly
*/
get playing(): Track {
return this.tracks[0];
}
/**
* Calculated volume of this queue
* @type {Number}
*/
get calculatedVolume(): number {
return this.filters.normalizer ? this.volume + 70 : this.volume;
}
/**
* Total duration
* @type {Number}
*/
get totalTime(): number {
return this.tracks.length > 0 ? this.tracks.map((t) => t.durationMS).reduce((p, c) => p + c) : 0;
}
/**
* Current stream time
* @type {Number}
*/
get currentStreamTime(): number {
return this.voiceConnection?.dispatcher?.streamTime + this.additionalStreamTime || 0;
}
/**
* Sets audio filters in this player
* @param {QueueFilters} filters Audio filters to set
* @type {Promise<void>}
*/
setFilters(filters: QueueFilters): Promise<void> {
return this.player.setFilters(this.firstMessage, filters);
}
/**
* Returns array of all enabled filters
* @type {String[]}
*/
getFiltersEnabled(): string[] {
const filters: string[] = [];
@ -185,20 +94,12 @@ export class Queue extends EventEmitter {
return filters;
}
/**
* Returns all disabled filters
* @type {String[]}
*/
getFiltersDisabled(): string[] {
const enabled = this.getFiltersEnabled();
return Object.keys(this.filters).filter((f) => !enabled.includes(f));
}
/**
* String representation of this Queue
* @returns {String}
*/
toString(): string {
return `<Queue ${this.guildID}>`;
}

View file

@ -18,80 +18,10 @@ export class Track {
public fromPlaylist!: boolean;
public raw!: TrackData;
/**
* Track constructor
* @param {Player} player The player that instantiated this Track
* @param {TrackData} data Track data
*/
constructor(player: Player, data: TrackData) {
/**
* The player that instantiated this Track
* @name Track#player
* @type {Player}
* @readonly
*/
Object.defineProperty(this, 'player', { value: player, enumerable: false });
/**
* Title of this track
* @name Track#title
* @type {String}
*/
/**
* Description of this track
* @name Track#description
* @type {String}
*/
/**
* Author of this track
* @name Track#author
* @type {String}
*/
/**
* URL of this track
* @name Track#url
* @type {String}
*/
/**
* Thumbnail of this track
* @name Track#thumbnail
* @type {String}
*/
/**
* Duration of this track
* @name Track#duration
* @type {String}
*/
/**
* Views count of this track
* @name Track#views
* @type {Number}
*/
/**
* Person who requested this track
* @name Track#requestedBy
* @type {DiscordUser}
*/
/**
* If this track belongs to playlist
* @name Track#fromPlaylist
* @type {Boolean}
*/
/**
* Raw track data
* @name Track#raw
* @type {TrackData}
*/
void this._patch(data);
}
@ -110,19 +40,10 @@ export class Track {
Object.defineProperty(this, 'raw', { get: () => data, enumerable: false });
}
/**
* The queue in which this track is located
* @type {Queue}
* @readonly
*/
get queue(): Queue {
return this.player.queues.find((q) => q.tracks.includes(this));
}
/**
* The track duration in millisecond
* @type {Number}
*/
get durationMS(): number {
const times = (n: number, t: number) => {
let tn = 1;
@ -137,10 +58,6 @@ export class Track {
.reduce((a, c) => a + c, 0);
}
/**
* String representation of this track
* @returns {String}
*/
toString(): string {
return `${this.title} by ${this.author}`;
}

View file

@ -1,40 +1,5 @@
// @ts-nocheck
import { FiltersName } from '../types/types';
/**
* The available audio filters
* @typedef {Object} AudioFilters
* @property {String} bassboost The bassboost filter
* @property {String} 8D The 8D filter
* @property {String} vaporwave The vaporwave filter
* @property {String} nightcore The nightcore filter
* @property {String} phaser The phaser filter
* @property {String} tremolo The tremolo filter
* @property {String} vibrato The vibrato filter
* @property {String} reverse The reverse filter
* @property {String} treble The treble filter
* @property {String} normalizer The normalizer filter
* @property {String} surrounding The surrounding filter
* @property {String} pulsator The pulsator filter
* @property {String} subboost The subboost filter
* @property {String} kakaoke The kakaoke filter
* @property {String} flanger The flanger filter
* @property {String} gate The gate filter
* @property {String} haas The haas filter
* @property {String} mcompand The mcompand filter
* @property {String} mono The mono filter
* @property {String} mstlr The mstlr filter
* @property {String} mstrr The mstrr filter
* @property {String} compressor The compressor filter
* @property {String} expander The expander filter
* @property {String} softlimiter The softlimiter filter
* @property {String} chorus The chorus filter
* @property {String} chorus2d The chorus2d filter
* @property {String} chorus3d The chorus3d filter
* @property {String} fadein The fadein filter
*/
const FilterList = {
bassboost: 'bass=g=20',
'8D': 'apulsator=hz=0.09',

View file

@ -1,5 +1,3 @@
// @ts-nocheck
import { PlayerOptions as DP_OPTIONS } from '../types/types';
export const PlayerEvents = {

View file

@ -1,5 +1,3 @@
// @ts-nocheck
export default class PlayerError extends Error {
constructor(msg: string, name?: string) {
super();

View file

@ -1,5 +1,3 @@
// @ts-nocheck
import { QueryType, TimeData } from '../types/types';
import { FFmpeg } from 'prism-media';
import YouTube from 'youtube-sr';