Skip to content
Permalink
Newer
Older
100644 69 lines (63 sloc) 1.86 KB
1
export async function onRequestPost(context: RequestContext) {
October 19, 2023 16:49
2
const { appeal } = context.data;
3
const body = new FormData();
4
body.append("from", "noreply@mail.carcrushers.cc");
October 19, 2023 16:49
5
body.append("to", appeal.email);
6
body.append("subject", "Appeal Accepted");
7
body.append("template", "appeal_accepted");
8
body.append("v:note", context.data.body.feedback || "No note provided.");
9
10
const emailReq = await fetch(
11
"https://api.mailgun.net/v3/mail.carcrushers.cc/messages",
12
{
13
body,
14
headers: {
15
authorization: `Basic ${btoa("api:" + context.env.MAILGUN_API_KEY)}`,
16
},
17
method: "POST",
18
}
19
);
20
21
if (!emailReq.ok) {
22
console.log(await emailReq.json());
23
return new Response('{"error":"Failed to accept appeal"}', {
24
headers: {
25
"content-type": "application/json",
26
},
27
status: 500,
28
});
29
}
30
31
const { current_user: currentUser } = context.data;
32
33
await fetch(
October 19, 2023 16:49
34
`https://discord.com/api/v10/guilds/242263977986359297/bans/${appeal.id}`,
35
{
36
headers: {
37
authorization: `Bot ${context.env.BOT_TOKEN}`,
38
"x-audit-log-reason": `Appeal accepted by ${currentUser.username}#${currentUser.discriminator} (${currentUser.id})`,
39
},
40
method: "DELETE",
41
}
42
);
43
44
await fetch(context.env.APPEALS_WEBHOOK, {
45
body: JSON.stringify({
46
embeds: [
47
{
48
title: "Appeal Accepted",
49
color: 0x00ff00,
October 19, 2023 16:49
50
description: `Appeal from user ${appeal.username}#${appeal.discriminator} (${appeal.id}) was accepted.`,
51
fields: [
52
{
53
name: "Moderator",
54
value: `${currentUser.username}#${currentUser.discriminator} (${currentUser.id})`,
55
},
56
],
57
},
58
],
59
}),
60
headers: {
61
"content-type": "application/json",
62
},
63
method: "POST",
64
});
65
66
return new Response(null, {
67
status: 204,
68
});
69
}