of fucking course its oop again

This commit is contained in:
amy 2025-02-19 15:59:18 +03:30
parent 6359da85ea
commit 6ea0e02ee8
No known key found for this signature in database
4 changed files with 134 additions and 52 deletions

View file

@ -0,0 +1,79 @@
import { Command } from "../command.ts";
import {
ActionRowBuilder,
ApplicationIntegrationType,
ButtonBuilder,
ButtonStyle,
ChatInputCommandInteraction,
EmbedBuilder,
InteractionContextType,
SlashCommandBuilder
} from "discord.js";
import { getSongOnPreferredProvider } from "../helper.ts"
function keepV(url) {
const urlObj = new URL(url);
const vParam = urlObj.searchParams.get("v");
urlObj.search = "";
if (vParam) {
urlObj.searchParams.set("v", vParam);
}
return urlObj.toString();
}
export default class PingCommand extends Command {
async run(interaction: ChatInputCommandInteraction, config) {
await interaction.deferReply()
const meow = await fetch(`https://api.listenbrainz.org/1/user/${config.listenbrainzAccount}/playing-now`).then((res) => res.json());
if (!meow) {
await interaction.followUp("something shat itself!");
return;
}
if (meow.payload.count === 0) {
await interaction.followUp("user isnt listening to music");
} else {
const track_metadata = meow.payload.listens[0].track_metadata
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) {
interaction.followUp("song not found")
return
}
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))
interaction.followUp({
components: [
nya
],
embeds: [embed]
});
}
}
slashCommand = new SlashCommandBuilder()
.setName("nowplaying")
.setDescription("balls").setIntegrationTypes([
ApplicationIntegrationType.UserInstall
])
.setContexts([
InteractionContextType.BotDM,
InteractionContextType.Guild,
InteractionContextType.PrivateChannel
]);
}

26
src/commands/ping.ts Normal file
View file

@ -0,0 +1,26 @@
import {Command} from "../command.ts";
import {
ApplicationIntegrationType,
ChatInputCommandInteraction,
InteractionContextType,
SlashCommandBuilder
} from "discord.js";
export default class PingCommand extends Command {
async run(interaction: ChatInputCommandInteraction, config) {
await interaction.reply({
content: 'Pong!',
});
}
slashCommand = new SlashCommandBuilder()
.setName("ping")
.setDescription("Pong!").setIntegrationTypes([
ApplicationIntegrationType.UserInstall
])
.setContexts([
InteractionContextType.BotDM,
InteractionContextType.Guild,
InteractionContextType.PrivateChannel
]);
}