76 lines
2.1 KiB
TypeScript
76 lines
2.1 KiB
TypeScript
import { getBanList, setBanList } from "../../../roblox-open-cloud.js";
|
|
import { jsonError } from "../../../common.js";
|
|
|
|
export async function onRequestPost(context: RequestContext) {
|
|
const { statsReduction } = context.data.body;
|
|
|
|
if (statsReduction && typeof statsReduction !== "number")
|
|
return jsonError("Invalid stat reduction", 400);
|
|
|
|
const appeal: Record<string, any> | null = await context.env.D1.prepare(
|
|
"SELECT * FROM game_appeals WHERE id = ?;",
|
|
)
|
|
.bind(context.params.id)
|
|
.first();
|
|
|
|
if (!appeal) return jsonError("Appeal not found", 400);
|
|
|
|
const banList = (await getBanList(context)) as {
|
|
[k: string]: {
|
|
BanType: number;
|
|
hidden_from_leaderboards?: boolean;
|
|
serverconfigurator_blacklist?: boolean;
|
|
Unbanned?: boolean;
|
|
UnbanReduct?: number;
|
|
};
|
|
};
|
|
|
|
await context.env.D1.prepare("DELETE FROM game_appeals WHERE id = ?;")
|
|
.bind(context.params.id)
|
|
.run();
|
|
|
|
if (!banList[appeal.roblox_id]?.BanType)
|
|
return new Response(null, {
|
|
status: 204,
|
|
});
|
|
|
|
if (banList[appeal.roblox_id].BanType === 2) {
|
|
banList[appeal.roblox_id] = {
|
|
BanType: 0,
|
|
Unbanned: true,
|
|
UnbanReduct: statsReduction,
|
|
};
|
|
} else if (appeal.type === "server configurator") {
|
|
banList[appeal.roblox_id] = {
|
|
...banList[appeal.roblox_id],
|
|
serverconfigurator_blacklist: false,
|
|
};
|
|
} else if (appeal.type === "blacklist") {
|
|
banList[appeal.roblox_id] = {
|
|
...banList[appeal.roblox_id],
|
|
hidden_from_leaderboards: false,
|
|
Unbanned: true,
|
|
UnbanReduct: statsReduction,
|
|
};
|
|
}
|
|
|
|
await context.env.D1.prepare(
|
|
"INSERT INTO game_mod_logs (action, evidence, executed_at, executor, id, target) VALUES (?, ?, ?, ?, ?, ?);",
|
|
)
|
|
.bind(
|
|
`accept appeal | ${banList[appeal.roblox_id]?.BanType === 2 ? "ban" : appeal.type}`,
|
|
`https://carcrushers.cc/mod-queue?id=${context.params.id}&type=gma`,
|
|
Date.now(),
|
|
context.data.current_user.id,
|
|
crypto.randomUUID(),
|
|
appeal.roblox_id,
|
|
)
|
|
.run();
|
|
|
|
await setBanList(context, banList);
|
|
|
|
return new Response(null, {
|
|
status: 204,
|
|
});
|
|
}
|