diff options
Diffstat (limited to 'src/commands/config')
-rw-r--r-- | src/commands/config/muteRole.ts | 57 | ||||
-rw-r--r-- | src/commands/config/prefix.ts | 16 | ||||
-rw-r--r-- | src/commands/config/welcomeChannel.ts | 49 |
3 files changed, 117 insertions, 5 deletions
diff --git a/src/commands/config/muteRole.ts b/src/commands/config/muteRole.ts new file mode 100644 index 0000000..f51c5ce --- /dev/null +++ b/src/commands/config/muteRole.ts @@ -0,0 +1,57 @@ +import { Role } from 'discord.js'; +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { BushSlashMessage } from '../../lib/extensions/BushInteractionMessage'; +import { BushMessage } from '../../lib/extensions/BushMessage'; +import { Guild } from '../../lib/models'; +import AllowedMentions from '../../lib/utils/AllowedMentions'; + +export default class MuteRoleCommand extends BushCommand { + constructor() { + super('muteRole', { + aliases: ['muterole'], + category: 'config', + description: { + content: 'Set the prefix of the current server (resets to default if prefix is not given)', + usage: 'prefix [prefix]', + examples: ['prefix', 'prefix +'] + }, + clientPermissions: ['SEND_MESSAGES'], + userPermissions: ['SEND_MESSAGES', 'MANAGE_GUILD'], + args: [ + { + id: 'role', + type: 'role', + prompt: { + start: "What would you like to set the server's mute role to?", + retry: '{error} Choose a valid role.', + optional: false + } + } + ], + slash: true, + slashOptions: [ + { + type: 'ROLE', + name: 'role', + description: 'The mute role for this server.', + required: true + } + ] + }); + } + + async exec(message: BushMessage | BushSlashMessage, args: { role: Role }): Promise<void> { + let row = await Guild.findByPk(message.guild.id); + if (!row) { + row = Guild.build({ + id: message.guild.id + }); + } + row.muteRole = args.role.id; + await row.save(); + await message.util.send({ + content: `${this.client.util.emojis.success} Changed the mute role to <@&${args.role.id}>.`, + allowedMentions: AllowedMentions.none() + }); + } +} diff --git a/src/commands/config/prefix.ts b/src/commands/config/prefix.ts index 1326426..5b73a1a 100644 --- a/src/commands/config/prefix.ts +++ b/src/commands/config/prefix.ts @@ -1,6 +1,6 @@ -import { Message } from 'discord.js'; import { BushCommand } from '../../lib/extensions/BushCommand'; import { BushSlashMessage } from '../../lib/extensions/BushInteractionMessage'; +import { BushMessage } from '../../lib/extensions/BushMessage'; import { Guild } from '../../lib/models'; export default class PrefixCommand extends BushCommand { @@ -11,10 +11,16 @@ export default class PrefixCommand extends BushCommand { args: [ { id: 'prefix', - type: 'string' + type: 'string', + prompt: { + start: 'What would you like the new prefix to be?', + retry: '{error} Choose a valid prefix', + optional: true + } } ], - userPermissions: ['MANAGE_GUILD'], + clientPermissions: ['SEND_MESSAGES'], + userPermissions: ['SEND_MESSAGES', 'MANAGE_GUILD'], description: { content: 'Set the prefix of the current server (resets to default if prefix is not given)', usage: 'prefix [prefix]', @@ -32,7 +38,7 @@ export default class PrefixCommand extends BushCommand { }); } - async exec(message: Message | BushSlashMessage, { prefix }: { prefix?: string }): Promise<void> { + async exec(message: BushMessage | BushSlashMessage, { prefix }: { prefix?: string }): Promise<void> { let row = await Guild.findByPk(message.guild.id); if (!row) { row = Guild.build({ @@ -41,7 +47,7 @@ export default class PrefixCommand extends BushCommand { } await row.update({ prefix: prefix || this.client.config.prefix }); if (prefix) { - await message.util.send(`${this.client.util.emojis.success} changed prefix from \`${prefix}\``); + await message.util.send(`${this.client.util.emojis.success} changed prefix from \`${prefix}\` to `); } else { await message.util.send(`${this.client.util.emojis.success} reset prefix to \`${this.client.config.prefix}\``); } diff --git a/src/commands/config/welcomeChannel.ts b/src/commands/config/welcomeChannel.ts new file mode 100644 index 0000000..72e55f1 --- /dev/null +++ b/src/commands/config/welcomeChannel.ts @@ -0,0 +1,49 @@ +import { User } from 'discord.js'; +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { BushMessage } from '../../lib/extensions/BushMessage'; +import { Global } from '../../lib/models'; + +export default class WelcomeChannelCommand extends BushCommand { + public constructor() { + super('welcomeChannel', { + aliases: ['welcomechannel', 'wc'], + category: 'config', + description: { + content: 'Configure the what channel you want the bot to send a message in when someone joins the server.', + usage: 'welcomechannel [channel]', + examples: ['welcomechannel #welcome'] + }, + clientPermissions: ['SEND_MESSAGES'], + ownerOnly: true + }); + } + 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.` + ); + } + } +} |