aboutsummaryrefslogtreecommitdiff
path: root/src/commands/config
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/config')
-rw-r--r--src/commands/config/autoPublishChannel.ts21
-rw-r--r--src/commands/config/blacklist.ts132
-rw-r--r--src/commands/config/disable.ts128
-rw-r--r--src/commands/config/prefix.ts20
4 files changed, 283 insertions, 18 deletions
diff --git a/src/commands/config/autoPublishChannel.ts b/src/commands/config/autoPublishChannel.ts
index 421e030..a2692e2 100644
--- a/src/commands/config/autoPublishChannel.ts
+++ b/src/commands/config/autoPublishChannel.ts
@@ -1,4 +1,4 @@
-import { BushCommand, BushMessage } from '@lib';
+import { AllowedMentions, BushCommand, BushMessage } from '@lib';
import { Channel } from 'discord.js';
export default class AutoPublishChannelCommand extends BushCommand {
@@ -40,14 +40,17 @@ export default class AutoPublishChannelCommand extends BushCommand {
public async exec(message: BushMessage, { channel }: { channel: Channel }): Promise<unknown> {
const autoPublishChannels = await message.guild.getSetting('autoPublishChannels');
- autoPublishChannels.includes(channel.id)
- ? autoPublishChannels.splice(autoPublishChannels.indexOf(channel.id), 1)
- : autoPublishChannels.push(channel.id);
- await message.guild.setSetting('autoPublishChannels', autoPublishChannels);
- return await message.util.reply(
- `${this.client.util.emojis.success} Successfully ${
- autoPublishChannels.includes(channel.id) ? 'disabled' : 'enabled'
- } auto publishing in <#${channel.id}>.`
+ const newValue = this.client.util.addOrRemoveFromArray(
+ autoPublishChannels.includes(channel.id) ? 'remove' : 'add',
+ autoPublishChannels,
+ channel.id
);
+ await message.guild.setSetting('autoPublishChannels', newValue);
+ return await message.util.reply({
+ content: `${this.client.util.emojis.success} Successfully ${
+ autoPublishChannels.includes(channel.id) ? 'disabled' : 'enabled'
+ } auto publishing in <#${channel.id}>.`,
+ allowedMentions: AllowedMentions.none()
+ });
}
}
diff --git a/src/commands/config/blacklist.ts b/src/commands/config/blacklist.ts
new file mode 100644
index 0000000..4706041
--- /dev/null
+++ b/src/commands/config/blacklist.ts
@@ -0,0 +1,132 @@
+import { AllowedMentions, BushCommand, BushMessage, BushSlashMessage, Global } from '@lib';
+import { Argument } from 'discord-akairo';
+import { Channel, User } from 'discord.js';
+
+export default class BlacklistCommand extends BushCommand {
+ public constructor() {
+ super('blacklist', {
+ aliases: ['blacklist', 'unblacklist'],
+ category: 'config',
+ description: {
+ content: 'A command to blacklist users and channels.',
+ usage: 'blacklist|unblacklist <user|channel>',
+ examples: ['blacklist @user', 'unblacklist #channel']
+ },
+ args: [
+ {
+ id: 'target',
+ type: Argument.union('channel', 'user'),
+ match: 'phrase',
+ prompt: {
+ start: 'What channel or user that you would like to blacklist/unblacklist?',
+ retry: '{error} Pick a valid command.',
+ optional: false
+ }
+ },
+ {
+ id: 'global',
+ match: 'flag',
+ flag: '--global'
+ }
+ ],
+ slash: true,
+ slashOptions: [
+ {
+ name: 'action',
+ description: 'Would you like to add or remove someone or something from/to the blacklist?',
+ type: 'STRING',
+ choices: [
+ {
+ name: 'blacklist',
+ value: 'blacklist'
+ },
+ {
+ name: 'unblacklist',
+ value: 'unblacklist'
+ }
+ ],
+ required: true
+ },
+ {
+ name: 'target',
+ description: 'What channel or user that you would like to blacklist/unblacklist?',
+ type: 'STRING',
+ required: true
+ }
+ ],
+ channel: 'guild',
+ clientPermissions: ['SEND_MESSAGES'],
+ userPermissions: ['SEND_MESSAGES', 'MANAGE_GUILD']
+ });
+ }
+
+ public async exec(
+ message: BushMessage | BushSlashMessage,
+ args: { action: 'blacklist' | 'unblacklist'; target: Channel | User | string; global: boolean }
+ ): Promise<unknown> {
+ let action: 'blacklist' | 'unblacklist' | 'toggle' =
+ args.action ?? (message?.util?.parsed?.alias as 'blacklist' | 'unblacklist') ?? 'toggle';
+ const global = args.global && message.author.isOwner();
+ const target =
+ typeof args.target === 'string'
+ ? (await Argument.cast('channel', this.client.commandHandler.resolver, message as BushMessage, args.target)) ??
+ (await Argument.cast('user', this.client.commandHandler.resolver, message as BushMessage, args.target))
+ : args.target;
+ if (!target) return await message.util.reply(`${this.client.util.emojis.error} Choose a valid channel or user.`);
+ const targetID = target.id;
+
+ if (global) {
+ if (action === 'toggle') {
+ const blacklistedUsers = (await Global.findByPk(this.client.config.dev ? 'development' : 'production'))
+ .blacklistedUsers;
+ const blacklistedChannels = (await Global.findByPk(this.client.config.dev ? 'development' : 'production'))
+ .blacklistedChannels;
+ action = blacklistedUsers.includes(targetID) || blacklistedChannels.includes(targetID) ? 'unblacklist' : 'blacklist';
+ }
+ const success = await this.client.util
+ .insertOrRemoveFromGlobal(
+ action === 'blacklist' ? 'add' : 'remove',
+ target instanceof User ? 'blacklistedUsers' : 'blacklistedChannels',
+ targetID
+ )
+ .catch(() => false);
+ if (!success)
+ return await message.util.reply({
+ content: `${this.client.util.emojis.error} There was an error globally **${action}ing** ${
+ target?.tag ?? target.name
+ }.`,
+ allowedMentions: AllowedMentions.none()
+ });
+ else
+ return await message.util.reply({
+ content: `${this.client.util.emojis.success} Successfully **${action}ed** ${target?.tag ?? target.name} globally.`,
+ allowedMentions: AllowedMentions.none()
+ });
+ // guild disable
+ } else {
+ const blacklistedChannels = await message.guild.getSetting('blacklistedChannels');
+ const blacklistedUsers = await message.guild.getSetting('blacklistedUsers');
+ if (action === 'toggle') {
+ action = blacklistedChannels.includes(targetID) ?? blacklistedUsers.includes(targetID) ? 'unblacklist' : 'blacklist';
+ }
+ const newValue = this.client.util.addOrRemoveFromArray(
+ action === 'blacklist' ? 'add' : 'remove',
+ target instanceof User ? blacklistedUsers : blacklistedChannels,
+ targetID
+ );
+ const success = await message.guild
+ .setSetting(target instanceof User ? 'blacklistedUsers' : 'blacklistedChannels', newValue)
+ .catch(() => false);
+ if (!success)
+ return await message.util.reply({
+ content: `${this.client.util.emojis.error} There was an error **${action}ing** ${target?.tag ?? target.name}.`,
+ allowedMentions: AllowedMentions.none()
+ });
+ else
+ return await message.util.reply({
+ content: `${this.client.util.emojis.success} Successfully **${action}ed** ${target?.tag ?? target.name}.`,
+ allowedMentions: AllowedMentions.none()
+ });
+ }
+ }
+}
diff --git a/src/commands/config/disable.ts b/src/commands/config/disable.ts
new file mode 100644
index 0000000..007cdb1
--- /dev/null
+++ b/src/commands/config/disable.ts
@@ -0,0 +1,128 @@
+import { AllowedMentions, BushCommand, BushMessage, BushSlashMessage, Global } from '@lib';
+
+export default class DisableCommand extends BushCommand {
+ public constructor() {
+ super('disable', {
+ aliases: ['disable', 'enable'],
+ category: 'config',
+ description: {
+ content: 'A command to disable and enable commands.',
+ usage: 'disable|enable <command>',
+ examples: ['enable ban', 'disable kick']
+ },
+ args: [
+ {
+ id: 'command',
+ type: 'commandAlias',
+ match: 'phrase',
+ prompt: {
+ start: 'What command would you like to enable/disable?',
+ retry: '{error} Pick a valid command.',
+ optional: false
+ }
+ },
+ {
+ id: 'global',
+ match: 'flag',
+ flag: '--global'
+ }
+ ],
+ slash: true,
+ slashOptions: [
+ {
+ name: 'action',
+ description: 'Would you like to disable or enable a command?',
+ type: 'STRING',
+ choices: [
+ {
+ name: 'enable',
+ value: 'enable'
+ },
+ {
+ name: 'disable',
+ value: 'disable'
+ }
+ ],
+ required: true
+ },
+ {
+ name: 'command',
+ description: 'What command would you like to enable/disable?',
+ type: 'STRING',
+ required: true
+ }
+ ],
+ channel: 'guild',
+ clientPermissions: ['SEND_MESSAGES'],
+ userPermissions: ['SEND_MESSAGES', 'MANAGE_GUILD']
+ });
+ }
+
+ blacklistedCommands = ['eval', 'disable'];
+
+ public async exec(
+ message: BushMessage | BushSlashMessage,
+ args: { action: 'enable' | 'disable'; command: BushCommand | string; global: boolean }
+ ): Promise<unknown> {
+ let action: 'disable' | 'enable' | 'toggle' =
+ args.action ?? (message?.util?.parsed?.alias as 'disable' | 'enable') ?? 'toggle';
+ const global = args.global && message.author.isOwner();
+ const commandID = (args.command as BushCommand).id;
+
+ if (global) {
+ if (action === 'toggle') {
+ const disabledCommands = (await Global.findByPk(this.client.config.dev ? 'development' : 'production'))
+ .disabledCommands;
+ action = disabledCommands.includes(commandID) ? 'disable' : 'enable';
+ }
+ const success = await this.client.util
+ .insertOrRemoveFromGlobal(action === 'disable' ? 'remove' : 'add', 'disabledCommands', commandID)
+ .catch(() => false);
+ if (!success)
+ return await message.util.reply({
+ content: `${this.client.util.emojis.error} There was an error globally **${action.substr(
+ 0,
+ action.length - 2
+ )}ing** the **${commandID}** command.`,
+ allowedMentions: AllowedMentions.none()
+ });
+ else
+ return await message.util.reply({
+ content: `${this.client.util.emojis.success} Successfully **${action.substr(
+ 0,
+ action.length - 2
+ )}ed** the **${commandID}** command globally.`,
+ allowedMentions: AllowedMentions.none()
+ });
+
+ // guild disable
+ } else {
+ const disabledCommands = await message.guild.getSetting('disabledCommands');
+ if (action === 'toggle') {
+ action = disabledCommands.includes(commandID) ? 'disable' : 'enable';
+ }
+ const newValue = this.client.util.addOrRemoveFromArray(
+ action === 'disable' ? 'remove' : 'add',
+ disabledCommands,
+ commandID
+ );
+ const success = await message.guild.setSetting('disabledCommands', newValue).catch(() => false);
+ if (!success)
+ return await message.util.reply({
+ content: `${this.client.util.emojis.error} There was an error **${action.substr(
+ 0,
+ action.length - 2
+ )}ing** the **${commandID}** command.`,
+ allowedMentions: AllowedMentions.none()
+ });
+ else
+ return await message.util.reply({
+ content: `${this.client.util.emojis.success} Successfully **${action.substr(
+ 0,
+ action.length - 2
+ )}ed** the **${commandID}** command.`,
+ allowedMentions: AllowedMentions.none()
+ });
+ }
+ }
+}
diff --git a/src/commands/config/prefix.ts b/src/commands/config/prefix.ts
index 79956be..380442b 100644
--- a/src/commands/config/prefix.ts
+++ b/src/commands/config/prefix.ts
@@ -1,4 +1,4 @@
-import { BushCommand, BushMessage, BushSlashMessage } from '@lib';
+import { AllowedMentions, BushCommand, BushMessage, BushSlashMessage } from '@lib';
export default class PrefixCommand extends BushCommand {
public constructor() {
@@ -40,15 +40,17 @@ export default class PrefixCommand extends BushCommand {
const oldPrefix = await message.guild.getSetting('prefix');
await message.guild.setSetting('prefix', args.prefix ?? this.client.config.prefix);
if (args.prefix) {
- return await message.util.send(
- `${this.client.util.emojis.success} changed the server's prefix ${oldPrefix ? `from \`${oldPrefix}\`` : ''} to \`${
- args.prefix
- }\`.`
- );
+ return await message.util.send({
+ content: `${this.client.util.emojis.success} changed the server's prefix ${
+ oldPrefix ? `from \`${oldPrefix}\`` : ''
+ } to \`${args.prefix}\`.`,
+ allowedMentions: AllowedMentions.none()
+ });
} else {
- return await message.util.send(
- `${this.client.util.emojis.success} reset the server's prefix to \`${this.client.config.prefix}\`.`
- );
+ return await message.util.send({
+ content: `${this.client.util.emojis.success} reset the server's prefix to \`${this.client.config.prefix}\`.`,
+ allowedMentions: AllowedMentions.none()
+ });
}
}
}