From d7aa7f2a18aea40464043899a2eabb9df788fc0f Mon Sep 17 00:00:00 2001 From: FAYStarNext Date: Sat, 7 Sep 2024 07:19:40 +0000 Subject: [PATCH 1/5] Refactor Filters class to use proper type names --- src/structures/Filters.ts | 36 ++++++++++++++++++------------------ src/structures/Manager.ts | 3 +-- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/structures/Filters.ts b/src/structures/Filters.ts index 993cdab..489d406 100644 --- a/src/structures/Filters.ts +++ b/src/structures/Filters.ts @@ -2,13 +2,13 @@ import { Band, bassBoostEqualizer, softEqualizer, trebleBassEqualizer, tvEqualiz import { Player } from "./Player"; export class Filters { - public distortion: distortionOptions | null; + public distortion: DistortionOptions | null; public equalizer: Band[]; - public karaoke: karaokeOptions | null; + public karaoke: KaraokeOptions | null; public player: Player; - public rotation: rotationOptions | null; - public timescale: timescaleOptions | null; - public vibrato: vibratoOptions | null; + public rotation: RotationOptions | null; + public timescale: TimescaleOptions | null; + public vibrato: VibratoOptions | null; public volume: number; private filterStatus: { @@ -68,7 +68,7 @@ export class Filters { return this; } - private setFilterStatus(filter: keyof availableFilters, status: boolean): this { + private setFilterStatus(filter: keyof AvailableFilters, status: boolean): this { this.filterStatus[filter] = status; return this; } @@ -144,7 +144,7 @@ export class Filters { } /** Applies the karaoke options specified by the filter. */ - public setKaraoke(karaoke?: karaokeOptions): this { + public setKaraoke(karaoke?: KaraokeOptions): this { return this.applyFilter({ property: "karaoke", value: karaoke, @@ -152,22 +152,22 @@ export class Filters { } /** Applies the timescale options specified by the filter. */ - public setTimescale(timescale?: timescaleOptions): this { + public setTimescale(timescale?: TimescaleOptions): this { return this.applyFilter({ property: "timescale", value: timescale }); } /** Applies the vibrato options specified by the filter. */ - public setVibrato(vibrato?: vibratoOptions): this { + public setVibrato(vibrato?: VibratoOptions): this { return this.applyFilter({ property: "vibrato", value: vibrato }); } /** Applies the rotation options specified by the filter. */ - public setRotation(rotation?: rotationOptions): this { + public setRotation(rotation?: RotationOptions): this { return this.applyFilter({ property: "rotation", value: rotation }); } /** Applies the distortion options specified by the filter. */ - public setDistortion(distortion?: distortionOptions): this { + public setDistortion(distortion?: DistortionOptions): this { return this.applyFilter({ property: "distortion", value: distortion }); } @@ -199,13 +199,13 @@ export class Filters { } /** Returns the status of the specified filter . */ - public getFilterStatus(filter: keyof availableFilters): boolean { + public getFilterStatus(filter: keyof AvailableFilters): boolean { return this.filterStatus[filter]; } } /** Options for adjusting the timescale of audio. */ -interface timescaleOptions { +interface TimescaleOptions { /** The speed factor for the timescale. */ speed?: number; /** The pitch factor for the timescale. */ @@ -215,7 +215,7 @@ interface timescaleOptions { } /** Options for applying vibrato effect to audio. */ -interface vibratoOptions { +interface VibratoOptions { /** The frequency of the vibrato effect. */ frequency: number; /** * The depth of the vibrato effect.*/ @@ -223,13 +223,13 @@ interface vibratoOptions { } /** Options for applying rotation effect to audio. */ -interface rotationOptions { +interface RotationOptions { /** The rotation speed in Hertz (Hz). */ rotationHz: number; } /** Options for applying karaoke effect to audio. */ -interface karaokeOptions { +interface KaraokeOptions { /** The level of karaoke effect. */ level?: number; /** The mono level of karaoke effect. */ @@ -240,7 +240,7 @@ interface karaokeOptions { filterWidth?: number; } -interface distortionOptions { +interface DistortionOptions { sinOffset?: number; sinScale?: number; cosOffset?: number; @@ -251,7 +251,7 @@ interface distortionOptions { scale?: number; } -interface availableFilters { +interface AvailableFilters { bassboost: boolean; distort: boolean; eightD: boolean; diff --git a/src/structures/Manager.ts b/src/structures/Manager.ts index aac867f..f5b4628 100644 --- a/src/structures/Manager.ts +++ b/src/structures/Manager.ts @@ -14,7 +14,6 @@ import { 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 ".."; @@ -176,7 +175,7 @@ export class Manager extends TypedEmitter { throw new Error("No available nodes."); } if (this.options.caches.enabled && this.options.caches.time > 0 && typeof query === "string") { - let data = this.caches.get(query); + const data = this.caches.get(query); if (data) return data; } const _query: SearchQuery = typeof query === "string" ? { query } : query; From 59862344e800d1b7dae949c6d321e97629ef1f81 Mon Sep 17 00:00:00 2001 From: FAYStarNext Date: Sat, 7 Sep 2024 07:20:55 +0000 Subject: [PATCH 2/5] Refactor Node class to remove unused code and fix socket handling --- src/structures/Node.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/structures/Node.ts b/src/structures/Node.ts index 78fa3cf..49308c1 100644 --- a/src/structures/Node.ts +++ b/src/structures/Node.ts @@ -128,7 +128,6 @@ export class Node { if (players.size) players.forEach((p) => p.destroy()); this.socket.close(1000, "destroy"); - // @ts-ignore this.socket.removeAllListeners(); this.socket = null; @@ -147,7 +146,6 @@ export class Node { this.manager.emit("NodeError", this, error); return this.destroy(); } - // @ts-ignore this.socket?.removeAllListeners(); this.socket = null; this.manager.emit("NodeReconnect", this); From 5680124f0795e628cc5335bdb2a731602809d455 Mon Sep 17 00:00:00 2001 From: FAYStarNext Date: Sat, 7 Sep 2024 07:25:00 +0000 Subject: [PATCH 3/5] Refactor Node and Filters classes to use proper type names --- src/index.ts | 8 +++++++- src/structures/Filters.ts | 2 +- src/structures/Manager.ts | 2 +- src/structures/Node.ts | 2 +- src/structures/Player.ts | 2 +- src/structures/Rest.ts | 5 +++-- src/utils/{filtersEqualizers.ts => FiltersEqualizers.ts} | 0 src/utils/{managerCheck.ts => ManagerCheck.ts} | 2 +- src/utils/{nodeCheck.ts => NodeCheck.ts} | 2 +- src/utils/{playerCheck.ts => PlayerCheck.ts} | 2 +- 10 files changed, 17 insertions(+), 10 deletions(-) rename src/utils/{filtersEqualizers.ts => FiltersEqualizers.ts} (100%) rename src/utils/{managerCheck.ts => ManagerCheck.ts} (97%) rename src/utils/{nodeCheck.ts => NodeCheck.ts} (97%) rename src/utils/{playerCheck.ts => PlayerCheck.ts} (95%) diff --git a/src/index.ts b/src/index.ts index 1a65971..136b882 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,4 +2,10 @@ export * from "./structures/Manager"; export * from "./structures/Node"; export * from "./structures/Player"; export * from "./structures/Queue"; -export * from "./structures/Utils"; \ No newline at end of file +export * from "./structures/Utils"; +export * from "./structures/Filters"; +export * from "./structures/Rest"; +export * from "./utils/FiltersEqualizers"; +export * from "./utils/ManagerCheck"; +export * from "./utils/NodeCheck"; +export * from "./utils/PlayerCheck"; \ No newline at end of file diff --git a/src/structures/Filters.ts b/src/structures/Filters.ts index 489d406..0991a8e 100644 --- a/src/structures/Filters.ts +++ b/src/structures/Filters.ts @@ -1,4 +1,4 @@ -import { Band, bassBoostEqualizer, softEqualizer, trebleBassEqualizer, tvEqualizer, vaporwaveEqualizer } from "../utils/filtersEqualizers"; +import { Band, bassBoostEqualizer, softEqualizer, trebleBassEqualizer, tvEqualizer, vaporwaveEqualizer } from "../utils/FiltersEqualizers"; import { Player } from "./Player"; export class Filters { diff --git a/src/structures/Manager.ts b/src/structures/Manager.ts index f5b4628..db3a7a8 100644 --- a/src/structures/Manager.ts +++ b/src/structures/Manager.ts @@ -17,7 +17,7 @@ import { Collection } from "@discordjs/collection"; import { Node, NodeOptions } from "./Node"; import { Player, PlayerOptions, Track, UnresolvedTrack } from "./Player"; import { VoiceState } from ".."; -import managerCheck from "../utils/managerCheck"; +import managerCheck from "../utils/ManagerCheck"; import { ClientUser, User } from "discord.js"; import { TypedEmitter } from "tiny-typed-emitter"; diff --git a/src/structures/Node.ts b/src/structures/Node.ts index 49308c1..03e072a 100644 --- a/src/structures/Node.ts +++ b/src/structures/Node.ts @@ -12,7 +12,7 @@ import { import { LavalinkResponse, Manager, PlaylistRawData } from "./Manager"; import { Player, Track, UnresolvedTrack } from "./Player"; import { Rest } from "./Rest"; -import nodeCheck from "../utils/nodeCheck"; +import nodeCheck from "../utils/NodeCheck"; import WebSocket from "ws"; export class Node { diff --git a/src/structures/Player.ts b/src/structures/Player.ts index 64fa633..85d5331 100644 --- a/src/structures/Player.ts +++ b/src/structures/Player.ts @@ -4,7 +4,7 @@ import { LavalinkInfo, Node } from "./Node"; import { Queue } from "./Queue"; import { Sizes, State, Structure, TrackSourceName, TrackUtils, VoiceState } from "./Utils"; import * as _ from "lodash"; -import playerCheck from "../utils/playerCheck"; +import playerCheck from "../utils/PlayerCheck"; import { ClientUser, Message, User } from "discord.js"; export class Player { diff --git a/src/structures/Rest.ts b/src/structures/Rest.ts index 77ea149..f7d069b 100644 --- a/src/structures/Rest.ts +++ b/src/structures/Rest.ts @@ -44,7 +44,7 @@ export class Rest { } /* Sends a GET request to the specified endpoint and returns the response data. */ - private async request(method: string, endpoint: string, body?: unknown): Promise { + private async request(method: Method, endpoint: string, body?: unknown): Promise { const config: AxiosRequestConfig = { method, url: this.url + endpoint, @@ -63,7 +63,6 @@ export class Rest { this.node.destroy(); this.node.manager.createNode(this.node.options).connect(); } - return null; } } @@ -118,3 +117,5 @@ interface playOptions { noReplace?: boolean; }; } + +export type Method = "GET" | "POST" | "PATCH" | "DELETE"; \ No newline at end of file diff --git a/src/utils/filtersEqualizers.ts b/src/utils/FiltersEqualizers.ts similarity index 100% rename from src/utils/filtersEqualizers.ts rename to src/utils/FiltersEqualizers.ts diff --git a/src/utils/managerCheck.ts b/src/utils/ManagerCheck.ts similarity index 97% rename from src/utils/managerCheck.ts rename to src/utils/ManagerCheck.ts index 98f95cf..2adf23d 100644 --- a/src/utils/managerCheck.ts +++ b/src/utils/ManagerCheck.ts @@ -1,6 +1,6 @@ import { ManagerOptions } from "../structures/Manager"; -export default function managerCheck(options: ManagerOptions) { +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, usePriority, useNode, replaceYouTubeCredentials } = diff --git a/src/utils/nodeCheck.ts b/src/utils/NodeCheck.ts similarity index 97% rename from src/utils/nodeCheck.ts rename to src/utils/NodeCheck.ts index f7c63fb..b31b277 100644 --- a/src/utils/nodeCheck.ts +++ b/src/utils/NodeCheck.ts @@ -1,6 +1,6 @@ import { NodeOptions } from "../structures/Node"; -export default function nodeCheck(options: NodeOptions) { +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, priority } = options; diff --git a/src/utils/playerCheck.ts b/src/utils/PlayerCheck.ts similarity index 95% rename from src/utils/playerCheck.ts rename to src/utils/PlayerCheck.ts index 5cf5c47..10a9758 100644 --- a/src/utils/playerCheck.ts +++ b/src/utils/PlayerCheck.ts @@ -1,6 +1,6 @@ import { PlayerOptions } from "../structures/Player"; -export default function playerCheck(options: PlayerOptions) { +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; From e15078de8810fc891c5297af80f33e26d1a18b51 Mon Sep 17 00:00:00 2001 From: FAYStarNext Date: Sat, 7 Sep 2024 07:54:08 +0000 Subject: [PATCH 4/5] Refactor file paths to use proper casing --- src/{structures => Structures}/Filters.ts | 2 +- src/{structures => Structures}/Manager.ts | 4 ++-- src/{structures => Structures}/Node.ts | 2 +- src/{structures => Structures}/Player.ts | 6 ++---- src/{structures => Structures}/Queue.ts | 0 src/{structures => Structures}/Rest.ts | 0 src/{structures => Structures}/Utils.ts | 0 src/{utils => Utils}/FiltersEqualizers.ts | 0 src/{utils => Utils}/ManagerCheck.ts | 8 +++++--- src/{utils => Utils}/NodeCheck.ts | 2 +- src/{utils => Utils}/PlayerCheck.ts | 2 +- src/index.ts | 22 +++++++++++----------- 12 files changed, 24 insertions(+), 24 deletions(-) rename src/{structures => Structures}/Filters.ts (99%) rename src/{structures => Structures}/Manager.ts (99%) rename src/{structures => Structures}/Node.ts (99%) rename src/{structures => Structures}/Player.ts (99%) rename src/{structures => Structures}/Queue.ts (100%) rename src/{structures => Structures}/Rest.ts (100%) rename src/{structures => Structures}/Utils.ts (100%) rename src/{utils => Utils}/FiltersEqualizers.ts (100%) rename src/{utils => Utils}/ManagerCheck.ts (91%) rename src/{utils => Utils}/NodeCheck.ts (97%) rename src/{utils => Utils}/PlayerCheck.ts (95%) diff --git a/src/structures/Filters.ts b/src/Structures/Filters.ts similarity index 99% rename from src/structures/Filters.ts rename to src/Structures/Filters.ts index 0991a8e..374c23f 100644 --- a/src/structures/Filters.ts +++ b/src/Structures/Filters.ts @@ -1,4 +1,4 @@ -import { Band, bassBoostEqualizer, softEqualizer, trebleBassEqualizer, tvEqualizer, vaporwaveEqualizer } from "../utils/FiltersEqualizers"; +import { Band, bassBoostEqualizer, softEqualizer, trebleBassEqualizer, tvEqualizer, vaporwaveEqualizer } from "../Utils/FiltersEqualizers"; import { Player } from "./Player"; export class Filters { diff --git a/src/structures/Manager.ts b/src/Structures/Manager.ts similarity index 99% rename from src/structures/Manager.ts rename to src/Structures/Manager.ts index db3a7a8..8fba726 100644 --- a/src/structures/Manager.ts +++ b/src/Structures/Manager.ts @@ -17,7 +17,7 @@ import { Collection } from "@discordjs/collection"; import { Node, NodeOptions } from "./Node"; import { Player, PlayerOptions, Track, UnresolvedTrack } from "./Player"; import { VoiceState } from ".."; -import managerCheck from "../utils/ManagerCheck"; +import managerCheck from "../Utils/ManagerCheck"; import { ClientUser, User } from "discord.js"; import { TypedEmitter } from "tiny-typed-emitter"; @@ -420,7 +420,7 @@ export interface ManagerOptions { defaultSearchPlatform?: SearchPlatform; /** Whether the YouTube video titles should be replaced if the Author does not exactly match. */ replaceYouTubeCredentials?: boolean; - caches?: { + caches: { /** Whether to cache the search results. */ enabled: boolean; /** The time to cache the search results. */ diff --git a/src/structures/Node.ts b/src/Structures/Node.ts similarity index 99% rename from src/structures/Node.ts rename to src/Structures/Node.ts index 03e072a..ae1c5bd 100644 --- a/src/structures/Node.ts +++ b/src/Structures/Node.ts @@ -12,7 +12,7 @@ import { import { LavalinkResponse, Manager, PlaylistRawData } from "./Manager"; import { Player, Track, UnresolvedTrack } from "./Player"; import { Rest } from "./Rest"; -import nodeCheck from "../utils/NodeCheck"; +import nodeCheck from "../Utils/NodeCheck"; import WebSocket from "ws"; export class Node { diff --git a/src/structures/Player.ts b/src/Structures/Player.ts similarity index 99% rename from src/structures/Player.ts rename to src/Structures/Player.ts index 85d5331..ed04415 100644 --- a/src/structures/Player.ts +++ b/src/Structures/Player.ts @@ -4,7 +4,7 @@ import { LavalinkInfo, Node } from "./Node"; import { Queue } from "./Queue"; import { Sizes, State, Structure, TrackSourceName, TrackUtils, VoiceState } from "./Utils"; import * as _ from "lodash"; -import playerCheck from "../utils/PlayerCheck"; +import playerCheck from "../Utils/PlayerCheck"; import { ClientUser, Message, User } from "discord.js"; export class Player { @@ -545,9 +545,7 @@ export class Player { if (!this.queue.current) return undefined; position = Number(position); - if (isNaN(position)) { - throw new RangeError("Position must be a number."); - } + if (isNaN(position)) throw new RangeError("Position must be a number."); if (position < 0 || position > this.queue.current.duration) position = Math.max(Math.min(position, this.queue.current.duration), 0); this.position = position; diff --git a/src/structures/Queue.ts b/src/Structures/Queue.ts similarity index 100% rename from src/structures/Queue.ts rename to src/Structures/Queue.ts diff --git a/src/structures/Rest.ts b/src/Structures/Rest.ts similarity index 100% rename from src/structures/Rest.ts rename to src/Structures/Rest.ts diff --git a/src/structures/Utils.ts b/src/Structures/Utils.ts similarity index 100% rename from src/structures/Utils.ts rename to src/Structures/Utils.ts diff --git a/src/utils/FiltersEqualizers.ts b/src/Utils/FiltersEqualizers.ts similarity index 100% rename from src/utils/FiltersEqualizers.ts rename to src/Utils/FiltersEqualizers.ts diff --git a/src/utils/ManagerCheck.ts b/src/Utils/ManagerCheck.ts similarity index 91% rename from src/utils/ManagerCheck.ts rename to src/Utils/ManagerCheck.ts index 2adf23d..a577517 100644 --- a/src/utils/ManagerCheck.ts +++ b/src/Utils/ManagerCheck.ts @@ -1,9 +1,9 @@ -import { ManagerOptions } from "../structures/Manager"; +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, usePriority, useNode, replaceYouTubeCredentials } = + const { autoPlay, clientId, clientName, defaultSearchPlatform, nodes, plugins, send, shards, trackPartial, usePriority, useNode, replaceYouTubeCredentials, caches } = options; if (typeof autoPlay !== "undefined" && typeof autoPlay !== "boolean") { @@ -17,7 +17,9 @@ export default function ManagerCheck(options: ManagerOptions) { if (typeof clientName !== "undefined" && typeof clientName !== "string") { throw new TypeError('Manager option "clientName" must be a string.'); } - + if (typeof caches !== "undefined" && typeof caches !== "object") { + throw new TypeError('Manager option "caches" must be a object.'); + } if (typeof defaultSearchPlatform !== "undefined" && typeof defaultSearchPlatform !== "string") { throw new TypeError('Manager option "defaultSearchPlatform" must be a string.'); } diff --git a/src/utils/NodeCheck.ts b/src/Utils/NodeCheck.ts similarity index 97% rename from src/utils/NodeCheck.ts rename to src/Utils/NodeCheck.ts index b31b277..dc6cdba 100644 --- a/src/utils/NodeCheck.ts +++ b/src/Utils/NodeCheck.ts @@ -1,4 +1,4 @@ -import { NodeOptions } from "../structures/Node"; +import { NodeOptions } from "../Structures/Node"; export default function NodeCheck(options: NodeOptions) { if (!options) throw new TypeError("NodeOptions must not be empty."); diff --git a/src/utils/PlayerCheck.ts b/src/Utils/PlayerCheck.ts similarity index 95% rename from src/utils/PlayerCheck.ts rename to src/Utils/PlayerCheck.ts index 10a9758..379ee3f 100644 --- a/src/utils/PlayerCheck.ts +++ b/src/Utils/PlayerCheck.ts @@ -1,4 +1,4 @@ -import { PlayerOptions } from "../structures/Player"; +import { PlayerOptions } from "../Structures/Player"; export default function PlayerCheck(options: PlayerOptions) { if (!options) throw new TypeError("PlayerOptions must not be empty."); diff --git a/src/index.ts b/src/index.ts index 136b882..6dcd663 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,11 @@ -export * from "./structures/Manager"; -export * from "./structures/Node"; -export * from "./structures/Player"; -export * from "./structures/Queue"; -export * from "./structures/Utils"; -export * from "./structures/Filters"; -export * from "./structures/Rest"; -export * from "./utils/FiltersEqualizers"; -export * from "./utils/ManagerCheck"; -export * from "./utils/NodeCheck"; -export * from "./utils/PlayerCheck"; \ No newline at end of file +export * from "./Structures/Manager"; +export * from "./Structures/Node"; +export * from "./Structures/Player"; +export * from "./Structures/Queue"; +export * from "./Structures/Utils"; +export * from "./Structures/Filters"; +export * from "./Structures/Rest"; +export * from "./Utils/FiltersEqualizers"; +export * from "./Utils/ManagerCheck"; +export * from "./Utils/NodeCheck"; +export * from "./Utils/PlayerCheck"; \ No newline at end of file From 5835076b2498ddaec086596bc7af574970edcd88 Mon Sep 17 00:00:00 2001 From: FAYStarNext Date: Sat, 7 Sep 2024 07:54:29 +0000 Subject: [PATCH 5/5] Refactor copyright year and author name --- LICENSE | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index fdebf61..3a3ef60 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2024 FAYStarNext +Copyright (c) 2024 EwarinDev Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/package.json b/package.json index 5f6176d..ae52bb4 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "sunday.ts", "main": "dist/index.js", "types": "dist/index.d.ts", - "version": "1.1.0", + "version": "1.1.1", "description": "Sunday a lavalink wrapper", "license": "MIT", "author": "EwarinDev",