From 2c876755a0c71a1179f96369658469a8ccc0c620 Mon Sep 17 00:00:00 2001 From: kagchi Date: Tue, 5 Dec 2023 20:17:26 +0700 Subject: [PATCH] fix: remove unused structures --- packages/core/src/Structures/Filter.ts | 50 ---------------------- packages/core/src/Structures/Kirishima.ts | 52 +++++++++-------------- packages/core/src/index.ts | 1 - packages/core/src/typings/index.ts | 3 +- 4 files changed, 22 insertions(+), 84 deletions(-) delete mode 100644 packages/core/src/Structures/Filter.ts diff --git a/packages/core/src/Structures/Filter.ts b/packages/core/src/Structures/Filter.ts deleted file mode 100644 index 685a54f..0000000 --- a/packages/core/src/Structures/Filter.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { - ChannelMixEqualizer, - DistortionEqualizer, - Equalizer, - KaraokeEqualizer, - LowPassEqualizer, - RotationEqualizer, - TimeScaleEqualizer, - TremoloEqualizer, - VibratoEqualizer -} from "lavalink-api-types"; - -export class KirishimaFilter { - public volume: number | null; - public equalizer: Equalizer[] | null; - public karaoke: KaraokeEqualizer | null; - public timescale: TimeScaleEqualizer | null; - public tremolo: TremoloEqualizer | null; - public vibrato: VibratoEqualizer | null; - public rotation: RotationEqualizer | null; - public distortion: DistortionEqualizer | null; - public channelMix: ChannelMixEqualizer | null; - public lowPass: LowPassEqualizer | null; - - public constructor(options?: KirishimaFilterOptions) { - this.volume = options?.volume ?? 1.0; - this.equalizer = options?.equalizer ?? null; - this.karaoke = options?.karaoke ?? null; - this.timescale = options?.timescale ?? null; - this.tremolo = options?.tremolo ?? null; - this.vibrato = options?.vibrato ?? null; - this.rotation = options?.rotation ?? null; - this.distortion = options?.distortion ?? null; - this.channelMix = options?.channelMix ?? null; - this.lowPass = options?.lowPass ?? null; - } -} - -export interface KirishimaFilterOptions { - volume: number | null; - equalizer: Equalizer[] | null; - karaoke: KaraokeEqualizer | null; - timescale: TimeScaleEqualizer | null; - tremolo: TremoloEqualizer | null; - vibrato: VibratoEqualizer | null; - rotation: RotationEqualizer | null; - distortion: DistortionEqualizer | null; - channelMix: ChannelMixEqualizer | null; - lowPass: LowPassEqualizer | null; -} diff --git a/packages/core/src/Structures/Kirishima.ts b/packages/core/src/Structures/Kirishima.ts index 881fd09..330ca25 100644 --- a/packages/core/src/Structures/Kirishima.ts +++ b/packages/core/src/Structures/Kirishima.ts @@ -1,17 +1,17 @@ /* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */ import { EventEmitter } from "node:events"; -import { KirishimaNodeOptions, KirishimaOptions, KirishimaPlayerOptions, LoadTrackResponse } from "../typings/index.js"; +import { KirishimaNodeOptions, KirishimaOptions } from "../typings/index.js"; import crypto from "node:crypto"; import { KirishimaNode } from "./Node.js"; import { GatewayVoiceServerUpdateDispatch, GatewayVoiceStateUpdateDispatch } from "discord-api-types/gateway/v9"; import { Collection } from "@discordjs/collection"; -import { KirishimaPlayer } from "./Player.js"; -import { Structure } from "./Structure.js"; +import { PlayerOptions } from "@kirishima/types"; +import { BasePlayer } from "./BasePlayer.js"; export class Kirishima extends EventEmitter { public nodes = new Collection(); - public players?: Collection; + public players?: Collection; public constructor(public options: KirishimaOptions) { super(); @@ -19,7 +19,7 @@ export class Kirishima extends EventEmitter { if ( typeof options.spawnPlayer !== "function" || - (typeof options.spawnPlayer === undefined && (typeof options.fetchPlayer !== "function" || typeof options.fetchPlayer === undefined)) + (typeof options.spawnPlayer === "undefined" && (typeof options.fetchPlayer !== "function" || typeof options.fetchPlayer === "undefined")) ) { this.players = new Collection(); options.spawnPlayer = this.defaultSpawnPlayerHandler.bind(this); @@ -27,7 +27,7 @@ export class Kirishima extends EventEmitter { if ( typeof options.fetchPlayer !== "function" || - (typeof options.fetchPlayer === undefined && (typeof options.spawnPlayer !== "function" || typeof options.spawnPlayer === undefined)) + (typeof options.fetchPlayer === "undefined" && (typeof options.spawnPlayer !== "function" || typeof options.spawnPlayer === "undefined")) ) { options.fetchPlayer = this.defaultFetchPlayerHandler.bind(this); } @@ -35,14 +35,9 @@ export class Kirishima extends EventEmitter { if (!options.nodes.length) throw new Error("Nodes option must not a empty array"); } - public async initialize(clientId?: string) { + public async initialize(clientId?: string): Promise { if (!clientId && !this.options.clientId) throw new Error("Invalid clientId provided"); if (clientId && !this.options.clientId) this.options.clientId = clientId; - if (this.options.plugins) { - for (const plugin of [...this.options.plugins.values()]) { - await plugin.load(this); - } - } return this.setNodes(this.options.nodes); } @@ -50,29 +45,29 @@ export class Kirishima extends EventEmitter { const isArray = Array.isArray(nodeOrNodes); if (isArray) { for (const node of nodeOrNodes) { - const kirishimaNode = new (Structure.get("KirishimaNode"))(node, this); + const kirishimaNode = new KirishimaNode(node, this); await kirishimaNode.connect(); this.nodes.set(node.identifier ??= crypto.randomBytes(4).toString("hex"), kirishimaNode); } return this; } - const kirishimaNode = new (Structure.get("KirishimaNode"))(nodeOrNodes, this); + const kirishimaNode = new KirishimaNode(nodeOrNodes, this); await kirishimaNode.connect(); this.nodes.set(nodeOrNodes.identifier ??= crypto.randomBytes(4).toString("hex"), kirishimaNode); return this; } - public setClientName(clientName: string) { + public setClientName(clientName: string): this { this.options.clientName = clientName; return this; } - public setClientId(clientId: string) { + public setClientId(clientId: string): this { this.options.clientId = clientId; return this; } - public resolveNode(identifierOrGroup?: string) { + public resolveNode(identifierOrGroup?: string): KirishimaNode | undefined { const resolveGroupedNode = this.nodes.filter(x => x.connected).find(x => x.options.group?.includes(identifierOrGroup!)!); if (resolveGroupedNode) return resolveGroupedNode; const resolveIdenfitierNode = this.nodes.filter(x => x.connected).find(x => x.options.identifier === identifierOrGroup); @@ -80,7 +75,7 @@ export class Kirishima extends EventEmitter { return this.resolveBestNode().first(); } - public resolveBestNode() { + public resolveBestNode(): Collection { return this.nodes .filter(x => x.connected) .sort((x, y) => { @@ -90,30 +85,23 @@ export class Kirishima extends EventEmitter { }); } - public async resolveTracks(options: string | { source?: string | undefined; query: string }, node?: KirishimaNode): Promise { - node ??= this.resolveNode(); - const resolveTracks = await node!.rest.loadTracks(options); - if (resolveTracks.tracks.length) resolveTracks.tracks = resolveTracks.tracks.map(x => new (Structure.get("KirishimaTrack"))(x)); - return resolveTracks as unknown as LoadTrackResponse; - } - - public spawnPlayer(options: KirishimaPlayerOptions, node?: KirishimaNode) { + public spawnPlayer(options: PlayerOptions, node?: KirishimaNode): unknown { return this.options.spawnPlayer!(options.guildId, options, node ?? this.resolveNode()!); } - public async handleVoiceServerUpdate(packet: GatewayVoiceServerUpdateDispatch) { + public async handleVoiceServerUpdate(packet: GatewayVoiceServerUpdateDispatch): Promise { for (const node of [...this.nodes.values()]) { await node.handleVoiceServerUpdate(packet); } } - public async handleVoiceStateUpdate(packet: GatewayVoiceStateUpdateDispatch) { + public async handleVoiceStateUpdate(packet: GatewayVoiceStateUpdateDispatch): Promise { for (const node of [...this.nodes.values()]) { await node.handleVoiceStateUpdate(packet); } } - public async handleRawPacket(t: "VOICE_SERVER_UPDATE" | "VOICE_STATE_UPDATE", packet: unknown) { + public async handleRawPacket(t: "VOICE_SERVER_UPDATE" | "VOICE_STATE_UPDATE", packet: unknown): Promise { if (t === "VOICE_STATE_UPDATE") { await this.handleVoiceStateUpdate(packet as GatewayVoiceStateUpdateDispatch); } @@ -122,15 +110,15 @@ export class Kirishima extends EventEmitter { } } - private defaultSpawnPlayerHandler(guildId: string, options: KirishimaPlayerOptions, node: KirishimaNode) { + private defaultSpawnPlayerHandler(guildId: string, options: PlayerOptions, node: KirishimaNode): BasePlayer { const player = this.players!.has(guildId); if (player) return this.players!.get(guildId)!; - const kirishimaPlayer = new (Structure.get("KirishimaPlayer"))(options, this, node); + const kirishimaPlayer = new BasePlayer(options, this, node); this.players!.set(guildId, kirishimaPlayer); return kirishimaPlayer; } - private defaultFetchPlayerHandler(guildId: string) { + private defaultFetchPlayerHandler(guildId: string): BasePlayer | undefined { return this.players!.get(guildId); } } diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 5d4dcdd..dfe2a01 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,6 +1,5 @@ export * from "./Structures/Node.js"; export * from "./Structures/Kirishima.js"; -export * from "./Structures/Filter.js"; export * from "./Structures/BasePlayer.js"; export * from "./typings/index.js"; diff --git a/packages/core/src/typings/index.ts b/packages/core/src/typings/index.ts index a8d7d03..dca18f1 100644 --- a/packages/core/src/typings/index.ts +++ b/packages/core/src/typings/index.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-redundant-type-constituents */ import { Awaitable } from "@sapphire/utilities"; import { KirishimaNode } from "../Structures/Node.js"; import { PlayerOptions, ShardPayload } from "@kirishima/types"; @@ -21,7 +22,7 @@ export interface KirishimaOptions { export type SpawnPlayerOptionHook = (guildId: string, options: PlayerOptions, node: KirishimaNode) => Awaitable; -export type PlayerOptionHook = (guildId: string) => Awaitable; +export type PlayerOptionHook = (guildId: string) => Awaitable; export interface KirishimaNodeOptions { identifier?: string;