diff --git a/src/joinRequestHandler.tsx b/src/joinRequestHandler.tsx index b7d154d..8e9a1b6 100644 --- a/src/joinRequestHandler.tsx +++ b/src/joinRequestHandler.tsx @@ -1,4 +1,4 @@ -import { ComponentTypes, MessageFlags, Shard } from "oceanic.js"; +import { ButtonStyles, ComponentTypes, MessageFlags, Shard } from "oceanic.js"; import { client } from "."; import { Constants } from "./Constants"; import { db } from "./database"; @@ -14,6 +14,8 @@ import { } from "~/components"; import { selfappReq } from "./selfappReq"; import { User } from "./components/User"; +import { Response } from "./types"; +import { match } from "./utils"; export async function setupJoinRequestHandler(shard: Shard) { shard.ws?.on("message", async (d) => { @@ -25,19 +27,165 @@ export async function setupJoinRequestHandler(shard: Shard) { case "GUILD_JOIN_REQUEST_UPDATE": { switch (applicationData.status) { case "SUBMITTED": { + const rawResponses = + applicationData.request.form_responses; + const response: Response = { + hereFor: match(rawResponses[0].response, { + 0: ["tag"], + 1: ["chat"], + 2: ["tag", "chat"] + }), + foundThrough: match(rawResponses[1].response, { + 0: "archive", + 1: "user", + 2: "tag", + 3: "other", + 4: "sold" + }), + languages: rawResponses[2].response, + details: rawResponses[3].response, + canBoost: rawResponses[4].response === 0 + }; + const user = await client.rest.users.get( + applicationData.request.user.id + ); const pendingMsg = await client.rest.channels.createMessage( Constants.PENDING_CHANNEL_ID, - Placeholder + + {"<@&1375617676139040909>"} + + + + ## New join request + + + + + + ### Application +
+ Here for +
+ -# {response.hereFor.join(", ")} +
+ Found through +
+ -#{" "} + {(() => { + switch ( + response.foundThrough + ) { + case "archive": + return "Guild Archive/nelly.tools"; + case "tag": + return 'Hit "Ask to Join" on a clan tag'; + case "user": + return "User invited them\n-# **Only accept if someone is mentioned in details**"; + case "other": + return "Something else"; + case "sold": + return "Was sold an invite\n-# **Only the owner can interact with this application**"; + } + })()} +
+ Languages +
+ -# {response.languages} +
+ Can boost +
+ -#{" "} + {response.canBoost + ? "Yes" + : "No"} +
+ + + ### Details +
+ {response.details} +
+ + + + + + + + + + + + + +
); await db.run( - "INSERT INTO applications (id, user_id, status, message_id, channel_id) VALUES (?, ?, 0, ?, ?)", + "INSERT INTO applications (id, user_id, status, message_id, channel_id, responses) VALUES (?, ?, 0, ?, ?, ?)", applicationData.request.id, applicationData.request.user_id, pendingMsg.id, - pendingMsg.channelID + pendingMsg.channelID, + JSON.stringify(response) ); break; diff --git a/src/types.ts b/src/types.ts index e69de29..cbaf5e2 100644 --- a/src/types.ts +++ b/src/types.ts @@ -0,0 +1,7 @@ +export type Response = { + hereFor: ("tag" | "chat")[]; + foundThrough: "archive" | "user" | "tag" | "other" | "sold"; + languages: string; + details: string; + canBoost: boolean; +}; diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..5b95965 --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,9 @@ +export function match( + value: any, + matches: { + [key: number | string]: any; + } +) { + if (matches[value]) return matches[value]; + else return null; +}