Create appeal accept and deny endpoints
This commit is contained in:
parent
75c38e9cc5
commit
a3eca56fec
69
functions/api/appeals/[id]/accept.ts
Normal file
69
functions/api/appeals/[id]/accept.ts
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
export async function onRequestPost(context: RequestContext) {
|
||||||
|
const { metadata, value } = context.data.appeal;
|
||||||
|
const body = new FormData();
|
||||||
|
body.append("from", "noreply@mail.carcrushers.cc");
|
||||||
|
body.append("to", value.email);
|
||||||
|
body.append("subject", "Appeal Accepted");
|
||||||
|
body.append("template", "appeal_accepted");
|
||||||
|
body.append("v:note", context.data.body.feedback || "No note provided.");
|
||||||
|
|
||||||
|
const emailReq = await fetch(
|
||||||
|
"https://api.mailgun.net/v3/mail.carcrushers.cc/messages",
|
||||||
|
{
|
||||||
|
body,
|
||||||
|
headers: {
|
||||||
|
authorization: `Basic ${btoa("api:" + context.env.MAILGUN_API_KEY)}`,
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!emailReq.ok) {
|
||||||
|
console.log(await emailReq.json());
|
||||||
|
return new Response('{"error":"Failed to accept appeal"}', {
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json",
|
||||||
|
},
|
||||||
|
status: 500,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const { current_user: currentUser } = context.data;
|
||||||
|
|
||||||
|
await fetch(
|
||||||
|
`https://discord.com/api/v10/guilds/242263977986359297/bans/${metadata.id}`,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
authorization: `Bot ${context.env.BOT_TOKEN}`,
|
||||||
|
"x-audit-log-reason": `Appeal accepted by ${currentUser.username}#${currentUser.discriminator} (${currentUser.id})`,
|
||||||
|
},
|
||||||
|
method: "DELETE",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
await fetch(context.env.APPEALS_WEBHOOK, {
|
||||||
|
body: JSON.stringify({
|
||||||
|
embeds: [
|
||||||
|
{
|
||||||
|
title: "Appeal Accepted",
|
||||||
|
color: 0x00ff00,
|
||||||
|
description: `Appeal from user ${metadata.tag} (${metadata.id}) was accepted.`,
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: "Moderator",
|
||||||
|
value: `${currentUser.username}#${currentUser.discriminator} (${currentUser.id})`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json",
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
});
|
||||||
|
|
||||||
|
return new Response(null, {
|
||||||
|
status: 204,
|
||||||
|
});
|
||||||
|
}
|
58
functions/api/appeals/[id]/deny.ts
Normal file
58
functions/api/appeals/[id]/deny.ts
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
export async function onRequestPost(context: RequestContext) {
|
||||||
|
const { metadata, value } = context.data.appeal;
|
||||||
|
const body = new FormData();
|
||||||
|
body.append("from", "noreply@mail.carcrushers.cc");
|
||||||
|
body.append("to", value.email);
|
||||||
|
body.append("subject", "Appeal Denied");
|
||||||
|
body.append("template", "appeal_denied");
|
||||||
|
body.append("v:note", context.data.body.feedback || "No note provided.");
|
||||||
|
|
||||||
|
const emailReq = await fetch(
|
||||||
|
"https://api.mailgun.net/v3/mail.carcrushers.cc/messages",
|
||||||
|
{
|
||||||
|
body,
|
||||||
|
headers: {
|
||||||
|
authorization: `Basic ${btoa("api:" + context.env.MAILGUN_API_KEY)}`,
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!emailReq.ok) {
|
||||||
|
console.log(await emailReq.json());
|
||||||
|
return new Response('{"error":"Failed to deny appeal"}', {
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json",
|
||||||
|
},
|
||||||
|
status: 500,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const { current_user: currentUser } = context.data;
|
||||||
|
|
||||||
|
await fetch(context.env.APPEALS_WEBHOOK, {
|
||||||
|
body: JSON.stringify({
|
||||||
|
embeds: [
|
||||||
|
{
|
||||||
|
title: "Appeal Denied",
|
||||||
|
color: 0xff0000,
|
||||||
|
description: `Appeal from user ${metadata.tag} (${metadata.id}) was denied.`,
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: "Moderator",
|
||||||
|
value: `${currentUser.username}#${currentUser.discriminator} (${currentUser.id})`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json",
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
});
|
||||||
|
|
||||||
|
return new Response(null, {
|
||||||
|
status: 204,
|
||||||
|
});
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user