2020-12-02 11:21:39 +05:00
|
|
|
const ytsr = require('youtube-sr')
|
2020-08-14 17:57:32 +05:00
|
|
|
const soundcloud = require('soundcloud-scraper')
|
2020-08-13 18:21:42 +05:00
|
|
|
const Discord = require('discord.js')
|
|
|
|
|
2020-11-24 01:17:09 +05:00
|
|
|
const youtubeVideoRegex = (/(?:youtube\.com\/(?:[^/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?/\s]{11})/)
|
2020-08-13 18:21:42 +05:00
|
|
|
const spotifySongRegex = (/https?:\/\/(?:embed\.|open\.)(?:spotify\.com\/)(?:track\/|\?uri=spotify:track:)((\w|-){22})/)
|
|
|
|
|
|
|
|
module.exports = class Util {
|
|
|
|
constructor () {
|
|
|
|
throw new Error(`The ${this.constructor.name} class may not be instantiated.`)
|
|
|
|
}
|
|
|
|
|
2020-08-14 02:07:54 +05:00
|
|
|
static isVoiceEmpty (channel) {
|
|
|
|
return channel.members.filter((member) => !member.user.bot).size === 0
|
|
|
|
}
|
|
|
|
|
2020-08-14 17:47:49 +05:00
|
|
|
static isSoundcloudLink (query) {
|
2020-08-14 17:57:32 +05:00
|
|
|
return soundcloud.validateURL(query)
|
2020-08-14 17:47:49 +05:00
|
|
|
}
|
|
|
|
|
2020-08-13 18:21:42 +05:00
|
|
|
static isSpotifyLink (query) {
|
|
|
|
return spotifySongRegex.test(query)
|
|
|
|
}
|
|
|
|
|
|
|
|
static isYTPlaylistLink (query) {
|
2020-12-27 02:39:39 +05:00
|
|
|
return ytsr.default.validate(query, 'PLAYLIST')
|
2020-08-13 18:21:42 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
static isYTVideoLink (query) {
|
|
|
|
return youtubeVideoRegex.test(query)
|
|
|
|
}
|
|
|
|
}
|