Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move appeal bans entirely to D1
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent 736543c commit eb550a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 7 additions & 5 deletions functions/api/appeals/[id]/ban.ts
Expand Up @@ -9,10 +9,12 @@ export async function onRequestPost(context: RequestContext) {
status: 400,
});

await context.env.DATA.put(
`appealban_${context.data.targetId}`,
JSON.stringify({ moderator: currentUser.id }),
);
await context.env.D1.prepare(
"INSERT INTO appeal_bans (created_at, created_by, user) VALUES (?, ?, ?);",
)
.bind(Date.now(), context.data.current_user.id, context.data.targetId)
.run();

await fetch(context.env.APPEALS_WEBHOOK, {
body: JSON.stringify({
embeds: [
Expand All @@ -23,7 +25,7 @@ export async function onRequestPost(context: RequestContext) {
fields: [
{
name: "Moderator",
value: `${currentUser.username}#${currentUser.discriminator} (${currentUser.id})`,
value: `${currentUser.username} (${currentUser.id})`,
},
],
},
Expand Down
8 changes: 7 additions & 1 deletion functions/api/appeals/submit.ts
Expand Up @@ -52,7 +52,13 @@ export async function onRequestPost(context: RequestContext) {
status: 403,
});

if (await context.env.DATA.get(`appealban_${currentUser.id}`)) {
if (
(
await context.env.D1.prepare("SELECT * FROM appeal_bans WHERE user = ?;")
.bind(currentUser.id)
.run()
).results.length
) {
await context.env.DATA.put(`blockedappeal_${currentUser.id}`, "1", {
metadata: { email: currentUser.email },
});
Expand Down

0 comments on commit eb550a7

Please sign in to comment.