From 57c9f7ce45b40badeb13ed1e57a99b52cb8465f7 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sat, 6 Sep 2025 17:00:32 -0700 Subject: feat: Add NSFW command --- src/server.js | 92 ++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 72 insertions(+), 20 deletions(-) (limited to 'src/server.js') diff --git a/src/server.js b/src/server.js index b505f31..5695344 100644 --- a/src/server.js +++ b/src/server.js @@ -4,8 +4,8 @@ import { InteractionType, verifyKey, } from 'discord-interactions'; -import { HOT_COMMAND, ROLEPLAY_COMMAND } from './commands.js'; -import { getCutePost, getRoleplayPost } from './reddit.js'; +import { HOT_COMMAND, ROLEPLAY_COMMAND, NSFW_COMMAND } from './commands.js'; +import { getCutePost, getRoleplayPost, getNSFWPost } from './reddit.js'; class JSONResponse extends Response { constructor(body, init) { @@ -90,27 +90,79 @@ router.post('/', async (request, environment) => { if (interaction.type === InteractionType.APPLICATION_COMMAND) { switch (interaction.data.name.toLowerCase()) { case HOT_COMMAND.name.toLowerCase(): { - const post = await getCutePost(); - const embed = createPostEmbed(post); - - return new JSONResponse({ - type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, - data: { - embeds: [embed], - }, - }); + try { + const post = await getCutePost(); + const embed = createPostEmbed(post); + + return new JSONResponse({ + type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, + data: { + embeds: [embed], + }, + }); + } catch { + return new JSONResponse({ + type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, + data: { + content: '❌ No posts found. Try again later!', + flags: 64, + }, + }); + } } case ROLEPLAY_COMMAND.name.toLowerCase(): { - const post = await getRoleplayPost(); - const embed = createPostEmbed(post); - - return new JSONResponse({ - type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, - data: { - embeds: [embed], - }, - }); + try { + const post = await getRoleplayPost(); + const embed = createPostEmbed(post); + + return new JSONResponse({ + type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, + data: { + embeds: [embed], + }, + }); + } catch { + return new JSONResponse({ + type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, + data: { + content: '❌ No roleplay posts found. Try again later!', + flags: 64, + }, + }); + } + } + + case NSFW_COMMAND.name.toLowerCase(): { + if (!interaction.channel_id || !interaction.channel?.nsfw) { + return new JSONResponse({ + type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, + data: { + content: '❌ This command can only be used in NSFW channels.', + flags: 64, + }, + }); + } + + try { + const post = await getNSFWPost(); + const embed = createPostEmbed(post); + + return new JSONResponse({ + type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, + data: { + embeds: [embed], + }, + }); + } catch { + return new JSONResponse({ + type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, + data: { + content: '❌ No NSFW posts found. Try again later!', + flags: 64, + }, + }); + } } default: -- cgit v1.2.3