[cmd] audio

This commit is contained in:
derpystuff 2022-05-25 23:47:58 +02:00
parent 851bd2f75d
commit a68b840af7
2 changed files with 5 additions and 9 deletions

View file

@ -31,16 +31,13 @@ module.exports = {
} catch(e){ } catch(e){
return editOrReply(context, {embeds:[createEmbed("error", context, "Unable to fetch message.")]}) return editOrReply(context, {embeds:[createEmbed("error", context, "Unable to fetch message.")]})
} }
console.log(msg)
let urls = msg.content.match(urlr) let urls = msg.content.match(urlr)
console.log(urls)
if(urls){ if(urls){
try{ try{
let songlink = await superagent.get(`https://api.song.link/v1-alpha.1/links?url=${encodeURIComponent(urls[0])}`) let songlink = await superagent.get(`https://api.song.link/v1-alpha.1/links?url=${encodeURIComponent(urls[0])}`)
let song = songlink.body.entitiesByUniqueId[songlink.body.entityUniqueId] let song = songlink.body.entitiesByUniqueId[songlink.body.entityUniqueId]
let btns = renderMusicButtons(songlink.body.linksByPlatform) let btns = renderMusicButtons(songlink.body.linksByPlatform)
console.log(JSON.stringify(btns, null, 2))
return editOrReply(context, {embeds:[ return editOrReply(context, {embeds:[
createEmbed("default", context, { createEmbed("default", context, {
author: { author: {
@ -51,9 +48,7 @@ module.exports = {
footer: {} footer: {}
}) })
], components: btns}) ], components: btns})
}catch(e){ }catch(e){} //ignore it and run the audio detection flow
console.log(e)
} //ignore it and run the audio detection flow
} }
} }
@ -62,7 +57,6 @@ module.exports = {
if(!audios.length) return editOrReply(context, {embeds:[createEmbed("warning", context, `Could not find supported video.`)]}) if(!audios.length) return editOrReply(context, {embeds:[createEmbed("warning", context, `Could not find supported video.`)]})
let audioSearch = await searchAudio(context, audios[0].url) let audioSearch = await searchAudio(context, audios[0].url)
search = audioSearch.response search = audioSearch.response
console.log(audioSearch.response.body)
if(audioSearch.response.body.status == 0){ if(audioSearch.response.body.status == 0){
// API lowkey sucks, fetch more metadata via songlink // API lowkey sucks, fetch more metadata via songlink
let url = audioSearch.response.body.media[Object.keys(audioSearch.response.body.media)[0]] let url = audioSearch.response.body.media[Object.keys(audioSearch.response.body.media)[0]]
@ -73,7 +67,6 @@ module.exports = {
let song = songlink.body.entitiesByUniqueId[songlink.body.entityUniqueId] let song = songlink.body.entitiesByUniqueId[songlink.body.entityUniqueId]
let btns = renderMusicButtons(songlink.body.linksByPlatform) let btns = renderMusicButtons(songlink.body.linksByPlatform)
console.log(JSON.stringify(btns, null, 2))
return editOrReply(context, {embeds:[ return editOrReply(context, {embeds:[
createEmbed("default", context, { createEmbed("default", context, {
author: { author: {
@ -87,10 +80,10 @@ module.exports = {
} }
}catch(e){ }catch(e){
console.log(e)
if(e.response?.body?.status){ if(e.response?.body?.status){
return editOrReply(context, {embeds:[createEmbed("error", context, e.response.body.message)]}) return editOrReply(context, {embeds:[createEmbed("error", context, e.response.body.message)]})
} }
console.log(e)
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform audio search.`)]}) return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform audio search.`)]})
} }
}, },

View file

@ -75,6 +75,9 @@ async function getRecentVideo(context, limit) {
message.embeds.toArray()[0].video message.embeds.toArray()[0].video
) { ) {
attachments.push(message.embeds.toArray()[0].video) attachments.push(message.embeds.toArray()[0].video)
} else if (message.attachments.first() &&
message.attachments.first().contentType.includes("video")){
attachments.push(message.attachments.first())
} }
} }
return attachments; return attachments;