google blocked my IP lmao

This commit is contained in:
Emily 2020-04-15 15:43:31 +10:00
parent bb5b7edbb4
commit 6487f20b70

View file

@ -51,18 +51,18 @@ module.exports = client => {
return 'https://www.youtube.com/watch?v=' + id return 'https://www.youtube.com/watch?v=' + id
} }
client.music.getVideoByQuery = async function (query) { client.music.getVideoByQuery = async query => {
let response let resp
if (ytdl.validateURL(query)) { try {
const id = await await ytdl.getURLVideoID(query) const id = await ytdl.getURLVideoID(query)
response = await fetch('https://invidio.us/api/v1/videos/' + id) resp = await fetch('https://invidio.us/api/v1/videos/' + id)
} else { console.log(resp)
// TODO: replace this workaround } catch (err) {
response = await fetch('https://invidio.us/api/v1/search?q=' + encodeURIComponent(query) + '**') resp = await fetch('https://invidio.us/api/v1/search?q=' + encodeURIComponent(query))
} }
const parsed = await response.json() const parsed = await resp.json()
if (parsed) { if (parsed) {
const videos = parsed const videos = parsed
@ -91,6 +91,13 @@ module.exports = client => {
if (!ignoreQueue) { if (!ignoreQueue) {
videos = await client.music.getVideoByQuery(query) videos = await client.music.getVideoByQuery(query)
if (!videos[1]) {
if (!videos[0]) {
video = videos
} else {
video = videos[0]
}
}
} }
if (videos || ignoreQueue) { if (videos || ignoreQueue) {
@ -105,7 +112,7 @@ module.exports = client => {
guild.queue = [] guild.queue = []
} }
if (videos[1]) { if (!video) {
let output = '' let output = ''
let i = 0 let i = 0
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
@ -118,26 +125,21 @@ module.exports = client => {
embed.setColor(client.embedColour(message.guild)) embed.setColor(client.embedColour(message.guild))
embed.setDescription(output) embed.setDescription(output)
const selection = await client.awaitReply(message, embed) const selection = await client.awaitReply(message, embed)
console.log(selection)
for (i = 0; i < 4; i++) { switch (selection) {
if ([`${i + 1}`].includes(selection)) {
if (!videos[i]) {
return message.channel.send('Invalid selection')
}
video = videos[i]
break
}
} }
} }
if (!video && videos[0]) { if (!video && videos[0]) {
video = videos[0] video = videos[0]
} else if(!video) { } else if (!video) {
video = videos video = videos
} }
console.log(video)
// Add video to queue // Add video to queue
guild.queue.push({ video: video, requestedBy: message.member.id }) guild.queue.push({ video: video, requestedBy: message.member.id })
} }