forked from engineering/cloudservices
75 lines
4.1 KiB
TypeScript
75 lines
4.1 KiB
TypeScript
/* eslint-disable no-await-in-loop */
|
|
import { MessageEmbed, TextChannel } from 'discord.js';
|
|
import { Client } 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 });
|
|
let user = client.guilds.cache.get('446067825673633794').members.cache.get(acc.userID);
|
|
try {
|
|
if (!user) user = await client.guilds.cache.get('446067825673633794').members.fetch(acc.userID);
|
|
} catch (error) {
|
|
continue; // eslint-disable-line no-continue
|
|
}
|
|
|
|
if (!acc.permissions.director && user.roles.cache.has('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.cache.has('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.cache.has('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.intern && user.roles.cache.has('701481967149121627')) {
|
|
await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.intern': 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.cache.has('662163685439045632')) {
|
|
await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.director': false } });
|
|
}
|
|
if (acc.permissions.technician && !user.roles.cache.has('701454780828221450')) {
|
|
await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.technician': false } });
|
|
}
|
|
if (acc.permissions.staff && !user.roles.cache.has('446104438969466890')) {
|
|
await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.staff': false } });
|
|
}
|
|
if (acc.permissions.intern && !user.roles.cache.has('701481967149121627')) {
|
|
await client.db.Account.updateOne({ username: acc.username }, { $set: { 'permissions.intern': false } });
|
|
}
|
|
|
|
if ((acc.permissions.staff || acc.permissions.intern || acc.permissions.technician || acc.permissions.director || user.roles.cache.has('858049948401401866')) && acc.tier < 3) {
|
|
await client.db.Account.updateOne({ username: acc.username }, { $set: { tier: 3 } });
|
|
const embed = new MessageEmbed();
|
|
embed.setTitle('Cloud Account | Tier Change');
|
|
embed.setColor('#0099ff');
|
|
embed.addField('User', `${acc.username} | <@${acc.userID}>`, true);
|
|
embed.addField('Technician', 'SYSTEM', true);
|
|
embed.addField('Old Tier -> New Tier', `${acc.tier} -> 3`, true);
|
|
embed.addField('Reason', 'T3 Staff Benefit', true);
|
|
embed.setFooter(client.user.username, client.user.avatarURL());
|
|
embed.setTimestamp();
|
|
const ch = await client.channels.fetch('580950455581147146') as TextChannel;
|
|
ch.send({ embeds: [embed] });
|
|
client.users.fetch(acc.userID).then((chan) => {
|
|
chan.send('***Your CS Account tier has been upgraded to `Tier 3` automatically as apart of your staff benefit.***');
|
|
});
|
|
}
|
|
}
|
|
}, 300000);
|
|
}
|