mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-02 22:16:13 +00:00
3 files changed
+30
-4
No files matched your search
@@ -126,7 +126,7 @@ module.exports = {
|
||||
inline: true
|
||||
},
|
||||
{
|
||||
name: '**Audio source**',
|
||||
name: '**Track source**',
|
||||
value: `**${sourceIcons.get(currentTrack.raw.source)} [${source}](${currentTrack.url})**`,
|
||||
inline: true
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const { embedOptions, playerOptions, botOptions } = require('../../config');
|
||||
const { notInVoiceChannel } = require('../../utils/validation/voiceChannelValidation');
|
||||
const { transformQuery } = require('../../utils/validation/searchQueryValidation');
|
||||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||
const { useMainPlayer, useQueue } = require('discord-player');
|
||||
|
||||
@@ -17,7 +18,9 @@ module.exports = {
|
||||
const player = useMainPlayer();
|
||||
const query = interaction.options.getString('query');
|
||||
|
||||
const searchResult = await player.search(query, {
|
||||
const transformedQuery = await transformQuery(query);
|
||||
|
||||
const searchResult = await player.search(transformedQuery, {
|
||||
requestedBy: interaction.user
|
||||
});
|
||||
|
||||
@@ -26,7 +29,7 @@ module.exports = {
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(
|
||||
`**${embedOptions.icons.warning} No track found**\nNo results found for \`${query}\`.\n\nIf you specified a URL, please make sure it is valid and public.`
|
||||
`**${embedOptions.icons.warning} No track found**\nNo results found for \`${transformedQuery}\`.\n\nIf you specified a URL, please make sure it is valid and public.`
|
||||
)
|
||||
.setColor(embedOptions.colors.warning)
|
||||
]
|
||||
@@ -151,7 +154,7 @@ module.exports = {
|
||||
});
|
||||
}
|
||||
|
||||
if (queue.currentTrack === track) {
|
||||
if (queue.currentTrack === track && queue.tracks.data.length === 0) {
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
const logger = require('../../services/logger');
|
||||
|
||||
exports.transformQuery = async (query) => {
|
||||
if (query.includes('open.spotify.com')) {
|
||||
try {
|
||||
// regex to check for country-based Spotify url
|
||||
const regex = new RegExp(
|
||||
'https://open.spotify.com/((?:[a-z]{2,4}-[a-z]{2,4}/)|(?:[a-z]{2,4}/))?track/([a-zA-Z0-9]+)'
|
||||
);
|
||||
const isCountryBased = regex.test(query);
|
||||
|
||||
// if country-based, transform to normal Spotify url
|
||||
if (isCountryBased) {
|
||||
const trackId = query.match(regex)[2];
|
||||
query = `https://open.spotify.com/track/${trackId}`;
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
return query;
|
||||
};
|
||||
Reference in new issue
Block a user