diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-09-06 17:23:33 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-09-06 17:23:33 -0400 |
commit | 95fed59b18d9e3131a210004177611aabc495474 (patch) | |
tree | 2912050c76b3d67b88622f2b0ceb2e5beb71e218 /src | |
parent | 13306f17accea5d3653dd4b8670ba0d6ab69c7c5 (diff) | |
download | tanzanite-95fed59b18d9e3131a210004177611aabc495474.tar.gz tanzanite-95fed59b18d9e3131a210004177611aabc495474.tar.bz2 tanzanite-95fed59b18d9e3131a210004177611aabc495474.zip |
superUser sync and config command fix
Diffstat (limited to 'src')
-rw-r--r-- | src/commands/config/config.ts | 10 | ||||
-rw-r--r-- | src/tasks/updateSuperUsers.ts | 29 |
2 files changed, 35 insertions, 4 deletions
diff --git a/src/commands/config/config.ts b/src/commands/config/config.ts index cba4468..dc31b5b 100644 --- a/src/commands/config/config.ts +++ b/src/commands/config/config.ts @@ -3,6 +3,7 @@ import { ArgumentOptions, Flag } from 'discord-akairo'; import { Channel, Formatters, + GuildMember, Message, MessageActionRow, MessageButton, @@ -10,7 +11,8 @@ import { MessageEmbed, MessageOptions, MessageSelectMenu, - Role + Role, + User } from 'discord.js'; import _ from 'lodash'; @@ -203,8 +205,8 @@ export default class SettingsCommand extends BushCommand { const messageOptions = await this.generateMessageOptions(message, setting ?? undefined); msg = (await message.util.reply(messageOptions)) as Message; } else { - const parseVal = (val: string | Channel | Role) => { - if (val instanceof Channel || val instanceof Role) { + const parseVal = (val: string | Channel | Role | User | GuildMember) => { + if (val instanceof Channel || val instanceof Role || val instanceof User || val instanceof GuildMember) { return val.id; } return val; @@ -352,7 +354,7 @@ export default class SettingsCommand extends BushCommand { : client.config.isDevelopment ? 'dev ' : message.util.parsed?.prefix ?? client.config.prefix - }${message.util.parsed?.alias ?? 'config'} ${setting} ${ + }${message.util.parsed?.alias ?? 'config'} ${message.util.isSlash ? _.snakeCase(setting) : setting} ${ guildSettingsObj[setting].type.includes('-array') ? 'add/remove' : 'set' } <value>" to set this setting.` ); 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<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.'); + } +} |