From e377117d33a18e313f52746579b4b1bdd9b2b1ab Mon Sep 17 00:00:00 2001 From: nin0 Date: Sat, 24 May 2025 17:17:45 -0400 Subject: [PATCH 1/2] working locked applications --- components-jsx/ComponentMessage.tsx | 28 +++++++++++----- src/Constants.ts | 4 +++ src/joinRequestHandler.tsx | 4 ++- src/lockUnlock.tsx | 50 +++++++++++++++++++++++++++++ src/selfappReq.ts | 2 -- src/utils.ts | 39 ++++++++++++++++++++++ 6 files changed, 116 insertions(+), 11 deletions(-) create mode 100644 src/lockUnlock.tsx diff --git a/components-jsx/ComponentMessage.tsx b/components-jsx/ComponentMessage.tsx index f9a7dd0..f722ba1 100644 --- a/components-jsx/ComponentMessage.tsx +++ b/components-jsx/ComponentMessage.tsx @@ -1,14 +1,26 @@ -import { CreateMessageOptions, EditMessageOptions, MessageComponent, MessageFlags } from "oceanic.js"; +import { + CreateMessageOptions, + EditMessageOptions, + InteractionOptions, + MessageComponent, + MessageFlags +} from "oceanic.js"; import { childrenToArray } from "./utils"; type MessageOptions = CreateMessageOptions | EditMessageOptions; -export type ComponentMessageProps = MessageOptions & { children: MessageComponent[]; }; +export type ComponentMessageProps = MessageOptions & { + children: MessageComponent[]; +}; -export function ComponentMessage({ children, flags, ...props }: ComponentMessageProps): MessageOptions { - return { - flags: MessageFlags.IS_COMPONENTS_V2 | (flags ?? 0), - components: childrenToArray(children), - ...props - }; +export function ComponentMessage({ + children, + flags, + ...props +}: ComponentMessageProps): MessageOptions { + return { + flags: MessageFlags.IS_COMPONENTS_V2 | (flags ?? 0), + components: childrenToArray(children), + ...props + }; } diff --git a/src/Constants.ts b/src/Constants.ts index b0d4873..1a07fff 100644 --- a/src/Constants.ts +++ b/src/Constants.ts @@ -1,6 +1,10 @@ export const Constants = { PENDING_CHANNEL_ID: "1370539719842070683", REJECTION_CHANNEL_ID: "1371073658403164261", + REVIEWER_ROLE_ID: "1375617676139040909", + MOD_ROLE_ID: "1370539692143153152", + MANAGER_ROLE_ID: "1370539689659863091", + OWNER_ID: "886685857560539176", COLORS: { NEW_REQ: 0xaaaaff, BAD: 0xffaaaa, diff --git a/src/joinRequestHandler.tsx b/src/joinRequestHandler.tsx index 597d88d..9279374 100644 --- a/src/joinRequestHandler.tsx +++ b/src/joinRequestHandler.tsx @@ -19,6 +19,8 @@ import { match } from "./utils"; import { PendingApplicationMessage } from "./components/PendingApplicationMessage"; import { ApplicationContent } from "./components/ApplicationContent"; +import("./lockUnlock"); + export async function setupJoinRequestHandler(shard: Shard) { shard.ws?.on("message", async (d) => { const data = JSON.parse(d.toString("utf8")); @@ -127,7 +129,7 @@ export async function setupJoinRequestHandler(shard: Shard) { } const response: Response = JSON.parse( - application.responses + application ? application.responses : {} // this will never be used if no applications ); const msg = await client.rest.channels.createMessage( diff --git a/src/lockUnlock.tsx b/src/lockUnlock.tsx new file mode 100644 index 0000000..a58f5bd --- /dev/null +++ b/src/lockUnlock.tsx @@ -0,0 +1,50 @@ +import { ComponentTypes, InteractionTypes, MessageFlags } from "oceanic.js"; +import { client } from "."; +import { db } from "./database"; +import { PendingApplicationMessage } from "./components/PendingApplicationMessage"; +import { canUser } from "./utils"; + +client.on("interactionCreate", async (interaction) => { + if (interaction.type === InteractionTypes.MESSAGE_COMPONENT) + if (interaction.data.componentType === ComponentTypes.BUTTON) { + if (!canUser(interaction.member!, "owner")) + return await interaction.createMessage({ + flags: MessageFlags.EPHEMERAL, + content: "💢 nop" + }); + + const application = await db.get( + "SELECT * FROM applications WHERE message_id=?", + interaction.message.id + ); + + switch (interaction.data.customID.split("-")[0]) { + case "lock": { + await interaction.editParent( + + ); + break; + } + case "unlock": { + await interaction.editParent( + + ); + break; + } + } + } +}); diff --git a/src/selfappReq.ts b/src/selfappReq.ts index a2d5e11..cbde29f 100644 --- a/src/selfappReq.ts +++ b/src/selfappReq.ts @@ -12,8 +12,6 @@ export async function selfappReq( return `?${new URLSearchParams(data).toString()}`; })(); - console.log(url); - return await fetch(url, { method, headers: { diff --git a/src/utils.ts b/src/utils.ts index 5b95965..e6baeed 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,3 +1,6 @@ +import { Member } from "oceanic.js"; +import { Constants } from "./Constants"; + export function match( value: any, matches: { @@ -7,3 +10,39 @@ export function match( if (matches[value]) return matches[value]; else return null; } + +export function canUser( + member: Member, + can: "review" | "moderate" | "manage" | "owner" +) { + switch (can) { + case "review": + return ( + member.roles.some((role) => + [ + Constants.REVIEWER_ROLE_ID, + Constants.MOD_ROLE_ID, + Constants.MANAGER_ROLE_ID + ].includes(role) + ) || member.id === Constants.OWNER_ID + ); + case "moderate": + return ( + member.roles.some((role) => + [Constants.MOD_ROLE_ID, Constants.MANAGER_ROLE_ID].includes( + role + ) + ) || member.id === Constants.OWNER_ID + ); + case "manage": + return ( + member.roles.some((role) => + [Constants.MANAGER_ROLE_ID].includes(role) + ) || member.id === Constants.OWNER_ID + ); + case "owner": + return member.id === Constants.OWNER_ID; + default: + return false; + } +} From 7dcc0c2cc48454aca00164fc0ee9c4acd8ced9b3 Mon Sep 17 00:00:00 2001 From: nin0 Date: Sat, 24 May 2025 20:00:39 -0400 Subject: [PATCH 2/2] internal corporate restructuring (90% of our engineer team has been laid off and replaced by Grok) --- src/components/ApplicationContent.tsx | 2 +- src/components/PendingApplicationMessage.tsx | 158 ++++++++++--------- src/index.ts | 10 +- src/joinRequestActions/interview.ts | 37 +++++ src/{ => joinRequestActions}/lockUnlock.tsx | 13 +- src/joinRequestHandler.tsx | 35 ++-- src/{ => utils}/database.ts | 0 src/utils/rejectReasons.ts | 23 +++ src/{ => utils}/selfappReq.ts | 0 src/{ => utils}/types.ts | 0 src/{ => utils}/utils.ts | 2 +- 11 files changed, 184 insertions(+), 96 deletions(-) create mode 100644 src/joinRequestActions/interview.ts rename src/{ => joinRequestActions}/lockUnlock.tsx (76%) rename src/{ => utils}/database.ts (100%) create mode 100644 src/utils/rejectReasons.ts rename src/{ => utils}/selfappReq.ts (100%) rename src/{ => utils}/types.ts (100%) rename src/{ => utils}/utils.ts (95%) diff --git a/src/components/ApplicationContent.tsx b/src/components/ApplicationContent.tsx index 97a14c8..1ae1ac3 100644 --- a/src/components/ApplicationContent.tsx +++ b/src/components/ApplicationContent.tsx @@ -1,5 +1,5 @@ import { TextDisplay } from "components-jsx/TextDisplay"; -import { Response } from "~/types"; +import { Response } from "~/utils/types"; export function ApplicationContent(props: { response: Response; diff --git a/src/components/PendingApplicationMessage.tsx b/src/components/PendingApplicationMessage.tsx index e5f6565..80ebe71 100644 --- a/src/components/PendingApplicationMessage.tsx +++ b/src/components/PendingApplicationMessage.tsx @@ -5,16 +5,19 @@ import { Container } from "components-jsx/Container"; import { Divider } from "components-jsx/Divider"; import { TextDisplay } from "components-jsx/TextDisplay"; import { ButtonStyles, User as OUser } from "oceanic.js"; -import { Response } from "~/types"; +import { Response } from "~/utils/types"; import { User } from "./User"; import { Constants } from "~/Constants"; import { ApplicationContent } from "./ApplicationContent"; +import { StringSelect } from "components-jsx/StringSelect"; +import { rejectReasons } from "~/utils/rejectReasons"; export function PendingApplicationMessage(props: { id: string; user: OUser; response: Response; locked?: boolean; + threadID: string; }) { const { id, user, response } = props; const locked = props.locked || false; @@ -30,83 +33,84 @@ export function PendingApplicationMessage(props: { - - - - ### Details -
- {response.details} -
- - - - - - - - - - - - - + + +