Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (opts.parameters.length < 1 || !this.songrequest) {
if (this.songrequest) {
sendMessage(translate('core.usage') + ': !songrequest ', opts.sender, opts.attr);
} else {
sendMessage('$sender, ' + translate('core.settings.songs.songrequest.false'), opts.sender, opts.attr);
}
return;
}
const urlRegex = /^.*(?:youtu.be\/|v\/|e\/|u\/\w+\/|embed\/|v=)([^#&?]*).*/;
const idRegex = /^[a-zA-Z0-9-_]{11}$/;
const match = opts.parameters.match(urlRegex);
const videoID = (match && match[1].length === 11) ? match[1] : opts.parameters;
if (_.isNil(videoID.match(idRegex))) { // not id or url
ytsearch(opts.parameters, { maxResults: 1, key: 'AIzaSyDYevtuLOxbyqBjh17JNZNvSQO854sngK0' }, (err, results) => {
if (err) {
return error(err);
}
if (typeof results !== 'undefined' && results[0].id) {
opts.parameters = results[0].id;
this.addSongToQueue(opts);
}
});
return;
}
// is song banned?
const ban = await getRepository(SongBan).findOne({ videoId: videoID });
if (ban) {
sendMessage(translate('songs.song-is-banned'), opts.sender, opts.attr);
return;