mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-09 06:33:05 -04:00
move audio command to utils
This commit is contained in:
parent
d70a7b4038
commit
10218dce80
1 changed files with 3 additions and 3 deletions
69
commands/message/utils/audio.js
Normal file
69
commands/message/utils/audio.js
Normal file
|
@ -0,0 +1,69 @@
|
|||
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);
|
||||
|
||||
if (!context.message.messageReference) return editOrReply(context, createEmbed("warning", context, "You need to reply to a message containing a song link."))
|
||||
try {
|
||||
let msg;
|
||||
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 (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.`))
|
||||
}
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue