forked from engineering/cloudservices
add new interval which automatically updates permissions based on roles
parent
febb9ee924
commit
56a2b3eabf
|
@ -0,0 +1,30 @@
|
||||||
|
/* eslint-disable no-await-in-loop */
|
||||||
|
import { Client } from '..';
|
||||||
|
|
||||||
|
export default function checkStaffStatus(client: Client) {
|
||||||
|
setInterval(async () => {
|
||||||
|
const accounts = await client.db.Account.find();
|
||||||
|
for (const acc of accounts) {
|
||||||
|
const user = client.guilds.get('446067825673633794').members.get(acc.userID) ?? await client.guilds.get('446067825673633794').getRESTMember(acc.userID);
|
||||||
|
if (!acc.permissions.facultyMarshal && user.roles.includes('662163685439045632')) {
|
||||||
|
await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.facultyMarshal': true } });
|
||||||
|
}
|
||||||
|
if (!acc.permissions.sheriff && user.roles.includes('455972169449734144')) {
|
||||||
|
await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.sheriff': true } });
|
||||||
|
}
|
||||||
|
if (!acc.permissions.staff && user.roles.includes('446104438969466890')) {
|
||||||
|
await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.staff': true } });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (acc.permissions.facultyMarshal && !user.roles.includes('662163685439045632')) {
|
||||||
|
await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.facultyMarshal': false } });
|
||||||
|
}
|
||||||
|
if (acc.permissions.sheriff && !user.roles.includes('455972169449734144')) {
|
||||||
|
await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.sheriff': false } });
|
||||||
|
}
|
||||||
|
if (acc.permissions.staff && !user.roles.includes('446104438969466890')) {
|
||||||
|
await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.staff': false } });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 300000);
|
||||||
|
}
|
Loading…
Reference in New Issue