From e04e514117a672737eb84fe747ee3b1f54982a55 Mon Sep 17 00:00:00 2001 From: Blacky <77108939+brblacky@users.noreply.github.com> Date: Fri, 5 Jan 2024 12:47:17 +0530 Subject: [PATCH] Update package version and fix search loop --- package.json | 2 +- src/commands/music/Search.ts | 2 +- src/commands/playlist/Add.ts | 5 ++++- src/structures/Dispatcher.ts | 10 ++++++---- src/structures/Queue.ts | 6 +++--- src/utils/SetupSystem.ts | 4 ++-- 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index fe4e200b0..8f97b5d4b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lavamusic", - "version": "4.0.3", + "version": "4.0.4", "description": "LavaMusic is a music bot for Discord, written in JavaScript using the Discord.js, Typescript, Shoukaku (Lavalink) library.", "main": "dist/index.js", "type": "module", diff --git a/src/commands/music/Search.ts b/src/commands/music/Search.ts index af3acd944..ccb8658ba 100644 --- a/src/commands/music/Search.ts +++ b/src/commands/music/Search.ts @@ -104,7 +104,7 @@ export default class Search extends Command { idle: 60000 / 2, }); collector.on('collect', async (int: any) => { - for (let i = 0; i < res.data.length; i++) { + for (let i = 0; i < res.data[0]; i++) { if (int.customId === `${i + 1}`) { let track = res.data[i]; track = player.buildTrack(track, ctx.author); diff --git a/src/commands/playlist/Add.ts b/src/commands/playlist/Add.ts index ab6dadc8d..cadd47440 100644 --- a/src/commands/playlist/Add.ts +++ b/src/commands/playlist/Add.ts @@ -96,10 +96,13 @@ export default class Add extends Command { ], }); let trackStrings; + let count; if (res.loadType === LoadType.PLAYLIST) { trackStrings = res.data.tracks.map((track) => JSON.stringify(track)); + count = res.data.tracks.length; } else { trackStrings = [JSON.stringify(res.data[0])]; + count = 1; } await client.prisma.playlist.update({ where: { @@ -113,7 +116,7 @@ export default class Add extends Command { ctx.sendMessage({ embeds: [ { - description: `Added ${res.tracks.length} to ${playlistData.name}`, + description: `Added ${count} to ${playlistData.name}`, color: client.color.green, }, ], diff --git a/src/structures/Dispatcher.ts b/src/structures/Dispatcher.ts index c149960ec..07691693f 100644 --- a/src/structures/Dispatcher.ts +++ b/src/structures/Dispatcher.ts @@ -22,11 +22,13 @@ export class Song implements Track { } pluginInfo: unknown; - constructor(track: Song, user: User) { + constructor(track: Song | Track, user: User) { if (!track) throw new Error('Track is not provided'); this.encoded = track.encoded; - this.info = track.info; - if (this.info && this.info.requester === undefined) this.info.requester = user; + this.info = { + ...track.info, + requester: user, + }; } } export default class Dispatcher { @@ -174,7 +176,7 @@ export default class Dispatcher { this.loop = loop; } - public buildTrack(track: Song, user: User): Song { + public buildTrack(track: Song | Track, user: User): Song { return new Song(track, user); } public async isPlaying(): Promise { diff --git a/src/structures/Queue.ts b/src/structures/Queue.ts index 4562dadea..e60869570 100644 --- a/src/structures/Queue.ts +++ b/src/structures/Queue.ts @@ -1,5 +1,5 @@ import { Guild } from 'discord.js'; -import { Node } from 'shoukaku'; +import { LavalinkResponse, Node } from 'shoukaku'; import { Dispatcher, Lavamusic } from './index.js'; export class Queue extends Map { @@ -56,10 +56,10 @@ export class Queue extends Map { } } - public async search(query: string): Promise { + public async search(query: string): Promise { const node = this.client.shoukaku.options.nodeResolver(this.client.shoukaku.nodes); const regex = /^https?:\/\//; - let result: any; + let result: LavalinkResponse | undefined; try { result = await node.rest.resolve( regex.test(query) ? query : `${this.client.config.searchEngine}:${query}` diff --git a/src/utils/SetupSystem.ts b/src/utils/SetupSystem.ts index 3caa19b54..cca2df7f1 100644 --- a/src/utils/SetupSystem.ts +++ b/src/utils/SetupSystem.ts @@ -1,10 +1,10 @@ /* eslint-disable no-case-declarations */ import { ColorResolvable, EmbedBuilder, Message, TextChannel } from 'discord.js'; +import { LoadType } from 'shoukaku'; import { getButtons } from './Buttons.js'; import { Song } from '../structures/Dispatcher.js'; import { Dispatcher, Lavamusic } from '../structures/index.js'; -import { LoadType } from 'shoukaku'; function neb(embed: EmbedBuilder, player: Dispatcher, client: Lavamusic): EmbedBuilder { let iconUrl = client.config.icons[player.current.info.sourceName]; @@ -119,7 +119,7 @@ async function setupStart( if (m) await m.edit({ embeds: [n] }).catch(() => { }); break; case LoadType.PLAYLIST: - if (res.length > client.config.maxPlaylistSize) { + if (res.data.tracks.length > client.config.maxPlaylistSize) { await message.channel .send({ embeds: [