Skip to content
Permalink
Newer
Older
100644 73 lines (66 sloc) 1.91 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:50
5
body.append("to", appeal.user.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",
October 19, 2023 16:50
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 context.env.D1.prepare("UPDATE appeals SET open = 0 WHERE id = ?;")
34
.bind(context.params.id)
35
.run();
36
37
await fetch(
October 19, 2023 16:49
38
`https://discord.com/api/v10/guilds/242263977986359297/bans/${appeal.id}`,
39
{
40
headers: {
41
authorization: `Bot ${context.env.BOT_TOKEN}`,
42
"x-audit-log-reason": `Appeal accepted by ${currentUser.username} (${currentUser.id})`,
43
},
44
method: "DELETE",
October 19, 2023 16:50
45
},
46
);
47
48
await fetch(context.env.APPEALS_WEBHOOK, {
49
body: JSON.stringify({
50
embeds: [
51
{
52
title: "Appeal Accepted",
53
color: 0x00ff00,
October 19, 2023 16:50
54
description: `Appeal from user ${appeal.user.username} (${appeal.user.id}) was accepted.`,
55
fields: [
56
{
57
name: "Moderator",
58
value: `${currentUser.username} (${currentUser.id})`,
59
},
60
],
61
},
62
],
63
}),
64
headers: {
65
"content-type": "application/json",
66
},
67
method: "POST",
68
});
69
70
return new Response(null, {
71
status: 204,
72
});
73
}