From 0c49e33712a7e85faa5b1961abd7e37717c5681e Mon Sep 17 00:00:00 2001 From: SXM_ABEL <90580222+SxMAbel@users.noreply.github.com> Date: Thu, 13 Jul 2023 15:35:17 -0400 Subject: [PATCH] BETA Ended v2.0.2-beta -> v2.0.3 --- package-lock.json | 4 +-- package.json | 2 +- src/structures/Filters.ts | 32 ++++++++--------- src/structures/Manager.ts | 76 ++++++--------------------------------- src/structures/Node.ts | 59 ++++-------------------------- src/structures/Player.ts | 45 ++--------------------- src/utils/managerCheck.ts | 64 +++++++++++++++++++++++++++++++++ src/utils/nodeCheck.ts | 72 +++++++++++++++++++++++++++++++++++++ src/utils/playerCheck.ts | 49 +++++++++++++++++++++++++ 9 files changed, 223 insertions(+), 180 deletions(-) create mode 100644 src/utils/managerCheck.ts create mode 100644 src/utils/nodeCheck.ts create mode 100644 src/utils/playerCheck.ts diff --git a/package-lock.json b/package-lock.json index e8efdf5e..017d9ee2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "magmastream", - "version": "2.0.2-beta", + "version": "2.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "magmastream", - "version": "2.0.2-beta", + "version": "2.0.2", "license": "Apache-2.0", "dependencies": { "@discordjs/collection": "^1.5.1", diff --git a/package.json b/package.json index 7392f173..7d1a300f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "magmastream", - "version": "2.0.2-beta", + "version": "2.0.3", "description": "A user-friendly Lavalink client designed for NodeJS.", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/structures/Filters.ts b/src/structures/Filters.ts index cb4bc05c..5ca2f7c9 100644 --- a/src/structures/Filters.ts +++ b/src/structures/Filters.ts @@ -1,50 +1,50 @@ import { Player } from "./Player"; export class Filters { - public player: Player; - public volume: number; + public distortion: distortionOptions; public equalizer: Band[]; - public vibrato: vibratoOptions; + public karaoke: karaokeOptions; + public player: Player; public rotation: rotationOptions; public timescale: timescaleOptions; - public karaoke: karaokeOptions; - public distortion: distortionOptions; + public vibrato: vibratoOptions; + public volume: number; constructor(player: Player) { - this.player = player; - this.volume = 1.0; + this.distortion = null; this.equalizer = []; - this.vibrato = null; + this.karaoke = null; + this.player = player; this.rotation = null; this.timescale = null; - this.karaoke = null; - this.distortion = null; + this.vibrato = null; + this.volume = 1.0; } private updateFilters(): this { const { + distortion, equalizer, karaoke, + rotation, timescale, vibrato, - rotation, volume, - distortion, } = this; this.player.node.rest.updatePlayer({ - guildId: this.player.guild, data: { filters: { - volume, + distortion, equalizer, karaoke, + rotation, timescale, vibrato, - rotation, - distortion, + volume, }, }, + guildId: this.player.guild, }); return this; diff --git a/src/structures/Manager.ts b/src/structures/Manager.ts index ba317368..15d2d7f0 100644 --- a/src/structures/Manager.ts +++ b/src/structures/Manager.ts @@ -1,9 +1,4 @@ /* eslint-disable no-async-promise-executor */ -import { Collection } from "@discordjs/collection"; -import { EventEmitter } from "events"; -import { VoiceState } from ".."; -import { Node, NodeOptions } from "./Node"; -import { Player, PlayerOptions, Track, UnresolvedTrack } from "./Player"; import { LoadType, Plugin, @@ -18,66 +13,15 @@ import { VoiceServer, WebSocketClosedEvent, } from "./Utils"; +import { Collection } from "@discordjs/collection"; +import { EventEmitter } from "events"; +import { Node, NodeOptions } from "./Node"; +import { Player, PlayerOptions, Track, UnresolvedTrack } from "./Player"; +import { VoiceState } from ".."; +import managerCheck from "../utils/managerCheck"; const REQUIRED_KEYS = ["event", "guild_id", "op", "sessionId"]; -function check(options: ManagerOptions) { - if (!options) throw new TypeError("ManagerOptions must not be empty."); - - if (typeof options.send !== "function") - throw new TypeError( - 'Manager option "send" must be present and a function.' - ); - - if ( - typeof options.clientId !== "undefined" && - !/^\d+$/.test(options.clientId) - ) - throw new TypeError( - 'Manager option "clientId" must be a non-empty string.' - ); - - if (typeof options.nodes !== "undefined" && !Array.isArray(options.nodes)) - throw new TypeError('Manager option "nodes" must be a array.'); - - if ( - typeof options.shards !== "undefined" && - typeof options.shards !== "number" - ) - throw new TypeError('Manager option "shards" must be a number.'); - - if (typeof options.plugins !== "undefined" && !Array.isArray(options.plugins)) - throw new TypeError('Manager option "plugins" must be a Plugin array.'); - - if ( - typeof options.autoPlay !== "undefined" && - typeof options.autoPlay !== "boolean" - ) - throw new TypeError('Manager option "autoPlay" must be a boolean.'); - - if ( - typeof options.trackPartial !== "undefined" && - !Array.isArray(options.trackPartial) - ) - throw new TypeError( - 'Manager option "trackPartial" must be a string array.' - ); - - if ( - typeof options.clientName !== "undefined" && - typeof options.clientName !== "string" - ) - throw new TypeError('Manager option "clientName" must be a string.'); - - if ( - typeof options.defaultSearchPlatform !== "undefined" && - typeof options.defaultSearchPlatform !== "string" - ) - throw new TypeError( - 'Manager option "defaultSearchPlatform" must be a string.' - ); -} - export interface Manager { /** * Emitted when a Node is created. @@ -265,7 +209,7 @@ export class Manager extends EventEmitter { constructor(options: ManagerOptions) { super(); - check(options); + managerCheck(options); Structure.get("Player").init(this); Structure.get("Node").init(this); @@ -588,10 +532,10 @@ export interface ManagerOptions { } export type SearchPlatform = - | "youtube" - | "youtube music" + | "deezer" | "soundcloud" - | "deezer"; + | "youtube music" + | "youtube"; export interface SearchQuery { /** The source to search from. */ diff --git a/src/structures/Node.ts b/src/structures/Node.ts index 37bafe68..72080fbb 100644 --- a/src/structures/Node.ts +++ b/src/structures/Node.ts @@ -1,8 +1,4 @@ /* eslint-disable no-case-declarations */ -import WebSocket from "ws"; -import { Dispatcher, Pool } from "undici"; -import { Manager } from "./Manager"; -import { Player, Track, UnresolvedTrack } from "./Player"; import { PlayerEvent, PlayerEvents, @@ -13,55 +9,12 @@ import { TrackStuckEvent, WebSocketClosedEvent, } from "./Utils"; +import { Manager } from "./Manager"; +import { Player, Track, UnresolvedTrack } from "./Player"; +import { Pool } from "undici"; import { Rest } from "./Rest"; - -function check(options: NodeOptions) { - if (!options) throw new TypeError("NodeOptions must not be empty."); - - if (typeof options.host !== "string" || !/.+/.test(options.host)) - throw new TypeError( - 'Node option "host" must be present and be a non-empty string.' - ); - - if (typeof options.port !== "undefined" && typeof options.port !== "number") - throw new TypeError('Node option "port" must be a number.'); - - if ( - typeof options.password !== "undefined" && - (typeof options.password !== "string" || !/.+/.test(options.password)) - ) - throw new TypeError('Node option "password" must be a non-empty string.'); - - if ( - typeof options.secure !== "undefined" && - typeof options.secure !== "boolean" - ) - throw new TypeError('Node option "secure" must be a boolean.'); - - if ( - typeof options.identifier !== "undefined" && - typeof options.identifier !== "string" - ) - throw new TypeError('Node option "identifier" must be a non-empty string.'); - - if ( - typeof options.retryAmount !== "undefined" && - typeof options.retryAmount !== "number" - ) - throw new TypeError('Node option "retryAmount" must be a number.'); - - if ( - typeof options.retryDelay !== "undefined" && - typeof options.retryDelay !== "number" - ) - throw new TypeError('Node option "retryDelay" must be a number.'); - - if ( - typeof options.requestTimeout !== "undefined" && - typeof options.requestTimeout !== "number" - ) - throw new TypeError('Node option "requestTimeout" must be a number.'); -} +import nodeCheck from "../utils/nodeCheck"; +import WebSocket from "ws"; export class Node { /** The socket for the node. */ @@ -110,7 +63,7 @@ export class Node { return this.manager.nodes.get(options.identifier || options.host); } - check(options); + nodeCheck(options); this.options = { port: 2333, diff --git a/src/structures/Player.ts b/src/structures/Player.ts index af9483cf..fee86ff5 100644 --- a/src/structures/Player.ts +++ b/src/structures/Player.ts @@ -1,49 +1,10 @@ +import { Filters } from "./Filters"; import { Manager, SearchQuery, SearchResult } from "./Manager"; import { Node } from "./Node"; import { Queue } from "./Queue"; -import { Filters } from "./Filters"; import { Sizes, State, Structure, TrackUtils, VoiceState } from "./Utils"; import * as _ from "lodash"; - -function check(options: PlayerOptions) { - if (!options) throw new TypeError("PlayerOptions must not be empty."); - - if (!/^\d+$/.test(options.guild)) - throw new TypeError( - 'Player option "guild" must be present and be a non-empty string.' - ); - - if (options.textChannel && !/^\d+$/.test(options.textChannel)) - throw new TypeError( - 'Player option "textChannel" must be a non-empty string.' - ); - - if (options.voiceChannel && !/^\d+$/.test(options.voiceChannel)) - throw new TypeError( - 'Player option "voiceChannel" must be a non-empty string.' - ); - - if (options.node && typeof options.node !== "string") - throw new TypeError('Player option "node" must be a non-empty string.'); - - if ( - typeof options.volume !== "undefined" && - typeof options.volume !== "number" - ) - throw new TypeError('Player option "volume" must be a number.'); - - if ( - typeof options.selfMute !== "undefined" && - typeof options.selfMute !== "boolean" - ) - throw new TypeError('Player option "selfMute" must be a boolean.'); - - if ( - typeof options.selfDeafen !== "undefined" && - typeof options.selfDeafen !== "boolean" - ) - throw new TypeError('Player option "selfDeafen" must be a boolean.'); -} +import playerCheck from "../utils/playerCheck"; export class Player { /** The Queue for the Player. */ @@ -121,7 +82,7 @@ export class Player { return this.manager.players.get(options.guild); } - check(options); + playerCheck(options); this.guild = options.guild; this.voiceState = Object.assign({ diff --git a/src/utils/managerCheck.ts b/src/utils/managerCheck.ts new file mode 100644 index 00000000..c17e52b0 --- /dev/null +++ b/src/utils/managerCheck.ts @@ -0,0 +1,64 @@ +import { ManagerOptions } from "../structures/Manager"; + +export default function managerCheck(options: ManagerOptions) { + if (!options) throw new TypeError("ManagerOptions must not be empty."); + + const { + autoPlay, + clientId, + clientName, + defaultSearchPlatform, + nodes, + plugins, + send, + shards, + trackPartial, + } = options; + + if (typeof autoPlay !== "undefined" && typeof autoPlay !== "boolean") { + throw new TypeError('Manager option "autoPlay" must be a boolean.'); + } + + if (typeof clientId !== "undefined" && !/^\d+$/.test(clientId)) { + throw new TypeError( + 'Manager option "clientId" must be a non-empty string.' + ); + } + + if (typeof clientName !== "undefined" && typeof clientName !== "string") { + throw new TypeError('Manager option "clientName" must be a string.'); + } + + if ( + typeof defaultSearchPlatform !== "undefined" && + typeof defaultSearchPlatform !== "string" + ) { + throw new TypeError( + 'Manager option "defaultSearchPlatform" must be a string.' + ); + } + + if (typeof nodes !== "undefined" && !Array.isArray(nodes)) { + throw new TypeError('Manager option "nodes" must be an array.'); + } + + if (typeof plugins !== "undefined" && !Array.isArray(plugins)) { + throw new TypeError('Manager option "plugins" must be a Plugin array.'); + } + + if (typeof send !== "function") { + throw new TypeError( + 'Manager option "send" must be present and a function.' + ); + } + + if (typeof shards !== "undefined" && typeof shards !== "number") { + throw new TypeError('Manager option "shards" must be a number.'); + } + + if (typeof trackPartial !== "undefined" && !Array.isArray(trackPartial)) { + throw new TypeError( + 'Manager option "trackPartial" must be a string array.' + ); + } +} diff --git a/src/utils/nodeCheck.ts b/src/utils/nodeCheck.ts new file mode 100644 index 00000000..8296dcb4 --- /dev/null +++ b/src/utils/nodeCheck.ts @@ -0,0 +1,72 @@ +import { NodeOptions } from "../structures/Node"; + +export default function nodeCheck(options: NodeOptions) { + if (!options) throw new TypeError("NodeOptions must not be empty."); + + const { + host, + identifier, + password, + port, + requestTimeout, + resumeStatus, + resumeTimeout, + retryAmount, + retryDelay, + secure, + } = options; + + if (typeof host !== "string" || !/.+/.test(host)) { + throw new TypeError( + 'Node option "host" must be present and be a non-empty string.' + ); + } + + if (typeof identifier !== "undefined" && typeof identifier !== "string") { + throw new TypeError('Node option "identifier" must be a non-empty string.'); + } + + if ( + typeof password !== "undefined" && + (typeof password !== "string" || !/.+/.test(password)) + ) { + throw new TypeError('Node option "password" must be a non-empty string.'); + } + + if (typeof port !== "undefined" && typeof port !== "number") { + throw new TypeError('Node option "port" must be a number.'); + } + + if ( + typeof requestTimeout !== "undefined" && + typeof requestTimeout !== "number" + ) { + throw new TypeError('Node option "requestTimeout" must be a number.'); + } + + if ( + typeof resumeStatus !== "undefined" && + typeof resumeStatus !== "boolean" + ) { + throw new TypeError('Node option "resumeStatus" must be a boolean.'); + } + + if ( + typeof resumeTimeout !== "undefined" && + typeof resumeTimeout !== "number" + ) { + throw new TypeError('Node option "resumeTimeout" must be a number.'); + } + + if (typeof retryAmount !== "undefined" && typeof retryAmount !== "number") { + throw new TypeError('Node option "retryAmount" must be a number.'); + } + + if (typeof retryDelay !== "undefined" && typeof retryDelay !== "number") { + throw new TypeError('Node option "retryDelay" must be a number.'); + } + + if (typeof secure !== "undefined" && typeof secure !== "boolean") { + throw new TypeError('Node option "secure" must be a boolean.'); + } +} diff --git a/src/utils/playerCheck.ts b/src/utils/playerCheck.ts new file mode 100644 index 00000000..28f712b6 --- /dev/null +++ b/src/utils/playerCheck.ts @@ -0,0 +1,49 @@ +import { PlayerOptions } from "../structures/Player"; + +export default function playerCheck(options: PlayerOptions) { + if (!options) throw new TypeError("PlayerOptions must not be empty."); + + const { + guild, + node, + selfDeafen, + selfMute, + textChannel, + voiceChannel, + volume, + } = options; + + if (!/^\d+$/.test(guild)) { + throw new TypeError( + 'Player option "guild" must be present and be a non-empty string.' + ); + } + + if (node && typeof node !== "string") { + throw new TypeError('Player option "node" must be a non-empty string.'); + } + + if (typeof selfDeafen !== "undefined" && typeof selfDeafen !== "boolean") { + throw new TypeError('Player option "selfDeafen" must be a boolean.'); + } + + if (typeof selfMute !== "undefined" && typeof selfMute !== "boolean") { + throw new TypeError('Player option "selfMute" must be a boolean.'); + } + + if (textChannel && !/^\d+$/.test(textChannel)) { + throw new TypeError( + 'Player option "textChannel" must be a non-empty string.' + ); + } + + if (voiceChannel && !/^\d+$/.test(voiceChannel)) { + throw new TypeError( + 'Player option "voiceChannel" must be a non-empty string.' + ); + } + + if (typeof volume !== "undefined" && typeof volume !== "number") { + throw new TypeError('Player option "volume" must be a number.'); + } +}