diff --git a/src/commands/radio.ts b/src/commands/radio.ts new file mode 100644 index 0000000..aea9317 --- /dev/null +++ b/src/commands/radio.ts @@ -0,0 +1,62 @@ +import { Command } from "../command.ts"; +import { + ActionRowBuilder, + ApplicationIntegrationType, + ButtonBuilder, + ButtonStyle, + ChatInputCommandInteraction, + ContainerBuilder, + InteractionContextType, + MessageFlags, + SectionBuilder, + SlashCommandBuilder, + TextDisplayBuilder, + ThumbnailBuilder, + type MessageActionRowComponentBuilder +} from "discord.js"; +import { type Config } from "../config.ts"; + +export default class RadioCommand extends Command { + async run(interaction: ChatInputCommandInteraction, config: Config) { + await interaction.deferReply() + const nowplaying = (await (await fetch(`${config.radioURL}/api/nowplaying/${config.radioName}`)).json()).now_playing.song + const components = [ + new ContainerBuilder() + .addSectionComponents( + new SectionBuilder() + .setThumbnailAccessory( + new ThumbnailBuilder() + .setURL(nowplaying.art) + ) + .addTextDisplayComponents( + new TextDisplayBuilder().setContent("# " + nowplaying.title), + ), + ) + .addActionRowComponents( + new ActionRowBuilder() + .addComponents( + new ButtonBuilder() + .setStyle(ButtonStyle.Link) + .setLabel("join the radio") + .setURL(`${config.radioURL}/public/${config.radioName}`), + ), + ), +]; + + await interaction.followUp({ + components: components, + flags: [MessageFlags.IsComponentsV2], + }) + } + + slashCommand = new SlashCommandBuilder() + .setName("radio") + .setDescription("see whats playing on the radio").setIntegrationTypes([ + ApplicationIntegrationType.UserInstall + ]) + .setContexts([ + InteractionContextType.BotDM, + InteractionContextType.Guild, + InteractionContextType.PrivateChannel + ]); +} diff --git a/src/config.ts b/src/config.ts index 2745b51..50dfb67 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,14 +1,12 @@ import rawconfig from "../config.json" with {type: "json"}; import {z} from 'zod'; -import type {S3Client} from "@aws-sdk/client-s3"; const configT = z.object({ token: z.string(), listenbrainzAccount: z.string(), gitapi: z.string(), sharkeyInstance:z.string(), - R2AccountID: z.string(), - R2AccessKeyId: z.string(), - R2SecretAccessKey: z.string(), + radioURL: z.string(), + radioName: z.string() }); export type Config = z.infer; export const config: Config = configT.parse(rawconfig);