Skip to content

Commit

Permalink
fix playlist autocomplete (#159)
Browse files Browse the repository at this point in the history
## Please describe the changes this PR makes and why it should be
merged:

## Status and versioning classification:
- Code changes have been tested against the Discord API, or there are no
code changes
- I know how to update typings and have done so, or typings don't need
updating
  • Loading branch information
brianferri authored Oct 27, 2023
2 parents a30a5cc + e5fc672 commit c8a0ae6
Show file tree
Hide file tree
Showing 7 changed files with 416 additions and 298 deletions.
24 changes: 24 additions & 0 deletions djs-bot/.vimspector.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"configurations": {
"Launch": {
"adapter": "js-debug",
"configuration": {
"request": "launch",
"program": "${workspaceRoot}/index.js",
"cwd": "${workspaceRoot}",
"externalConsole": true,
"type": "pwa-node"
}
},
"Attach": {
"adapter": "js-debug",
"configuration": {
"request": "attach",
"program": "${workspaceRoot}/index.js",
"cwd": "${workspaceRoot}",
"externalConsole": true,
"type": "pwa-node"
}
}
}
}
60 changes: 24 additions & 36 deletions djs-bot/commands/music/play.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const SlashCommand = require("../../lib/SlashCommand");
const { EmbedBuilder } = require("discord.js");
const { joinStageChannelRoutine, addTrack } = require("../../util/player");
const { addQueueEmbed, loadedPlaylistEmbed } = require("../../util/embeds");
const { addQueueEmbed, loadedPlaylistEmbed, redEmbed } = require("../../util/embeds");
const yt = require("youtube-sr").default;

async function testUrlRegex(string) {
Expand Down Expand Up @@ -89,43 +89,39 @@ const command = new SlashCommand()
});

let query = options.getString("query", true);
let res = await player.search(query, interaction.user).catch((err) => {
const res = await player.search(query, interaction.user).catch((err) => {
client.error(err);
return {
loadType: "LOAD_FAILED",
};
});

const editReplyEmbed = async (embed) => {
return interaction
.editReply({
embeds: [embed],
})
.catch(client.warn);
};

if (res.loadType === "LOAD_FAILED") {
if (!player.queue.current) {
player.destroy();
}
await interaction
.editReply({
embeds: [
new EmbedBuilder()
.setColor("Red")
.setDescription(
"There was an error while searching"
),
],

await editReplyEmbed(
redEmbed({
desc: "There was an error while searching",
})
.catch(client.warn);
);
}

if (res.loadType === "NO_MATCHES") {
if (!player.queue.current) {
player.destroy();
}
await interaction
.editReply({
embeds: [
new EmbedBuilder()
.setColor("Red")
.setDescription("No results were found"),
],
})
.catch(client.warn);

await editReplyEmbed(redEmbed({ desc: "No results were found" }));
}

if (res.loadType === "TRACK_LOADED" || res.loadType === "SEARCH_RESULT") {
Expand All @@ -138,17 +134,13 @@ const command = new SlashCommand()
if (player.queue.totalSize <= 1)
player.queue.previous = player.queue.current;

await interaction
.editReply({
embeds: [
addQueueEmbed({
track: res.tracks[0],
player,
requesterId: interaction.user.id,
}),
],
await editReplyEmbed(
addQueueEmbed({
track: res.tracks[0],
player,
requesterId: interaction.user.id,
})
.catch(client.warn);
);
}

if (res.loadType === "PLAYLIST_LOADED") {
Expand All @@ -162,11 +154,7 @@ const command = new SlashCommand()
player.play();
}

await interaction
.editReply({
embeds: [loadedPlaylistEmbed({ searchResult: res, query })],
})
.catch(client.warn);
await editReplyEmbed(loadedPlaylistEmbed({ searchResult: res, query }));
}

if (ret) setTimeout(() => ret.delete().catch(client.warn), 20000);
Expand Down
Loading

0 comments on commit c8a0ae6

Please sign in to comment.