mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-02 14:38:49 +00:00
feat: Renamed validator files and added permission validator
This commit is contained in:
1 parent
f04937eee0
commit
b68b7dac95
18 files changed
+51
-22
No files matched your search
@@ -0,0 +1,24 @@
|
||||
const logger = require('../../services/logger');
|
||||
|
||||
exports.transformQuery = async (query) => {
|
||||
if (query.startsWith('https://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) {
|
||||
logger.debug(`Transforming country-based Spotify url to normal Spotify url from query ${query}.`);
|
||||
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