blob: 6f7d9b41722f326737c3bcb8a225153040d7a847 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
}
|