Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions src/interfaces/appeal.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
/* eslint-disable @typescript-eslint/naming-convention -- This is what we get.*/
export interface Appeal {
table_id: number;
database_id: number;
workspace_id: number;
event_id: string;
event_type: string;
items: Array<
{
"id": number;
"order": string;
"User ID": string;
"Username": string;
"Code of Conduct": boolean;
"Reason": string;
"Fair": string;
"Improve": string;
"Email": string;
}
>;
id: number;
manualSort: number;
Discord_ID: string;
Username: string;
Code_of_Conduct: boolean;
Reason: string;
Fairness: string;
Improvement: string;
}
2 changes: 1 addition & 1 deletion src/modules/sendModerationDm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const sendModerationDm = async(
if (action === "ban") {
embed.addFields({
name: "Appeals",
value: `You can use [this form](https://forms.nhcarrigan.com/form/2Z1ohoTrVaiXVtboIVB1CKn8OZID7dHhslhnZO4---s) to appeal your ban after you have [read our code of conduct](https://www.freecodecamp.org/news/code-of-conduct).`,
value: `You can use [this form](https://forms.nhcarrigan.com/o/docs/forms/k7fPZmhgCS4RRKbStq8AcW/4) to appeal your ban after you have [read our code of conduct](https://www.freecodecamp.org/news/code-of-conduct).`,
});
}

Expand Down
226 changes: 118 additions & 108 deletions src/server/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const instantiateServer = async(
await camperChan.octokit.rest.pulls.createReview({
body:
action === "labeled"
// eslint-disable-next-line stylistic/max-len -- It's a string.
// eslint-disable-next-line stylistic/max-len -- It's a string.
? "This PR has been marked as DO NOT MERGE. When you are ready to merge it, remove the label and I'll unblock the PR."
// eslint-disable-next-line stylistic/max-len -- It's a string.
: "This PR has been unmarked as DO NOT MERGE. You may now merge this PR.",
Expand Down Expand Up @@ -144,145 +144,155 @@ export const instantiateServer = async(
await response.status(500).send("No secret provided.");
return;
}
const secretHeader = request.headers["x-appeal-secret"];
const secretHeader = request.headers.Authorization;
if (typeof secretHeader !== "string") {
await response.
status(400).
send(`Invalid value ${String(secretHeader)} for X-Appeal-Secret`);
send(`Invalid value ${String(secretHeader)} for Authorization`);
return;
}
if (secretHeader !== appealSecret) {
await response.status(401).send("Failed to verify appeal secret.");
return;
}
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- I'll make a type guard at some point.
const { body } = request as { body: Appeal };
const [ appeal ] = body.items;
if (!appeal) {
const { body } = request as { body: Array<Appeal> };
if (body.length === 0) {
await response.status(400).send("No appeal data provided.");
return;
}
// It's valid, so send an ok response immediately
await response.status(200).send("OK~!");
logHandler.log(
"info",
`New appeal received from ${appeal.Username} (${appeal["User ID"]})`,
);
await Promise.all(
body.map(async(appeal) => {
// It's valid, so send an ok response immediately
await response.status(200).send("OK~!");
logHandler.log(
"info",
`New appeal received from ${appeal.Username} (${appeal.Discord_ID})`,
);

await fetch(
"https://discord.com/api/v10/channels/987408145863307334/messages",
{
body: JSON.stringify({
components: [
{
content: "# NEW BAN APPEAL",
type: 10,
},
{
// eslint-disable-next-line @typescript-eslint/naming-convention -- Discord API name.
accent_color: null,
components: [
await fetch(
"https://discord.com/api/v10/channels/987408145863307334/messages",
{
body: JSON.stringify({
components: [
{
content: "**User Name and ID**",
content: "# NEW BAN APPEAL",
type: 10,
},
{
content: `${appeal.Username} (${appeal["User ID"]})`,
type: 10,
// eslint-disable-next-line @typescript-eslint/naming-convention -- Discord API name.
accent_color: null,
components: [
{
content: "**User Name and ID**",
type: 10,
},
{
content: `${appeal.Username} (${appeal.Discord_ID})`,
type: 10,
},
],
spoiler: false,
type: 17,
},
],
spoiler: false,
type: 17,
},
{
// eslint-disable-next-line @typescript-eslint/naming-convention -- Discord API name.
accent_color: null,
components: [
{
content: "**I have read and will follow Code of Conduct**",
type: 10,
// eslint-disable-next-line @typescript-eslint/naming-convention -- Discord API name.
accent_color: null,
components: [
{
content:
"**I have read and will follow Code of Conduct**",
type: 10,
},
{
content: String(appeal.Code_of_Conduct),
type: 10,
},
],
spoiler: false,
type: 17,
},
{
content: String(appeal["Code of Conduct"]),
type: 10,
// eslint-disable-next-line @typescript-eslint/naming-convention -- Discord API name.
accent_color: null,
components: [
{
content: "**Why were you banned?**",
type: 10,
},
{
content: appeal.Reason,
type: 10,
},
],
spoiler: false,
type: 17,
},
],
spoiler: false,
type: 17,
},
{
// eslint-disable-next-line @typescript-eslint/naming-convention -- Discord API name.
accent_color: null,
components: [
{
content: "**Why were you banned?**",
type: 10,
// eslint-disable-next-line @typescript-eslint/naming-convention -- Discord API name.
accent_color: null,
components: [
{
content: "**Was the ban fair? Why or why not?**",
type: 10,
},
{
content: appeal.Fairness,
type: 10,
},
],
spoiler: false,
type: 17,
},
{
content: appeal.Reason,
type: 10,
// eslint-disable-next-line @typescript-eslint/naming-convention -- Discord API name.
accent_color: null,
components: [
{
content: "**How will your behaviour improve?**",
type: 10,
},
{
content: appeal.Improvement,
type: 10,
},
],
spoiler: false,
type: 17,
},
],
spoiler: false,
type: 17,
},
{
flags: 32_768,
}),
headers: {
// eslint-disable-next-line @typescript-eslint/naming-convention -- Discord API name.
accent_color: null,
components: [
{
content: "**Was the ban fair? Why or why not?**",
type: 10,
},
{
content: appeal.Fair,
type: 10,
},
],
spoiler: false,
type: 17,
},
{
"Authorization": `Bot ${process.env.TOKEN ?? ""}`,
// eslint-disable-next-line @typescript-eslint/naming-convention -- Discord API name.
accent_color: null,
components: [
{
content: "**How will your behaviour improve?**",
type: 10,
},
{
content: appeal.Improve,
type: 10,
},
],
spoiler: false,
type: 17,
"Content-Type": "application/json",
},
method: "POST",
},
).
// eslint-disable-next-line max-nested-callbacks -- Necessary to handle the nested callback.
then((responseInner) => {
if (!responseInner.ok) {
throw new Error(
`Failed to send appeal message: ${responseInner.statusText}`,
);
}
}).
catch(
// eslint-disable-next-line max-nested-callbacks -- Necessary to handle the nested callback.
(error: unknown) => {
logHandler.error(JSON.stringify(error));
return void errorHandler(
camperChan,
"send appeal message",
error,
);
},
],
flags: 32_768,
}),
headers: {
// eslint-disable-next-line @typescript-eslint/naming-convention -- Discord API name.
"Authorization": `Bot ${process.env.TOKEN ?? ""}`,
// eslint-disable-next-line @typescript-eslint/naming-convention -- Discord API name.
"Content-Type": "application/json",
},
method: "POST",
},
).
then((responseInner) => {
if (!responseInner.ok) {
throw new Error(
`Failed to send appeal message: ${responseInner.statusText}`,
);
}
}).
catch(
(error: unknown) => {
logHandler.error(JSON.stringify(error));
return void errorHandler(camperChan, "send appeal message", error);
},
);
}),
);
});

server.listen({ port: 1443 }, (error) => {
Expand Down