2018-09-02 10:07:40 +00:00
|
|
|
import sql from "./sql";
|
|
|
|
|
|
|
|
export let admins = [];
|
2019-04-25 01:20:20 +00:00
|
|
|
|
|
|
|
export const loadAdmins = async () => {
|
|
|
|
const db = await sql;
|
2018-09-02 10:07:40 +00:00
|
|
|
admins = [];
|
2019-04-25 01:20:20 +00:00
|
|
|
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
|
|
|
});
|
2019-04-25 01:20:20 +00:00
|
|
|
}))
|
2018-09-02 10:07:40 +00:00
|
|
|
.catch(err => {
|
2019-04-25 01:20:20 +00:00
|
|
|
console.log("keine Admins vorhanden", err);
|
2018-09-02 10:07:40 +00:00
|
|
|
});
|
|
|
|
};
|
2019-04-25 01:20:20 +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;
|
|
|
|
};
|