mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-02 22:16:13 +00:00
24 lines
765 B
JavaScript
24 lines
765 B
JavaScript
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;
|
|
};
|