From 95fed59b18d9e3131a210004177611aabc495474 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Mon, 6 Sep 2021 17:23:33 -0400 Subject: superUser sync and config command fix --- src/tasks/updateSuperUsers.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/tasks/updateSuperUsers.ts (limited to 'src/tasks') diff --git a/src/tasks/updateSuperUsers.ts b/src/tasks/updateSuperUsers.ts new file mode 100644 index 0000000..5b1555f --- /dev/null +++ b/src/tasks/updateSuperUsers.ts @@ -0,0 +1,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: 300_000, // 5 minutes + runOnStart: true + }); + } + public override async exec(): Promise { + 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.'); + } +} -- cgit