f0ckv2/src/inc/admin.mjs

44 lines
1004 B
JavaScript
Raw Normal View History

2018-09-02 10:07:40 +00:00
import sql from "./sql";
export let admins = [];
export const loadAdmins = async () => {
const db = await sql;
2018-09-02 10:07:40 +00:00
admins = [];
2019-04-26 09:23:16 +00:00
try {
const rows = await db.query("select id, prefix, account, level, network from user");
rows.forEach(row => admins.push({
id: row.id,
prefix: row.prefix,
account: row.account,
network: row.network,
level: row.level
}));
} catch(err) {
console.log("keine Admins vorhanden", err);
}
2018-09-02 10:07:40 +00:00
};
(async () => {
await loadAdmins();
})();
2018-09-02 10:07:40 +00:00
export const getLevel = (network, user) => {
let ret = {
level: 0,
verified: false
};
if (typeof user !== "object")
return "user has to be an object!";
if (!user.account || !user.prefix)
return ret;
for(let admin of admins) {
if (admin.account === user.account.toLowerCase() && admin.network === network.toLowerCase()) {
ret = {
level: admin.level,
verified: user.prefix.toLowerCase() === admin.prefix
};
}
};
return ret;
};