diff options
| author | Fuwn <[email protected]> | 2025-10-01 20:37:00 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-10-01 20:37:00 -0700 |
| commit | fceda4e9330984d9b62465e7d00c27c6ac36e8b3 (patch) | |
| tree | 1b64a71c7561b5955149212a559b7abd1d486bd9 /packages/interactions/server.ts | |
| parent | feat(interactions): Add age-verify command (diff) | |
| download | umabotdiscord-fceda4e9330984d9b62465e7d00c27c6ac36e8b3.tar.xz umabotdiscord-fceda4e9330984d9b62465e7d00c27c6ac36e8b3.zip | |
feat(interactions): Add nsfw-apply command
Diffstat (limited to 'packages/interactions/server.ts')
| -rw-r--r-- | packages/interactions/server.ts | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/packages/interactions/server.ts b/packages/interactions/server.ts index 3a9651e..29245b6 100644 --- a/packages/interactions/server.ts +++ b/packages/interactions/server.ts @@ -7,6 +7,7 @@ import { TOP_COMMAND, COMPLAIN_COMMAND, APPEAL_COMMAND, + NSFW_APPLY_COMMAND, COLOURS_COMMAND, ROLEPLAY_VERIFY_COMMAND, AGE_VERIFY_COMMAND, @@ -23,6 +24,7 @@ import { createPostEmbed, createComplaintEmbed, createAppealEmbed, + createNSFWApplicationEmbed, createRoleDistributionEmbed, } from "./discord/embeds.ts"; import { JSONResponse } from "./discord/responses.ts"; @@ -32,6 +34,7 @@ import { GUILD_ID, COLOR_ROLE_IDS } from "../shared"; const router = AutoRouter(); const COMPLAINT_CHANNEL_ID = "1415868433714778204"; const APPEAL_CHANNEL_ID = "1420340807931531385"; +const NSFW_APPLY_CHANNEL_ID = "1423148301221625926"; const VERIFIED_ROLEPLAY_ROLE_ID = "1418311833303122021"; const ROLE_MANAGER_ROLE_ID = "1410993207608873070"; const ART_MEDIA_ROLE_ID = "1410333831281643630"; @@ -67,6 +70,32 @@ const sendComplaintToChannel = async ( } }; +const sendNSFWApplicationToChannel = async ( + environment: Environment, + embed: DiscordEmbed, +): Promise<boolean> => { + const url = `https://discord.com/api/v10/channels/${NSFW_APPLY_CHANNEL_ID}/messages`; + + try { + const response = await fetch(url, { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bot ${environment.DISCORD_TOKEN}`, + }, + body: JSON.stringify({ + embeds: [embed], + }), + }); + + return response.ok; + } catch (error) { + console.error("Error sending NSFW application to channel:", error); + + return false; + } +}; + const sendAppealToChannel = async ( environment: Environment, embed: DiscordEmbed, @@ -487,6 +516,70 @@ router.post("/", async (request: Request, environment: Environment) => { } } + case NSFW_APPLY_COMMAND.name.toLowerCase(): { + try { + const applicationMessage = interaction.data.options?.[0]?.value as string; + + if (!applicationMessage) + return new JSONResponse({ + type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, + data: { + content: "❌ Please provide a message for your NSFW access application.", + flags: 64, + }, + }); + + const applicant = { + username: + interaction.member?.user?.username || + interaction.user?.username || + "Unknown", + id: + interaction.member?.user?.id || interaction.user?.id || "Unknown", + avatar: + interaction.member?.user?.avatar || interaction.user?.avatar, + }; + const isDM = !interaction.guild_id; + const applicationEmbed = createNSFWApplicationEmbed( + applicationMessage, + applicant, + Date.now(), + isDM, + ); + const success = await sendNSFWApplicationToChannel(environment, applicationEmbed); + + if (success) { + return new JSONResponse({ + type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, + data: { + content: + "✅ Your NSFW access application has been submitted successfully! A moderator will review it and follow up with you soon.", + flags: 64, + }, + }); + } else { + return new JSONResponse({ + type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, + data: { + content: + "❌ Failed to submit your NSFW access application. Please try again later.", + flags: 64, + }, + }); + } + } catch (error) { + console.error("Error in nsfw-apply command:", error); + + return new JSONResponse({ + type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, + data: { + content: "❌ An error occurred while processing your NSFW access application.", + flags: 64, + }, + }); + } + } + case COLOURS_COMMAND.name.toLowerCase(): { try { if (!interaction.guild_id) |