Don't rely on metadata for appeals

This commit is contained in:
regalijan 2023-10-19 16:49:18 -04:00
parent 3d5b830827
commit 8d7e9bd93d
Signed by: regalijan
GPG Key ID: 5D4196DA269EF520
3 changed files with 11 additions and 11 deletions

View File

@ -1,7 +1,7 @@
export async function onRequestPost(context: RequestContext) { export async function onRequestPost(context: RequestContext) {
const { permissions } = context.data.current_user; const { permissions } = context.data.current_user;
if (!(permissions & (1 << 0)) || !(permissions & (1 << 11))) if (!(permissions & (1 << 0)) && !(permissions & (1 << 11)))
return new Response('{"error":"Forbidden"}', { return new Response('{"error":"Forbidden"}', {
headers: { headers: {
"content-type": "application/json", "content-type": "application/json",
@ -15,9 +15,9 @@ export async function onRequestPost(context: RequestContext) {
context.data.targetId = id; context.data.targetId = id;
if (!new URL(context.request.url).pathname.endsWith("/ban")) { if (!new URL(context.request.url).pathname.endsWith("/ban")) {
const keyWithMeta = await context.env.DATA.getWithMetadata(`appeal_${id}`); const key = await context.env.DATA.get(`appeal_${id}`);
if (!keyWithMeta.value) if (!key)
return new Response('{"error":"No appeal with that ID exists"}', { return new Response('{"error":"No appeal with that ID exists"}', {
headers: { headers: {
"content-type": "application/json", "content-type": "application/json",
@ -25,7 +25,7 @@ export async function onRequestPost(context: RequestContext) {
status: 404, status: 404,
}); });
context.data.appeal = keyWithMeta; context.data.appeal = key;
} }
if ( if (

View File

@ -1,8 +1,8 @@
export async function onRequestPost(context: RequestContext) { export async function onRequestPost(context: RequestContext) {
const { metadata, value } = context.data.appeal; const { appeal } = context.data;
const body = new FormData(); const body = new FormData();
body.append("from", "noreply@mail.carcrushers.cc"); body.append("from", "noreply@mail.carcrushers.cc");
body.append("to", value.email); body.append("to", appeal.email);
body.append("subject", "Appeal Accepted"); body.append("subject", "Appeal Accepted");
body.append("template", "appeal_accepted"); body.append("template", "appeal_accepted");
body.append("v:note", context.data.body.feedback || "No note provided."); body.append("v:note", context.data.body.feedback || "No note provided.");
@ -31,7 +31,7 @@ export async function onRequestPost(context: RequestContext) {
const { current_user: currentUser } = context.data; const { current_user: currentUser } = context.data;
await fetch( await fetch(
`https://discord.com/api/v10/guilds/242263977986359297/bans/${metadata.id}`, `https://discord.com/api/v10/guilds/242263977986359297/bans/${appeal.id}`,
{ {
headers: { headers: {
authorization: `Bot ${context.env.BOT_TOKEN}`, authorization: `Bot ${context.env.BOT_TOKEN}`,
@ -47,7 +47,7 @@ export async function onRequestPost(context: RequestContext) {
{ {
title: "Appeal Accepted", title: "Appeal Accepted",
color: 0x00ff00, color: 0x00ff00,
description: `Appeal from user ${metadata.tag} (${metadata.id}) was accepted.`, description: `Appeal from user ${appeal.username}#${appeal.discriminator} (${appeal.id}) was accepted.`,
fields: [ fields: [
{ {
name: "Moderator", name: "Moderator",

View File

@ -1,8 +1,8 @@
export async function onRequestPost(context: RequestContext) { export async function onRequestPost(context: RequestContext) {
const { metadata, value } = context.data.appeal; const { appeal } = context.data;
const body = new FormData(); const body = new FormData();
body.append("from", "noreply@mail.carcrushers.cc"); body.append("from", "noreply@mail.carcrushers.cc");
body.append("to", value.email); body.append("to", appeal.email);
body.append("subject", "Appeal Denied"); body.append("subject", "Appeal Denied");
body.append("template", "appeal_denied"); body.append("template", "appeal_denied");
body.append("v:note", context.data.body.feedback || "No note provided."); body.append("v:note", context.data.body.feedback || "No note provided.");
@ -36,7 +36,7 @@ export async function onRequestPost(context: RequestContext) {
{ {
title: "Appeal Denied", title: "Appeal Denied",
color: 0xff0000, color: 0xff0000,
description: `Appeal from user ${metadata.tag} (${metadata.id}) was denied.`, description: `Appeal from user ${appeal.username}#${appeal.discriminator} (${appeal.id}) was denied.`,
fields: [ fields: [
{ {
name: "Moderator", name: "Moderator",