Skip to content

Commit

Permalink
fix addsong
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasB25 committed Aug 21, 2024
1 parent a55fea5 commit 4acea13
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 156 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"@types/i18n": "^0.13.12",
"@types/node": "^22.4.1",
"@types/node": "^22.4.2",
"@types/signale": "^1.4.7",
"prisma": "^5.18.0",
"typescript": "^5.5.4"
Expand Down
18 changes: 9 additions & 9 deletions src/commands/info/LavaLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ export default class LavaLink extends Command {
embed.addFields({
name: `${node.name} (${statusEmoji})`,
value: `\`\`\`yaml\n${ctx.locale("cmd.lavalink.content", {
players: stats.players,
playingPlayers: stats.playingPlayers,
uptime: client.utils.formatTime(stats.uptime),
cores: stats.cpu.cores,
used: client.utils.formatBytes(stats.memory.used),
reservable: client.utils.formatBytes(stats.memory.reservable),
systemLoad: (stats.cpu.systemLoad * 100).toFixed(2),
lavalinkLoad: (stats.cpu.lavalinkLoad * 100).toFixed(2),
})}\n\`\`\``,
players: stats.players,
playingPlayers: stats.playingPlayers,
uptime: client.utils.formatTime(stats.uptime),
cores: stats.cpu.cores,
used: client.utils.formatBytes(stats.memory.used),
reservable: client.utils.formatBytes(stats.memory.reservable),
systemLoad: (stats.cpu.systemLoad * 100).toFixed(2),
lavalinkLoad: (stats.cpu.lavalinkLoad * 100).toFixed(2),
})}\n\`\`\``,
});
});

Expand Down
121 changes: 53 additions & 68 deletions src/commands/music/Play.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AutocompleteInteraction } from "discord.js";
import { LoadType } from "shoukaku";
import { Command, type Context, type Lavamusic } from "../../structures/index.js";
import type { AutocompleteInteraction } from "discord.js";

export default class Play extends Command {
constructor(client: Lavamusic) {
Expand Down Expand Up @@ -51,18 +51,19 @@ export default class Play extends Command {
let player = client.queue.get(ctx.guild!.id);
const vc = ctx.member as any;
if (!player) player = await client.queue.create(ctx.guild, vc.voice.channel, ctx.channel);

const res = await this.client.queue.search(query);
const embed = this.client.embed();

switch (res.loadType) {
case LoadType.ERROR:
ctx.editMessage({
await ctx.editMessage({
content: "",
embeds: [embed.setColor(this.client.color.red).setDescription(ctx.locale("cmd.play.errors.search_error"))],
});
break;
case LoadType.EMPTY:
ctx.editMessage({
await ctx.editMessage({
content: "",
embeds: [embed.setColor(this.client.color.red).setDescription(ctx.locale("cmd.play.errors.no_results"))],
});
Expand All @@ -73,24 +74,19 @@ export default class Play extends Command {
return await ctx.editMessage({
content: "",
embeds: [
embed.setColor(this.client.color.red).setDescription(
ctx.locale("cmd.play.errors.queue_too_long", {
maxQueueSize: client.config.maxQueueSize,
}),
),
embed
.setColor(this.client.color.red)
.setDescription(ctx.locale("cmd.play.errors.queue_too_long", { maxQueueSize: client.config.maxQueueSize })),
],
});
player.queue.push(track);
await player.isPlaying();
ctx.editMessage({
await ctx.editMessage({
content: "",
embeds: [
embed.setColor(this.client.color.main).setDescription(
ctx.locale("cmd.play.added_to_queue", {
title: res.data.info.title,
uri: res.data.info.uri,
}),
),
embed
.setColor(this.client.color.main)
.setDescription(ctx.locale("cmd.play.added_to_queue", { title: res.data.info.title, uri: res.data.info.uri })),
],
});
break;
Expand All @@ -100,11 +96,11 @@ export default class Play extends Command {
return await ctx.editMessage({
content: "",
embeds: [
embed.setColor(this.client.color.red).setDescription(
ctx.locale("cmd.play.errors.playlist_too_long", {
maxPlaylistSize: client.config.maxPlaylistSize,
}),
),
embed
.setColor(this.client.color.red)
.setDescription(
ctx.locale("cmd.play.errors.playlist_too_long", { maxPlaylistSize: client.config.maxPlaylistSize }),
),
],
});
for (const track of res.data.tracks) {
Expand All @@ -113,24 +109,22 @@ export default class Play extends Command {
return await ctx.editMessage({
content: "",
embeds: [
embed.setColor(this.client.color.red).setDescription(
ctx.locale("cmd.play.errors.queue_too_long", {
maxQueueSize: client.config.maxQueueSize,
}),
),
embed
.setColor(this.client.color.red)
.setDescription(
ctx.locale("cmd.play.errors.queue_too_long", { maxQueueSize: client.config.maxQueueSize }),
),
],
});
player.queue.push(pl);
}
await player.isPlaying();
ctx.editMessage({
await ctx.editMessage({
content: "",
embeds: [
embed.setColor(this.client.color.main).setDescription(
ctx.locale("cmd.play.added_playlist_to_queue", {
length: res.data.tracks.length,
}),
),
embed
.setColor(this.client.color.main)
.setDescription(ctx.locale("cmd.play.added_playlist_to_queue", { length: res.data.tracks.length })),
],
});
break;
Expand All @@ -141,63 +135,54 @@ export default class Play extends Command {
return await ctx.editMessage({
content: "",
embeds: [
embed.setColor(this.client.color.red).setDescription(
ctx.locale("cmd.play.errors.queue_too_long", {
maxQueueSize: client.config.maxQueueSize,
}),
),
embed
.setColor(this.client.color.red)
.setDescription(ctx.locale("cmd.play.errors.queue_too_long", { maxQueueSize: client.config.maxQueueSize })),
],
});
player.queue.push(track1);
await player.isPlaying();
ctx.editMessage({
await ctx.editMessage({
content: "",
embeds: [
embed.setColor(this.client.color.main).setDescription(
ctx.locale("cmd.play.added_to_queue", {
title: res.data[0].info.title,
uri: res.data[0].info.uri,
}),
),
embed
.setColor(this.client.color.main)
.setDescription(
ctx.locale("cmd.play.added_to_queue", { title: res.data[0].info.title, uri: res.data[0].info.uri }),
),
],
});
break;
}
}
}

public async autocomplete(interaction: AutocompleteInteraction): Promise<void> {
const focusedValue = interaction.options.getFocused();

try {
const res = await this.client.queue.search(focusedValue);
const songs = [];
const res = await this.client.queue.search(focusedValue);
const songs = [];

if (res?.loadType) {
if (res.loadType === LoadType.SEARCH && res.data.length) {
res.data.slice(0, 10).forEach((track) => {
const name = `${track.info.title} by ${track.info.author}`;
songs.push({
name: name.length > 100 ? `${name.substring(0, 97)}...` : name,
value: track.info.uri,
});
if (res?.loadType) {
if (res.loadType === LoadType.SEARCH && res.data.length) {
res.data.slice(0, 10).forEach((track) => {
const name = `${track.info.title} by ${track.info.author}`;
songs.push({
name: name.length > 100 ? `${name.substring(0, 97)}...` : name,
value: track.info.uri,
});
} else if (res.loadType === LoadType.PLAYLIST && res.data.tracks.length) {
res.data.tracks.slice(0, 10).forEach((track) => {
const name = `${track.info.title} by ${track.info.author}`;
songs.push({
name: name.length > 100 ? `${name.substring(0, 97)}...` : name,
value: track.info.uri,
});
});
} else if (res.loadType === LoadType.PLAYLIST && res.data.tracks.length) {
res.data.tracks.slice(0, 10).forEach((track) => {
const name = `${track.info.title} by ${track.info.author}`;
songs.push({
name: name.length > 100 ? `${name.substring(0, 97)}...` : name,
value: track.info.uri,
});
}
});
}

await interaction.respond(songs).catch(console.error);
} catch (error) {
console.error("Error during autocomplete interaction:", error);
await interaction.respond([]).catch(console.error);
}

return await interaction.respond(songs).catch(console.error);
}
}

Expand Down
Loading

0 comments on commit 4acea13

Please sign in to comment.