mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-13 08:33:02 -04:00
add /music-platforms
This commit is contained in:
parent
f99efdf813
commit
8642d88ebb
1 changed files with 72 additions and 0 deletions
72
commands/interaction/slash/utils/music-platforms.js
Normal file
72
commands/interaction/slash/utils/music-platforms.js
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
const { renderMusicButtons } = require('#utils/buttons');
|
||||||
|
const { createEmbed } = require('#utils/embed');
|
||||||
|
const { acknowledge } = require('#utils/interactions');
|
||||||
|
const { editOrReply } = require('#utils/message');
|
||||||
|
|
||||||
|
const { ApplicationCommandOptionTypes } = require("detritus-client/lib/constants");;
|
||||||
|
|
||||||
|
const superagent = require('superagent')
|
||||||
|
|
||||||
|
const urlr = /(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})/g
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'music-platforms',
|
||||||
|
description: 'Get links for a song across all streaming platforms.',
|
||||||
|
contexts: [
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
2
|
||||||
|
],
|
||||||
|
integrationTypes: [
|
||||||
|
1
|
||||||
|
],
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'url',
|
||||||
|
description: 'Song URL.',
|
||||||
|
type: ApplicationCommandOptionTypes.TEXT,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'incognito',
|
||||||
|
description: 'Makes the response only visible to you.',
|
||||||
|
type: ApplicationCommandOptionTypes.BOOLEAN,
|
||||||
|
required: false,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
run: async (context, args) => {
|
||||||
|
try{
|
||||||
|
await acknowledge(context, args.incognito);
|
||||||
|
|
||||||
|
let urls = args.url.match(urlr)
|
||||||
|
if(urls){
|
||||||
|
try{
|
||||||
|
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 btns = renderMusicButtons(songlink.body.linksByPlatform)
|
||||||
|
return editOrReply(context, {embeds:[
|
||||||
|
createEmbed("default", context, {
|
||||||
|
author: {
|
||||||
|
name: `${song.title} by ${song.artistName}`.substr(0,1000),
|
||||||
|
iconUrl: song.thumbnailUrl,
|
||||||
|
url: urls[0]
|
||||||
|
},
|
||||||
|
footer: {
|
||||||
|
text: `powered by song.link • ${context.application.name}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
], components: btns })
|
||||||
|
}catch(e){
|
||||||
|
return editOrReply(context, createEmbed("warning", context, "No results found."))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return editOrReply(context, createEmbed("warning", context, "No urls found."))
|
||||||
|
}
|
||||||
|
}catch(e){
|
||||||
|
console.log(e)
|
||||||
|
await editOrReply(context, createEmbed("error", context, "Unable to look up song url."))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
Loading…
Add table
Add a link
Reference in a new issue