"im sure its fine" ~hazel
This commit is contained in:
parent
a2cf556bcf
commit
2b92d56e28
1 changed files with 50 additions and 23 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { Command } from "../command.ts";
|
import {Command} from "../command.ts";
|
||||||
import {
|
import {
|
||||||
ActionRowBuilder,
|
ActionRowBuilder,
|
||||||
ApplicationIntegrationType,
|
ApplicationIntegrationType,
|
||||||
|
|
@ -10,8 +10,8 @@ import {
|
||||||
SlashCommandBuilder
|
SlashCommandBuilder
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
|
|
||||||
import { getSongOnPreferredProvider } from "../helper.ts"
|
import {getSongOnPreferredProvider} from "../helper.ts"
|
||||||
import { Config } from "../config.ts";
|
import {Config} from "../config.ts";
|
||||||
|
|
||||||
function keepV(url: string): string {
|
function keepV(url: string): string {
|
||||||
const urlObj = new URL(url);
|
const urlObj = new URL(url);
|
||||||
|
|
@ -29,9 +29,9 @@ function keepV(url: string): string {
|
||||||
export default class PingCommand extends Command {
|
export default class PingCommand extends Command {
|
||||||
async run(interaction: ChatInputCommandInteraction, config: Config) {
|
async run(interaction: ChatInputCommandInteraction, config: Config) {
|
||||||
await interaction.deferReply()
|
await interaction.deferReply()
|
||||||
|
const user = interaction.options.getString("user") ?? config.listenbrainzAccount;
|
||||||
|
console.log(`https://api.listenbrainz.org/1/user/${user}/playing-now`);
|
||||||
const meow = await fetch(`https://api.listenbrainz.org/1/user/${config.listenbrainzAccount}/playing-now`).then((res) => res.json());
|
const meow = await fetch(`https://api.listenbrainz.org/1/user/${user}/playing-now`).then((res) => res.json());
|
||||||
if (!meow) {
|
if (!meow) {
|
||||||
await interaction.followUp("something shat itself!");
|
await interaction.followUp("something shat itself!");
|
||||||
return;
|
return;
|
||||||
|
|
@ -40,29 +40,54 @@ export default class PingCommand extends Command {
|
||||||
await interaction.followUp("user isnt listening to music");
|
await interaction.followUp("user isnt listening to music");
|
||||||
} else {
|
} else {
|
||||||
const track_metadata = meow.payload.listens[0].track_metadata
|
const track_metadata = meow.payload.listens[0].track_metadata
|
||||||
const link = keepV(track_metadata.additional_info.origin_url)
|
if (track_metadata.additional_info.origin_url) {
|
||||||
|
const link = keepV(track_metadata.additional_info.origin_url)
|
||||||
|
|
||||||
|
const preferredApi = getSongOnPreferredProvider(await fetch(`https://api.song.link/v1-alpha.1/links?url=${link}`).then(a => a.json()), link)
|
||||||
|
if (preferredApi) {
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setAuthor({
|
||||||
|
name: preferredApi.artist,
|
||||||
|
})
|
||||||
|
.setTitle(preferredApi.title)
|
||||||
|
.setThumbnail(preferredApi.thumbnailUrl)
|
||||||
|
.setFooter({
|
||||||
|
text: "amy jr",
|
||||||
|
});
|
||||||
|
const nya = new ActionRowBuilder<ButtonBuilder>().addComponents(new ButtonBuilder().setURL(preferredApi.link).setLabel("link").setStyle(ButtonStyle.Link))
|
||||||
|
await interaction.followUp({
|
||||||
|
components: [
|
||||||
|
nya
|
||||||
|
],
|
||||||
|
embeds: [embed]
|
||||||
|
});
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const preferredApi = getSongOnPreferredProvider(await fetch(`https://api.song.link/v1-alpha.1/links?url=${link}`).then(a => a.json()), link)
|
|
||||||
if (!preferredApi) {
|
|
||||||
await interaction.followUp("song not found")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
const embed = new EmbedBuilder()
|
let hasURL = false;
|
||||||
.setAuthor({
|
if (track_metadata.additional_info.release_mbid) {
|
||||||
name: preferredApi.artist,
|
const thing = await fetch(`https://coverartarchive.org/release/${track_metadata.additional_info.release_mbid}/front`, {
|
||||||
|
method: "HEAD",
|
||||||
|
redirect: "manual",
|
||||||
})
|
})
|
||||||
.setTitle(preferredApi.title)
|
hasURL = thing.status === 307;
|
||||||
.setThumbnail(preferredApi.thumbnailUrl)
|
}
|
||||||
|
let embed = new EmbedBuilder()
|
||||||
|
.setAuthor({
|
||||||
|
name: track_metadata.artist_name,
|
||||||
|
})
|
||||||
|
.setTitle(track_metadata.track_name)
|
||||||
|
.setDescription("could not get additional info")
|
||||||
.setFooter({
|
.setFooter({
|
||||||
text: "amy jr",
|
text: "amy jr",
|
||||||
});
|
});
|
||||||
const nya = new ActionRowBuilder<ButtonBuilder>().addComponents(new ButtonBuilder().setURL(preferredApi.link).setLabel("link").setStyle(ButtonStyle.Link))
|
if (hasURL) {
|
||||||
|
embed.setThumbnail(`https://aart.yellows.ink/release/${track_metadata.additional_info.release_mbid}.webp`);
|
||||||
|
}
|
||||||
await interaction.followUp({
|
await interaction.followUp({
|
||||||
components: [
|
embeds: [embed],
|
||||||
nya
|
})
|
||||||
],
|
|
||||||
embeds: [embed]
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -71,7 +96,9 @@ export default class PingCommand extends Command {
|
||||||
.setName("nowplaying")
|
.setName("nowplaying")
|
||||||
.setDescription("balls").setIntegrationTypes([
|
.setDescription("balls").setIntegrationTypes([
|
||||||
ApplicationIntegrationType.UserInstall
|
ApplicationIntegrationType.UserInstall
|
||||||
])
|
]).addStringOption(option => {
|
||||||
|
return option.setName("user").setDescription("listenbrainz username").setRequired(false)
|
||||||
|
})
|
||||||
.setContexts([
|
.setContexts([
|
||||||
InteractionContextType.BotDM,
|
InteractionContextType.BotDM,
|
||||||
InteractionContextType.Guild,
|
InteractionContextType.Guild,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue