From 199c2dba163f45ab13c4ff6d3213eca9a551ac34 Mon Sep 17 00:00:00 2001 From: nin0 Date: Tue, 27 May 2025 06:30:40 -0400 Subject: [PATCH] Application Reviewing Bot Does What An Application Reviewing Bot Should Do: Accept Applications --- src/Constants.ts | 5 ++ src/joinRequestActions/accept.tsx | 116 ++++++++++++++++++++++++++++++ src/joinRequestHandler.tsx | 1 + 3 files changed, 122 insertions(+) create mode 100644 src/joinRequestActions/accept.tsx diff --git a/src/Constants.ts b/src/Constants.ts index 1a07fff..9454d52 100644 --- a/src/Constants.ts +++ b/src/Constants.ts @@ -1,10 +1,15 @@ export const Constants = { + APPROVED_CHANNEL_ID: "1371073576903376896", PENDING_CHANNEL_ID: "1370539719842070683", REJECTION_CHANNEL_ID: "1371073658403164261", REVIEWER_ROLE_ID: "1375617676139040909", MOD_ROLE_ID: "1370539692143153152", MANAGER_ROLE_ID: "1370539689659863091", OWNER_ID: "886685857560539176", + HERE_FOR_TAG: "1370898806249623643", + HERE_TO_CHAT: "1370898841309544589", + CAN_BOOST: "1371796535557361715", + FRIEND_ROLES: ["1370539694391165088", "1370539700862980117"], COLORS: { NEW_REQ: 0xaaaaff, BAD: 0xffaaaa, diff --git a/src/joinRequestActions/accept.tsx b/src/joinRequestActions/accept.tsx new file mode 100644 index 0000000..4120235 --- /dev/null +++ b/src/joinRequestActions/accept.tsx @@ -0,0 +1,116 @@ +import { ComponentTypes, InteractionTypes, MessageFlags } from "oceanic.js"; +import { client } from ".."; +import { canUser } from "../utils/utils"; +import { selfappReq } from "../utils/selfappReq"; +import { Response } from "~/utils/types"; +import { db } from "~/utils/database"; +import { ComponentMessage } from "components-jsx/ComponentMessage"; +import { Container } from "components-jsx/Container"; +import { Divider } from "components-jsx/Divider"; +import { TextDisplay } from "components-jsx/TextDisplay"; +import { ApplicationContent } from "~/components/ApplicationContent"; +import { User } from "~/components/User"; +import { Constants } from "~/Constants"; + +client.on("interactionCreate", async (interaction) => { + if (interaction.type === InteractionTypes.MESSAGE_COMPONENT) + if (interaction.data.componentType === ComponentTypes.BUTTON) { + if (interaction.data.customID.split("-")[0] === "accept") { + await interaction.defer(MessageFlags.EPHEMERAL); + if ( + !canUser(interaction.member!, "review") || + (!canUser(interaction.member!, "owner") && + interaction.data.customID.includes("friend")) + ) + return await interaction.createFollowup({ + flags: MessageFlags.EPHEMERAL, + content: "💢 nop" + }); + + const application = await db.get( + "SELECT * FROM applications WHERE message_id=?", + interaction.message.id + ); + + await db.run( + "DELETE FROM applications WHERE id=?", + application.id + ); + await client.rest.channels.deleteMessage( + application.channel_id, + application.message_id + ); + + await selfappReq( + `/guilds/${interaction.guildID}/requests/id/${application.id}`, + "PATCH", + { + action: "APPROVED" + } + ); + const user = await client.rest.users.get(application.user_id); + await interaction.createFollowup({ + flags: MessageFlags.EPHEMERAL, + content: `<:blobcatgreen:1375806000312881233> Approved @${user.tag}'s join request!` + }); + + const response: Response = JSON.parse(application.responses); + + const msg = await client.rest.channels.createMessage( + Constants.APPROVED_CHANNEL_ID, + + + ## Join request accepted + + + + + + + ); + + const member = await client.rest.guilds.getMember( + interaction.guildID!, + user.id + ); + client.rest.guilds.editMember(interaction.guildID!, user.id, { + reason: `${user.tag}'s application has been accepted`, + roles: (() => { + const roles = member.roles; + response.hereFor.includes("tag") && + roles.push(Constants.HERE_FOR_TAG); + response.hereFor.includes("chat") && + roles.push(Constants.HERE_TO_CHAT); + response.canBoost && roles.push(Constants.CAN_BOOST); + interaction.data.customID.includes("friend") && + roles.push(...Constants.FRIEND_ROLES); + return roles; + })() + }); + + await client.rest.request({ + auth: `Bot ${process.env.BOT_TOKEN}`, + method: "POST", + path: `/channels/${application.thread_id}/messages`, + json: { + content: "", + flags: 0, + message_reference: { + channel_id: msg.channelID, + guild_id: msg.guildID!, + message_id: msg.id, + type: 1 + } + } + }); + + await client.rest.channels.edit(application.thread_id, { + locked: true, + reason: `${user.tag}'s application has been accepted` + }); + } + } +}); diff --git a/src/joinRequestHandler.tsx b/src/joinRequestHandler.tsx index 0c0fcbb..3247f45 100644 --- a/src/joinRequestHandler.tsx +++ b/src/joinRequestHandler.tsx @@ -27,6 +27,7 @@ import { ApplicationContent } from "./components/ApplicationContent"; import("./joinRequestActions/lockUnlock"); import("./joinRequestActions/interview"); +import("./joinRequestActions/accept"); export async function setupJoinRequestHandler(shard: Shard) { shard.ws?.on("message", async (d) => {