diff options
| author | Fuwn <[email protected]> | 2025-10-08 22:43:38 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-10-08 22:43:38 -0700 |
| commit | 684dbde1d1ae2708d2dae623311326debf83c143 (patch) | |
| tree | 7f8450db4640b8d37c66012dd19c9ff4bc25972f /packages/interactions | |
| parent | feat(gateway:listeners): Disable mediaModeration module (diff) | |
| download | umabotdiscord-684dbde1d1ae2708d2dae623311326debf83c143.tar.xz umabotdiscord-684dbde1d1ae2708d2dae623311326debf83c143.zip | |
feat(interactions): Remove age-verify and nsfw-apply slash commands
Diffstat (limited to 'packages/interactions')
| -rw-r--r-- | packages/interactions/discord/commands/index.ts | 73 | ||||
| -rw-r--r-- | packages/interactions/discord/embeds.ts | 91 | ||||
| -rw-r--r-- | packages/interactions/register.ts | 4 | ||||
| -rw-r--r-- | packages/interactions/server.ts | 354 |
4 files changed, 2 insertions, 520 deletions
diff --git a/packages/interactions/discord/commands/index.ts b/packages/interactions/discord/commands/index.ts index c22d3aa..46665a4 100644 --- a/packages/interactions/discord/commands/index.ts +++ b/packages/interactions/discord/commands/index.ts @@ -96,23 +96,6 @@ export const APPEAL_COMMAND: DiscordCommand = { ], }; -export const NSFW_APPLY_COMMAND: DiscordCommand = { - name: "nsfw-apply", - description: "Submit an NSFW access application to the moderators", - contexts: [ - DISCORD_INTERACTION_CONTEXTS.GUILD, - DISCORD_INTERACTION_CONTEXTS.BOT_DM, - ], - options: [ - { - type: DISCORD_APPLICATION_COMMAND_OPTION_TYPES.STRING, - name: "message", - description: "Your NSFW access application message", - required: true, - }, - ], -}; - export const COLOURS_COMMAND: DiscordCommand = { name: "colours", description: "Show the distribution of colour roles in the server", @@ -151,59 +134,3 @@ export const ROLEPLAY_VERIFY_COMMAND: DiscordCommand = { }, ], }; - -export const AGE_VERIFY_COMMAND: DiscordCommand = { - name: "age-verify", - description: "Manage the verified age role (Staff only)", - options: [ - { - type: DISCORD_APPLICATION_COMMAND_OPTION_TYPES.STRING, - name: "action", - description: "Action to perform on the role", - required: true, - choices: [ - { - name: "Add Role", - value: "add", - }, - { - name: "Remove Role", - value: "remove", - }, - { - name: "Toggle Role", - value: "toggle", - }, - ], - }, - { - type: DISCORD_APPLICATION_COMMAND_OPTION_TYPES.USER, - name: "user", - description: "User to perform the action on", - required: true, - }, - { - type: DISCORD_APPLICATION_COMMAND_OPTION_TYPES.STRING, - name: "access", - description: "Type of access to grant", - required: true, - choices: [ - { - name: "Art & Media", - value: "art_media", - }, - { - name: "Roleplay NSFW", - value: "roleplay_nsfw", - }, - ], - }, - { - type: DISCORD_APPLICATION_COMMAND_OPTION_TYPES.STRING, - name: "reason", - description: - "Reason for verification (how and why you verified the user)", - required: true, - }, - ], -}; diff --git a/packages/interactions/discord/embeds.ts b/packages/interactions/discord/embeds.ts index bbae714..96c82f9 100644 --- a/packages/interactions/discord/embeds.ts +++ b/packages/interactions/discord/embeds.ts @@ -179,94 +179,3 @@ export const createAppealEmbed = ( }, }; }; - -export const createNSFWApplicationEmbed = ( - applicationContent: string, - applicant: { username: string; id: string; avatar?: string }, - timestamp: number, - isDM: boolean = true, - discordJoinDate?: string, - serverJoinDate?: string, -): DiscordEmbed => { - const fields = [ - { - name: "Applicant", - value: `<@${applicant.id}>`, - inline: true, - }, - { - name: "Timestamp", - value: `<t:${Math.floor(timestamp / 1000)}:F>`, - inline: true, - }, - ]; - - if (serverJoinDate) - fields.push({ - name: "Server Join Date", - value: `<t:${Math.floor(new Date(serverJoinDate).getTime() / 1000)}:F>`, - inline: true, - }); - - if (discordJoinDate) - fields.push({ - name: "Discord Join Date", - value: `<t:${Math.floor(new Date(discordJoinDate).getTime() / 1000)}:F>`, - inline: true, - }); - - return { - title: "🔞 NSFW Access Application", - description: applicationContent, - color: 0xff69b4, - fields, - thumbnail: applicant.avatar - ? { - url: `https://cdn.discordapp.com/avatars/${applicant.id}/${applicant.avatar}${applicant.avatar.startsWith("a_") ? ".gif" : ".png"}?size=256`, - } - : undefined, - footer: { - text: isDM - ? "Application submitted via DM" - : "Application submitted from server", - }, - }; -}; - -export const createAgeVerificationLogEmbed = ( - action: string, - targetUser: { username: string; id: string; avatar?: string }, - accessType: string, - reason: string, - moderator: { username: string; id: string; avatar?: string }, - timestamp: number, -): DiscordEmbed => { - return { - title: "🔞 Age Verification Log", - description: `**Action:** ${action}\n**Access Type:** ${accessType}\n**Reason:** ${reason}`, - color: 0x00ff00, - timestamp: new Date(timestamp).toISOString(), - fields: [ - { - name: "Target User", - value: `<@${targetUser.id}>`, - inline: true, - }, - { - name: "Moderator", - value: `<@${moderator.id}>`, - inline: true, - }, - { - name: "Timestamp", - value: `<t:${Math.floor(timestamp / 1000)}:F>`, - inline: true, - }, - ], - thumbnail: targetUser.avatar - ? { - url: `https://cdn.discordapp.com/avatars/${targetUser.id}/${targetUser.avatar}${targetUser.avatar.startsWith("a_") ? ".gif" : ".png"}?size=256`, - } - : undefined, - }; -}; diff --git a/packages/interactions/register.ts b/packages/interactions/register.ts index e076e5c..9ba9d90 100644 --- a/packages/interactions/register.ts +++ b/packages/interactions/register.ts @@ -5,10 +5,8 @@ import { TOP_COMMAND, COMPLAIN_COMMAND, APPEAL_COMMAND, - NSFW_APPLY_COMMAND, COLOURS_COMMAND, ROLEPLAY_VERIFY_COMMAND, - AGE_VERIFY_COMMAND, type DiscordCommand, } from "./discord/commands"; import dotenv from "dotenv"; @@ -36,10 +34,8 @@ const commands: DiscordCommand[] = [ TOP_COMMAND, COMPLAIN_COMMAND, APPEAL_COMMAND, - NSFW_APPLY_COMMAND, COLOURS_COMMAND, ROLEPLAY_VERIFY_COMMAND, - AGE_VERIFY_COMMAND, ]; const response = await fetch(url, { diff --git a/packages/interactions/server.ts b/packages/interactions/server.ts index 5ac6385..f836286 100644 --- a/packages/interactions/server.ts +++ b/packages/interactions/server.ts @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/no-unused-vars, no-unused-vars */ + import { AutoRouter } from "itty-router"; import { InteractionResponseType, InteractionType } from "discord-interactions"; import { @@ -7,10 +9,8 @@ import { TOP_COMMAND, COMPLAIN_COMMAND, APPEAL_COMMAND, - NSFW_APPLY_COMMAND, COLOURS_COMMAND, ROLEPLAY_VERIFY_COMMAND, - AGE_VERIFY_COMMAND, } from "./discord/commands"; import { getCutePost, @@ -24,8 +24,6 @@ import { createPostEmbed, createComplaintEmbed, createAppealEmbed, - createNSFWApplicationEmbed, - createAgeVerificationLogEmbed, createRoleDistributionEmbed, } from "./discord/embeds.ts"; import { JSONResponse } from "./discord/responses.ts"; @@ -35,8 +33,6 @@ import { CENTRAL_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 AGE_VERIFY_LOG_CHANNEL_ID = "1406422619934167106"; const VERIFIED_ROLEPLAY_ROLE_ID = "1418311833303122021"; const ROLE_MANAGER_ROLE_ID = "1410993207608873070"; const ART_MEDIA_ROLE_ID = "1410333831281643630"; @@ -72,58 +68,6 @@ 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 sendAgeVerificationLogToChannel = async ( - environment: Environment, - embed: DiscordEmbed, -): Promise<boolean> => { - const url = `https://discord.com/api/v10/channels/${AGE_VERIFY_LOG_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 age verification log to channel:", error); - - return false; - } -}; - const sendAppealToChannel = async ( environment: Environment, embed: DiscordEmbed, @@ -544,112 +488,6 @@ 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, - }; - let discordJoinDate: string | undefined; - let serverJoinDate: string | undefined; - - try { - const userId = interaction.member?.user?.id || interaction.user?.id; - - if (userId) { - const snowflake = BigInt(userId); - const timestamp = Number((snowflake >> 22n) + 1420070400000n); - - discordJoinDate = new Date(timestamp).toISOString(); - - if (interaction.guild_id) { - const memberResponse = await fetch( - `https://discord.com/api/v10/guilds/${interaction.guild_id}/members/${userId}`, - { - headers: { - Authorization: `Bot ${environment.DISCORD_TOKEN}`, - }, - }, - ); - - if (memberResponse.ok) { - const memberData = await memberResponse.json(); - - if (memberData.joined_at) - serverJoinDate = memberData.joined_at; - } - } - } - } catch (error) { - console.error("Error fetching join dates:", error); - } - - const isDM = !interaction.guild_id; - const applicationEmbed = createNSFWApplicationEmbed( - applicationMessage, - applicant, - Date.now(), - isDM, - discordJoinDate, - serverJoinDate, - ); - 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) @@ -863,194 +701,6 @@ router.post("/", async (request: Request, environment: Environment) => { } } - case AGE_VERIFY_COMMAND.name.toLowerCase(): { - try { - const member = interaction.member; - const hasAdminPermission = - member?.permissions && (parseInt(member.permissions) & 0x8) === 0x8; - const hasOwnerRole = member?.roles?.includes(OWNER_ROLE_ID); - const hasAdministratorRole = member?.roles?.includes( - ADMINISTRATOR_ROLE_ID, - ); - const hasModeratorRole = member?.roles?.includes(MODERATOR_ROLE_ID); - const hasTrialModeratorRole = member?.roles?.includes( - TRIAL_MODERATOR_ROLE_ID, - ); - - if ( - !hasAdminPermission && - !hasOwnerRole && - !hasAdministratorRole && - !hasModeratorRole && - !hasTrialModeratorRole - ) - return new JSONResponse({ - type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, - data: { - content: - "❌ You don't have permission to use this command. Only administrators and moderators can use this command.", - flags: 64, - }, - }); - - const action = interaction.data.options?.[0]?.value as string; - const targetUserID = interaction.data.options?.[1]?.value as string; - const access = interaction.data.options?.[2]?.value as string; - const reason = interaction.data.options?.[3]?.value as string; - - if (!action || !targetUserID || !access || !reason) - return new JSONResponse({ - type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, - data: { - content: - "❌ Missing required parameters. Please provide action, user, access type, and reason.", - flags: 64, - }, - }); - - const guild = await fetch( - `https://discord.com/api/v10/guilds/${CENTRAL_GUILD_ID}/members/${targetUserID}`, - { - headers: { - Authorization: `Bot ${environment.DISCORD_TOKEN}`, - }, - }, - ); - - if (!guild.ok) - return new JSONResponse({ - type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, - data: { - content: - "❌ Unable to fetch user information. The user may not be in this server.", - flags: 64, - }, - }); - - const targetMember = await guild.json(); - const currentRoles = targetMember.roles || []; - const targetRoleId = - access === "art_media" ? ART_MEDIA_ROLE_ID : ROLEPLAY_NSFW_ROLE_ID; - const hasRole = currentRoles.includes(targetRoleId); - let actionTaken = ""; - let newRoles = [...currentRoles]; - - if (action === "add") { - if (hasRole) - return new JSONResponse({ - type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, - data: { - content: `❌ <@${targetUserID}> already has the ${access === "art_media" ? "Art & Media" : "Roleplay NSFW"} role.`, - flags: 64, - }, - }); - - newRoles.push(targetRoleId); - - actionTaken = "added"; - } else if (action === "remove") { - if (!hasRole) - return new JSONResponse({ - type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, - data: { - content: `❌ <@${targetUserID}> doesn't have the ${access === "art_media" ? "Art & Media" : "Roleplay NSFW"} role.`, - flags: 64, - }, - }); - - newRoles = newRoles.filter((roleId) => roleId !== targetRoleId); - actionTaken = "removed"; - } else if (action === "toggle") { - if (hasRole) { - newRoles = newRoles.filter((roleId) => roleId !== targetRoleId); - actionTaken = "removed"; - } else { - newRoles.push(targetRoleId); - - actionTaken = "added"; - } - } - - const updateResponse = await fetch( - `https://discord.com/api/v10/guilds/${CENTRAL_GUILD_ID}/members/${targetUserID}`, - { - method: "PATCH", - headers: { - Authorization: `Bot ${environment.DISCORD_TOKEN}`, - "Content-Type": "application/json", - }, - body: JSON.stringify({ - roles: newRoles, - }), - }, - ); - - if (!updateResponse.ok) { - console.error( - "Failed to update user roles:", - await updateResponse.text(), - ); - - return new JSONResponse({ - type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, - data: { - content: - "❌ Failed to update user roles. The bot may not have sufficient permissions.", - flags: 64, - }, - }); - } - - const accessTypeName = - access === "art_media" ? "Art & Media" : "Roleplay NSFW"; - const moderator = { - 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 logEmbed = createAgeVerificationLogEmbed( - action, - { - username: targetMember.user?.username || "Unknown", - id: targetUserID, - avatar: targetMember.user?.avatar, - }, - accessTypeName, - reason, - moderator, - Date.now(), - ); - - try { - await sendAgeVerificationLogToChannel(environment, logEmbed); - } catch (logError) { - console.error("Failed to log age verification:", logError); - } - - return new JSONResponse({ - type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, - data: { - content: `✅ Successfully ${actionTaken} the ${accessTypeName} role for <@${targetUserID}>.`, - }, - }); - } catch (error) { - console.error("Error in age-verify command:", error); - - return new JSONResponse({ - type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, - data: { - content: "❌ An error occurred while managing the role.", - flags: 64, - }, - }); - } - } - default: return new JSONResponse({ error: "Unknown Type" }, { status: 400 }); } |