mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-07 13:43:06 -04:00
73 lines
No EOL
2.9 KiB
JavaScript
73 lines
No EOL
2.9 KiB
JavaScript
const { PERMISSION_GROUPS } = require('#constants');
|
|
const { renderMusicButtons } = require('#utils/buttons');
|
|
const { createEmbed } = require('#utils/embed');
|
|
const { acknowledge } = require('#utils/interactions');
|
|
const { icon } = require('#utils/markdown');
|
|
const { editOrReply } = require('#utils/message')
|
|
|
|
const superagent = require('superagent')
|
|
|
|
// TODO: make this a constant, or add a URL util
|
|
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: 'audio',
|
|
aliases: ['aud'],
|
|
metadata: {
|
|
description: `${icon("reply")} __Replying__ to a message while using this command will return a list of music streaming platforms the provided song (link) is available on.`,
|
|
description_short: 'Cross-platform music resolver',
|
|
category: 'utils',
|
|
usage: 'audio',
|
|
slashCommand: "Music Platforms"
|
|
},
|
|
permissionsClient: [...PERMISSION_GROUPS.baseline],
|
|
run: async (context) => {
|
|
await acknowledge(context);
|
|
|
|
try {
|
|
let msg;
|
|
if (!context.message.messageReference) msg = context.message;
|
|
else {
|
|
try {
|
|
msg = await context.message.channel.fetchMessage(context.message.messageReference.messageId)
|
|
} catch (e) {
|
|
return editOrReply(context, createEmbed("error", context, "Unable to fetch message."))
|
|
}
|
|
}
|
|
|
|
let urls = msg.content.match(urlr)
|
|
if(msg.messageSnapshots?.length >= 1) urls = msg.messageSnapshots.first().message.content.match(urlr);
|
|
if (urls) {
|
|
let songlink = await superagent.get(`https://api.song.link/v1-alpha.1/links`)
|
|
.query({
|
|
url: urls[0],
|
|
key: process.env.SONGLINK_KEY
|
|
})
|
|
let song = songlink.body.entitiesByUniqueId[songlink.body.entityUniqueId]
|
|
|
|
// YT Playlist thumbnails don't work properly
|
|
if(songlink.body.entityUniqueId.startsWith("YOUTUBE_PLAYLIST") && Object.keys(songlink.body.entitiesByUniqueId).length >= 2){
|
|
song.thumbnailUrl = songlink.body.entitiesByUniqueId[Object.keys(songlink.body.entitiesByUniqueId).filter((k)=>!k.startsWith("YOUTUBE_PLAYLIST"))[0]].thumbnailUrl
|
|
}
|
|
|
|
let btns = renderMusicButtons(songlink.body.linksByPlatform)
|
|
return editOrReply(context, {
|
|
embeds: [
|
|
createEmbed("defaultNoFooter", context, {
|
|
author: {
|
|
name: `${song.title} by ${song.artistName}`.substr(0, 1000),
|
|
iconUrl: song.thumbnailUrl,
|
|
url: urls[0]
|
|
}
|
|
})
|
|
], components: btns
|
|
})
|
|
} else {
|
|
return editOrReply(context, createEmbed("warning", context, "No urls found."))
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
return editOrReply(context, createEmbed("warning", context, `No results found.`))
|
|
}
|
|
},
|
|
}; |