Skip to content

Commit

Permalink
Update package version and fix search loop
Browse files Browse the repository at this point in the history
  • Loading branch information
appujet committed Jan 5, 2024
1 parent 8fd3159 commit e04e514
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/music/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/commands/playlist/Add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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,
},
],
Expand Down
10 changes: 6 additions & 4 deletions src/structures/Dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<void> {
Expand Down
6 changes: 3 additions & 3 deletions src/structures/Queue.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -56,10 +56,10 @@ export class Queue extends Map {
}
}

public async search(query: string): Promise<any> {
public async search(query: string): Promise<LavalinkResponse | undefined> {
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}`
Expand Down
4 changes: 2 additions & 2 deletions src/utils/SetupSystem.ts
Original file line number Diff line number Diff line change
@@ -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];
Expand Down Expand Up @@ -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: [
Expand Down

0 comments on commit e04e514

Please sign in to comment.