working locked applications

This commit is contained in:
nin0 2025-05-24 17:17:45 -04:00
parent 97d607871c
commit e377117d33
Signed by: nin0
SSH key fingerprint: SHA256:NOoDnFVvZNFvqfXCIhzr6oCTDImZAbTTuyAysZ8Ufk8
6 changed files with 116 additions and 11 deletions

View file

@ -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"; import { childrenToArray } from "./utils";
type MessageOptions = CreateMessageOptions | EditMessageOptions; type MessageOptions = CreateMessageOptions | EditMessageOptions;
export type ComponentMessageProps = MessageOptions & { children: MessageComponent[]; }; export type ComponentMessageProps = MessageOptions & {
children: MessageComponent[];
};
export function ComponentMessage({ children, flags, ...props }: ComponentMessageProps): MessageOptions { export function ComponentMessage({
return { children,
flags: MessageFlags.IS_COMPONENTS_V2 | (flags ?? 0), flags,
components: childrenToArray(children), ...props
...props }: ComponentMessageProps): MessageOptions {
}; return {
flags: MessageFlags.IS_COMPONENTS_V2 | (flags ?? 0),
components: childrenToArray(children),
...props
};
} }

View file

@ -1,6 +1,10 @@
export const Constants = { export const Constants = {
PENDING_CHANNEL_ID: "1370539719842070683", PENDING_CHANNEL_ID: "1370539719842070683",
REJECTION_CHANNEL_ID: "1371073658403164261", REJECTION_CHANNEL_ID: "1371073658403164261",
REVIEWER_ROLE_ID: "1375617676139040909",
MOD_ROLE_ID: "1370539692143153152",
MANAGER_ROLE_ID: "1370539689659863091",
OWNER_ID: "886685857560539176",
COLORS: { COLORS: {
NEW_REQ: 0xaaaaff, NEW_REQ: 0xaaaaff,
BAD: 0xffaaaa, BAD: 0xffaaaa,

View file

@ -19,6 +19,8 @@ import { match } from "./utils";
import { PendingApplicationMessage } from "./components/PendingApplicationMessage"; import { PendingApplicationMessage } from "./components/PendingApplicationMessage";
import { ApplicationContent } from "./components/ApplicationContent"; import { ApplicationContent } from "./components/ApplicationContent";
import("./lockUnlock");
export async function setupJoinRequestHandler(shard: Shard) { export async function setupJoinRequestHandler(shard: Shard) {
shard.ws?.on("message", async (d) => { shard.ws?.on("message", async (d) => {
const data = JSON.parse(d.toString("utf8")); const data = JSON.parse(d.toString("utf8"));
@ -127,7 +129,7 @@ export async function setupJoinRequestHandler(shard: Shard) {
} }
const response: Response = JSON.parse( 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( const msg = await client.rest.channels.createMessage(

50
src/lockUnlock.tsx Normal file
View file

@ -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(
<PendingApplicationMessage
id={application.id}
response={JSON.parse(application.responses)}
user={await client.rest.users.get(
application.user_id
)}
locked={true}
/>
);
break;
}
case "unlock": {
await interaction.editParent(
<PendingApplicationMessage
id={application.id}
response={JSON.parse(application.responses)}
user={await client.rest.users.get(
application.user_id
)}
locked={false}
/>
);
break;
}
}
}
});

View file

@ -12,8 +12,6 @@ export async function selfappReq(
return `?${new URLSearchParams(data).toString()}`; return `?${new URLSearchParams(data).toString()}`;
})(); })();
console.log(url);
return await fetch(url, { return await fetch(url, {
method, method,
headers: { headers: {

View file

@ -1,3 +1,6 @@
import { Member } from "oceanic.js";
import { Constants } from "./Constants";
export function match( export function match(
value: any, value: any,
matches: { matches: {
@ -7,3 +10,39 @@ export function match(
if (matches[value]) return matches[value]; if (matches[value]) return matches[value];
else return null; 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;
}
}