From e31beefa859cd988db1600408d8934cbb9890ce3 Mon Sep 17 00:00:00 2001 From: amy Date: Wed, 26 Feb 2025 23:21:01 +0330 Subject: [PATCH] "I'm unsure it's not fine" ~xirreal --- src/commands/songinfo.ts | 72 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/commands/songinfo.ts diff --git a/src/commands/songinfo.ts b/src/commands/songinfo.ts new file mode 100644 index 0000000..de62c95 --- /dev/null +++ b/src/commands/songinfo.ts @@ -0,0 +1,72 @@ +import {Command} from "../command.ts"; +import { + ActionRowBuilder, + ApplicationIntegrationType, ButtonBuilder, ButtonStyle, + ChatInputCommandInteraction, EmbedBuilder, + InteractionContextType, + SlashCommandBuilder +} from "discord.js"; +import { Config } from "../config.ts"; +import {getSongOnPreferredProvider} from "../helper.ts"; + +export default class MusicInfoCommand extends Command { + async run(interaction: ChatInputCommandInteraction, config: Config) { + await interaction.deferReply() + const link = interaction.options.getString("link")! + const info = await fetch("https://api.song.link/v1-alpha.1/links?url=" + link).then((res) => res.json()); + + //const meow = [...new Set(Object.values(info.linksByPlatform).map((i:any) => i.entityUniqueId))] + const meow = Object.keys(info.linksByPlatform) + let message = "" + + const nya: ActionRowBuilder[] = []; + let currentRow = new ActionRowBuilder(); + + for (const meowi of meow) { + if (currentRow.components.length >= 5) { + nya.push(currentRow); + currentRow = new ActionRowBuilder(); + } + currentRow.addComponents( + new ButtonBuilder() + .setURL(info.linksByPlatform[meowi].url) + .setLabel(meowi) + .setStyle(ButtonStyle.Link) + ); + } + if (currentRow.components.length > 0) { + nya.push(currentRow); + } + + const infoPreferred = getSongOnPreferredProvider(info, link)! + const mrrrr = new EmbedBuilder() + .setAuthor({ + name: infoPreferred.artist, + }) + .setTitle(infoPreferred.title) + .setThumbnail(infoPreferred.thumbnailUrl) + .setFooter({ + text: "amy jr", + }); + await interaction.followUp({ + embeds: [mrrrr], + components: nya + }); + + } + + slashCommand = new SlashCommandBuilder() + .setName("musicinfo") + .addStringOption(option =>{ + return option.setName("link").setDescription("link").setRequired(true); + }) + .setDescription("meow") + .setIntegrationTypes([ + ApplicationIntegrationType.UserInstall + ]) + .setContexts([ + InteractionContextType.BotDM, + InteractionContextType.Guild, + InteractionContextType.PrivateChannel + ]); +}