f0ckv2/src/inc/admin.mjs

45 lines
990 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 = [];
db.query(`select * from user`)
.then(rows => rows.forEach(row => {
admins.push({
id: row.id,
prefix: row.prefix,
account: row.account,
network: row.network,
level: row.level
2018-09-02 10:07:40 +00:00
});
}))
2018-09-02 10:07:40 +00:00
.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;
};