From d952979c5ab76a572da7cf9eede76095be0dbb88 Mon Sep 17 00:00:00 2001 From: WlodekM Date: Sat, 10 Aug 2024 15:29:07 +0300 Subject: wip ranks --- ranks.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 ranks.js (limited to 'ranks.js') diff --git a/ranks.js b/ranks.js new file mode 100644 index 0000000..6f7d9b4 --- /dev/null +++ b/ranks.js @@ -0,0 +1,20 @@ +import fs from 'fs'; +import path from 'path'; +import * as accounts from './accounts.js' +import { commands } from "./commands.js"; + +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) { + let 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