Permalink
Newer
100644
66 lines (56 sloc)
1.46 KB
1
import { queryLogs } from "../../gcloud.js";
2
import { getBanList } from "../../roblox-open-cloud.js";
3
4
export default async function (
5
context: RequestContext,
6
user: number,
7
): Promise<{ can_appeal?: boolean; error?: string; reason?: string }> {
8
if (
9
await context.env.D1.prepare("SELECT * FROM game_appeals WHERE open = 1 AND user = ?;")
10
.bind(user)
11
.first()
12
)
13
return {
14
can_appeal: false,
15
reason: "You have already submitted an appeal",
16
};
17
18
let banList;
19
20
try {
21
banList = (await getBanList(context)) as {
22
[k: number]: { BanType: number };
23
};
24
} catch {
25
return {
26
error: "Failed to check your ban status",
27
};
28
}
29
30
if (!banList[user]?.BanType)
31
return {
32
can_appeal: false,
33
reason: "You do not appear to be banned",
34
};
35
36
let userLogs;
37
38
try {
39
userLogs = await queryLogs(user, context);
40
} catch {
41
return {
42
error: "Could not determine your eligibility",
43
};
44
}
45
46
userLogs.sort((a, b) =>
47
parseInt(a.entity.properties.executed_at.integerValue) >
48
parseInt(b.entity.properties.executed_at.integerValue)
49
? -1
50
: 1,
51
);
52
53
const allowedTime =
54
parseInt(userLogs[0].entity.properties.executed_at.integerValue) +
55
2592000000;
56
57
if (Date.now() < allowedTime)
58
return {
59
can_appeal: false,
60
reason: `You must wait until ${new Date(
61
allowedTime,
62
).toLocaleString()} to submit an appeal`,
63
};
64
65
return { can_appeal: true, reason: "" };
66
}