diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-06-21 15:33:36 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-06-21 15:33:36 -0400 |
commit | 6eb42974bdd4da4f9a6d77c8fde4c19f9f0a351b (patch) | |
tree | 6b0490f7f17d5d663f0f764589328e8acb79dd22 /src/commands/dev/superUser.ts | |
parent | 5c3da90f441c321f55ae735d6002f4da91f2481e (diff) | |
download | tanzanite-6eb42974bdd4da4f9a6d77c8fde4c19f9f0a351b.tar.gz tanzanite-6eb42974bdd4da4f9a6d77c8fde4c19f9f0a351b.tar.bz2 tanzanite-6eb42974bdd4da4f9a6d77c8fde4c19f9f0a351b.zip |
fix(db): made it work now
Diffstat (limited to 'src/commands/dev/superUser.ts')
-rw-r--r-- | src/commands/dev/superUser.ts | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/commands/dev/superUser.ts b/src/commands/dev/superUser.ts new file mode 100644 index 0000000..c3ed0b0 --- /dev/null +++ b/src/commands/dev/superUser.ts @@ -0,0 +1,73 @@ +import { Constants } from 'discord-akairo'; +import { User } from 'discord.js'; +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { BushMessage } from '../../lib/extensions/BushMessage'; +import { Global } from '../../lib/models/Global'; + +export default class SuperUserCommand extends BushCommand { + public constructor() { + super('superuser', { + aliases: ['superuser', 'su'], + category: 'dev', + description: { + content: 'A command to manage superusers.', + usage: 'superuser <add/remove> <user>', + examples: ['superuser add IRONM00N'] + }, + clientPermissions: ['SEND_MESSAGES'], + ownerOnly: true + }); + } + *args(): unknown { + const action = yield { + id: 'action', + type: ['add', 'remove'], + match: Constants.ArgumentMatches.PHRASE, + prompt: { + start: 'Would you like to `add` or `remove` a user from the superuser list?', + retry: '{error} Choose if you would like to `add` or `remove` a user.', + required: true + } + }; + const user = yield { + id: 'user', + type: Constants.ArgumentTypes.USER, + match: Constants.ArgumentMatches.REST_CONTENT, + prompt: { + start: `Who would you like to ${action || 'add/remove'} from the superuser list?`, + retry: `Choose a valid user to ${action || 'add/remove'} from the superuser list.`, + required: true + } + }; + return { action, user }; + } + public async exec(message: BushMessage, args: { action: 'add' | 'remove'; user: User }): Promise<unknown> { + if (!this.client.config.owners.includes(message.author.id)) + return await message.util.reply(`${this.client.util.emojis.error} Only my developers can run this command...`); + + const superUsers = (await Global.findByPk(this.client.config.dev ? 'development' : 'production')).superUsers; + let success; + if (args.action === 'add') { + if (superUsers.includes(args.user.id)) { + return message.util.reply(`${this.client.util.emojis.warn} \`${args.user.tag}\` is already a superuser.`); + } + success = await this.client.util.insertOrRemoveFromGlobal('add', 'superUsers', args.user.id).catch(() => false); + } else { + if (!superUsers.includes(args.user.id)) { + return message.util.reply(`${this.client.util.emojis.warn} \`${args.user.tag}\` is not superuser.`); + } + success = await this.client.util.insertOrRemoveFromGlobal('remove', 'superUsers', args.user.id).catch(() => false); + } + if (success) { + const responses = [args.action == 'remove' ? `` : 'made', args.action == 'remove' ? 'is no longer' : '']; + return message.util.reply( + `${this.client.util.emojis.success} ${responses[0]} \`${args.user.tag}\` ${responses[1]} a superuser.` + ); + } else { + const response = [args.action == 'remove' ? `removing` : 'making', args.action == 'remove' ? `from` : 'to']; + return message.util.reply( + `${this.client.util.emojis.error} There was an error ${response[0]} \`${args.user.tag}\` ${response[1]} the superuser list.` + ); + } + } +} |