Drop KV for et member management

This commit is contained in:
Regalijan 2024-02-01 13:06:13 -05:00
parent c57b2fd8ad
commit 98a9e0eff2
Signed by: regalijan
GPG Key ID: 5D4196DA269EF520
2 changed files with 12 additions and 12 deletions

View File

@ -11,7 +11,6 @@ export async function onRequestDelete(context: RequestContext) {
) )
return jsonError("Invalid ID", 400); return jsonError("Invalid ID", 400);
await context.env.DATA.delete(`etmember_${id}`);
await context.env.D1.prepare("DELETE FROM et_members WHERE id = ?;") await context.env.D1.prepare("DELETE FROM et_members WHERE id = ?;")
.bind(id) .bind(id)
.run(); .run();
@ -35,7 +34,11 @@ export async function onRequestPost(context: RequestContext) {
if (typeof name !== "string" || !name.length || name.length > 32) if (typeof name !== "string" || !name.length || name.length > 32)
return jsonError("Invalid name", 400); return jsonError("Invalid name", 400);
if (await context.env.DATA.get(`etmember_${id}`)) if (
await context.env.D1.prepare("SELECT * FROM et_members WHERE id = ?;")
.bind(id)
.first()
)
return jsonError("User is already a member", 400); return jsonError("User is already a member", 400);
if (!["string", "undefined"].includes(typeof roblox_username)) if (!["string", "undefined"].includes(typeof roblox_username))
@ -86,15 +89,6 @@ export async function onRequestPost(context: RequestContext) {
const createdAt = Date.now(); const createdAt = Date.now();
const addingUser = context.data.current_user.id; const addingUser = context.data.current_user.id;
await context.env.DATA.put(
`etmember_${id}`,
JSON.stringify({
created_at: createdAt,
created_by: addingUser,
name,
roblox_id,
}),
);
await context.env.D1.prepare( await context.env.D1.prepare(
"INSERT INTO et_members (created_at, created_by, id, name, roblox_id) VALUES (?, ?, ?, ?, ?);", "INSERT INTO et_members (created_at, created_by, id, name, roblox_id) VALUES (?, ?, ?, ?, ?);",
) )

View File

@ -8,7 +8,13 @@ export default async function (
if (roles?.includes("374851061233614849")) permissions |= 1 << 0; // Administration if (roles?.includes("374851061233614849")) permissions |= 1 << 0; // Administration
if (!roles) permissions |= 1 << 1; if (!roles) permissions |= 1 << 1;
if (roles?.includes("593209890949038082")) permissions |= 1 << 2; // Discord Moderator if (roles?.includes("593209890949038082")) permissions |= 1 << 2; // Discord Moderator
if (Boolean(await context.env.DATA.get(`etmember_${userid}`))) if (
Boolean(
await context.env.D1.prepare("SELECT * FROM et_members WHERE id = ?;")
.bind(userid)
.first(),
)
)
permissions |= 1 << 3; // Events Team permissions |= 1 << 3; // Events Team
if (roles?.includes("607697704419852289")) permissions |= 1 << 4; // Events Team Management if (roles?.includes("607697704419852289")) permissions |= 1 << 4; // Events Team Management
if ( if (