59 lines
3.2 KiB
TypeScript
59 lines
3.2 KiB
TypeScript
/* eslint-disable no-await-in-loop */
|
|
import { Client } from '..';
|
|
import { RichEmbed } from '../class';
|
|
|
|
export default function checkStaffStatus(client: Client) {
|
|
setInterval(async () => {
|
|
const accounts = await client.db.Account.find();
|
|
for (const acc of accounts) {
|
|
const tier3 = await client.db.Tier.findOne({ id: 3 });
|
|
|
|
const user = client.guilds.get('446067825673633794').members.get(acc.userID) || await client.guilds.get('446067825673633794').getRESTMember(acc.userID);
|
|
if (!acc.permissions.director && user.roles.includes('662163685439045632')) {
|
|
await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.director': true } });
|
|
if (acc.ramLimitNotification !== -1) {
|
|
await client.db.Account.updateOne({ username: acc.username }, { $set: { ramLimitNotification: tier3.resourceLimits.ram - 20 } });
|
|
}
|
|
}
|
|
if (!acc.permissions.technician && user.roles.includes('701454780828221450')) {
|
|
await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.technician': true } });
|
|
if (acc.ramLimitNotification !== -1) {
|
|
await client.db.Account.updateOne({ username: acc.username }, { $set: { ramLimitNotification: tier3.resourceLimits.ram - 20 } });
|
|
}
|
|
}
|
|
if (!acc.permissions.staff && user.roles.includes('446104438969466890')) {
|
|
await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.staff': true } });
|
|
if (acc.ramLimitNotification !== -1) {
|
|
await client.db.Account.updateOne({ username: acc.username }, { $set: { ramLimitNotification: tier3.resourceLimits.ram - 20 } });
|
|
}
|
|
}
|
|
|
|
if (acc.permissions.director && !user.roles.includes('662163685439045632')) {
|
|
await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.director': false } });
|
|
}
|
|
if (acc.permissions.technician && !user.roles.includes('701454780828221450')) {
|
|
await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.technician': false } });
|
|
}
|
|
if (acc.permissions.staff && !user.roles.includes('446104438969466890')) {
|
|
await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.staff': false } });
|
|
}
|
|
|
|
if (acc.permissions.staff && acc.tier < 3) {
|
|
await client.db.Account.updateOne({ username: acc.username }, { $set: { tier: 3 } });
|
|
const embed = new RichEmbed();
|
|
embed.setTitle('Cloud Account | Tier Change');
|
|
embed.setColor('#0099ff');
|
|
embed.addField('User', `${acc.username} | <@${acc.userID}>`, true);
|
|
embed.addField('Moderator', `<@${client.user.id}>`, true);
|
|
embed.addField('Old Tier -> New Tier', `${acc.tier} -> 3`, true);
|
|
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
|
|
embed.setTimestamp();
|
|
this.client.createMessage('580950455581147146', { embed });
|
|
client.getDMChannel(acc.userID).then((chan) => {
|
|
chan.createMessage('***Your account has automatically been upgraded to Tier 3 since you are a Staff member.***');
|
|
});
|
|
}
|
|
}
|
|
}, 300000);
|
|
}
|