Uwev2/src/inc/admin.mjs

42 lines
956 B
JavaScript
Raw Normal View History

2017-12-04 11:22:53 +00:00
import sql from "./sql";
2017-11-25 12:31:26 +00:00
export let admins = [];
2017-11-25 23:26:39 +00:00
export const loadAdmins = () => {
admins = [];
2017-11-28 01:27:25 +00:00
sql.any(`select * from admins`)
2017-11-25 12:31:26 +00:00
.then(rows => {
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");
});
2017-11-25 23:26:39 +00:00
};
loadAdmins();
2017-11-25 12:31:26 +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;
};