diff --git a/example/src/index.ts b/example/src/index.ts index bd80d62..617f6e4 100644 --- a/example/src/index.ts +++ b/example/src/index.ts @@ -34,9 +34,6 @@ let manager = new Manager({ manager.on("NodeConnect", (node) => { console.log(`Node ${node.options.host} connected`); }); -// manager.on("NodeRaw", async (node) => { -// console.log(`sent raw data: ${JSON.stringify(node)}`); -// }); manager.on("PlayerCreate", (player) => { console.log(`Player created in guild ${player.guild}`); }); @@ -54,36 +51,23 @@ client.on("messageCreate", async (message) => { let res; let end; try { - // Search for tracks using a query or url, using a query searches youtube automatically and the track requester object res = await manager.search({query: search}); end = `Time took: ${Math.round(performance.now() - start)}ms.`; - // Check the load type as this command is not that advanced for basics if (res.loadType === 'empty') throw res; - if (res.loadType === 'playlist') { - throw { message: 'Playlists are not supported with this command.' }; - } + if (res.loadType === 'playlist') throw Error('Playlists are not supported with this command.'); } catch (err) { return message.reply(`there was an error while searching: ${err}`); } - - if (res.loadType === 'error') { - return message.reply('there was no tracks found with that query.'); - } - - // Create the player + if (res.loadType === 'error') return message.reply('there was no tracks found with that query.'); const player = manager.create({ guild: message.guild?.id as string, voiceChannel: message.member?.voice.channel.id, textChannel: message.channel.id, volume: 100, }); - - // Connect to the voice channel and add the track to the queue player.connect(); - await player.queue.add(res.tracks[0]); - // Checks if the client should play the track if it's the first one added + player.queue.add(res.tracks[0]); if (!player.playing && !player.paused && !player.queue.size) player.play(); - return message.reply(`enqueuing ${res.tracks[0].title}. ${end}`); } }); diff --git a/package.json b/package.json index 5cb3f6c..aeda9ba 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.0.15-indev", + "version": "1.0.16", "description": "Sunday a lavalink wrapper", "license": "MIT", "author": "FAYStarNext", 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 4b92d25..1d06448 100644 --- a/src/structures/Manager.ts +++ b/src/structures/Manager.ts @@ -87,7 +87,15 @@ export class Manager extends TypedEmitter { /** Returns the node to use. */ public get useableNodes(): Node { - return this.options.usePriority ? this.priorityNode : this.options.useNode === "leastLoad" ? this.leastLoadNode.first() : this.leastPlayersNode.first(); + let selectedNode: Node; + if (this.options.usePriority) { + selectedNode = this.priorityNode; + } else if (this.options.useNode === "leastLoad") { + selectedNode = this.leastLoadNode.first(); + } else { + selectedNode = this.leastPlayersNode.first(); + } + return selectedNode; } /** @@ -244,20 +252,6 @@ export class Manager extends TypedEmitter { throw new Error(err); } } - - private ToOrginalURL(uri: string): string { - switch (uri.split(":")[0]) { - case "yt": - const videoCode = uri.match(/v=([^&]+)/)?.[1]; - const playlistCode = uri.match(/list=([^&]+)/)?.[1]; - if (playlistCode) { - return "https://www.youtube.com/playlist?list=" + playlistCode; - } - return "https://www.youtube.com/watch?v=" + (videoCode ?? ""); - } - return uri; - } - private CheckURL(uri: string): string { let data = this.regex_link(uri); switch (data) {