From 714a4189eb02051ddd330513048b07b3be070e27 Mon Sep 17 00:00:00 2001 From: WlodekM Date: Sat, 30 Nov 2024 14:24:39 +0200 Subject: do stuff 3 --- ranks.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 ranks.ts (limited to 'ranks.ts') diff --git a/ranks.ts b/ranks.ts new file mode 100644 index 0000000..78cab46 --- /dev/null +++ b/ranks.ts @@ -0,0 +1,20 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import * as accounts from './accounts.ts' +import { commands } from "./commands.ts"; + +export function getRankData(name) { + if (!/^[^\/\\]*$/g.exec(name)) return null; + if (!fs.existsSync(path.join('ranks', `${name}.json`))) return null; + return JSON.parse(fs.readFileSync(path.join('ranks', `${name}.json`))) +} + +export function canUserDoCommand(command, username, guest=false) { + let permissionLevel = 0; + if (!guest) { + const accountData = accounts.getAccountData(username); + if (getRankData(accountData?.admin ? 'admin' : accountData?.rank)) permissionLevel = getRankData(accountData?.admin ? 'admin' : accountData?.rank).level; + } + // Banned users can be given a rank with negative permissions so that no commands can be ran + return permissionLevel >= commands[command]?.level ?? 0 +} \ No newline at end of file -- cgit 1.4.1-2-gfad0