Fix automatic unbans

This commit is contained in:
2023-10-21 00:26:33 -04:00
parent 3fb2eb20b9
commit 9212e3e454

View File

@ -10,7 +10,7 @@ export async function onRequestPost(context: RequestContext) {
context.env, context.env,
"Appeal Accepted", "Appeal Accepted",
context.data.body.feedback || "No additional details to display", context.data.body.feedback || "No additional details to display",
appeal.fcm_token, appeal.fcm_token
); );
} else { } else {
const emailResponse = await sendEmail( const emailResponse = await sendEmail(
@ -19,8 +19,8 @@ export async function onRequestPost(context: RequestContext) {
"Appeal Accepted", "Appeal Accepted",
"appeal_accepted", "appeal_accepted",
{ {
note: context.data.body.feedback || "No note provided.", note: context.data.body.feedback || "No note provided."
}, }
); );
if (!emailResponse.ok) { if (!emailResponse.ok) {
@ -32,7 +32,7 @@ export async function onRequestPost(context: RequestContext) {
const { current_user: currentUser } = context.data; const { current_user: currentUser } = context.data;
await context.env.D1.prepare( await context.env.D1.prepare(
"UPDATE appeals SET approved = 1, open = 0 WHERE id = ?;", "UPDATE appeals SET approved = 1, open = 0 WHERE id = ?;"
) )
.bind(context.params.id) .bind(context.params.id)
.run(); .run();
@ -43,18 +43,18 @@ export async function onRequestPost(context: RequestContext) {
appeal.open = false; appeal.open = false;
await context.env.DATA.put(`appeal_${appeal.id}`, JSON.stringify(appeal), { await context.env.DATA.put(`appeal_${appeal.id}`, JSON.stringify(appeal), {
expirationTtl: 94608000, expirationTtl: 94608000
}); });
await fetch( await fetch(
`https://discord.com/api/v10/guilds/242263977986359297/bans/${appeal.id}`, `https://discord.com/api/v10/guilds/242263977986359297/bans/${appeal.user.id}`,
{ {
headers: { headers: {
authorization: `Bot ${context.env.BOT_TOKEN}`, authorization: `Bot ${context.env.BOT_TOKEN}`,
"x-audit-log-reason": `Appeal accepted by ${currentUser.username} (${currentUser.id})`, "x-audit-log-reason": `Appeal accepted by ${currentUser.username} (${currentUser.id})`
}, },
method: "DELETE", method: "DELETE"
}, }
); );
await fetch(context.env.APPEALS_WEBHOOK, { await fetch(context.env.APPEALS_WEBHOOK, {
@ -67,19 +67,19 @@ export async function onRequestPost(context: RequestContext) {
fields: [ fields: [
{ {
name: "Moderator", name: "Moderator",
value: `${currentUser.username} (${currentUser.id})`, value: `${currentUser.username} (${currentUser.id})`
}, }
], ]
}, }
], ]
}), }),
headers: { headers: {
"content-type": "application/json", "content-type": "application/json"
}, },
method: "POST", method: "POST"
}); });
return new Response(null, { return new Response(null, {
status: 204, status: 204
}); });
} }