aboutsummaryrefslogtreecommitdiff
path: root/src/tasks/updateSuperUsers.ts
blob: e0e51f57b076a219083806a35492973a88fa757d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { BushTask } from '../lib/extensions/discord-akairo/BushTask';
import { Global } from '../lib/models/Global';

export default class UpdateSuperUsersTask extends BushTask {
	public constructor() {
		super('updateSuperUsers', {
			delay: 10_000,
			runOnStart: true
		});
	}
	public override async exec(): Promise<void> {
		const superUsers = client.guilds.cache
			.get(client.config.supportGuild.id)
			?.members.cache.filter(
				(member) =>
					(member.roles.cache.has('865954009280938056') || member.permissions.has('ADMINISTRATOR')) && !member.user.bot
			)
			.map((member) => member.id);

		const row =
			(await Global.findByPk(client.config.environment)) ?? (await Global.create({ environment: client.config.environment }));

		row.superUsers = superUsers ?? row.superUsers;
		client.cache.global.superUsers = superUsers ?? row.superUsers;
		await row.save();

		void client.logger.verbose(`updateSuperUsers`, 'Updated superusers.');
	}
}