aboutsummaryrefslogtreecommitdiff
path: root/src/commands/config
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/config')
-rw-r--r--src/commands/config/autoPublishChannel.ts6
-rw-r--r--src/commands/config/blacklist.ts13
-rw-r--r--src/commands/config/disable.ts13
-rw-r--r--src/commands/config/muteRole.ts2
-rw-r--r--src/commands/config/prefix.ts4
-rw-r--r--src/commands/config/punishmentFooter.ts2
-rw-r--r--src/commands/config/welcomeChannel.ts4
7 files changed, 26 insertions, 18 deletions
diff --git a/src/commands/config/autoPublishChannel.ts b/src/commands/config/autoPublishChannel.ts
index 3381dc2..f058402 100644
--- a/src/commands/config/autoPublishChannel.ts
+++ b/src/commands/config/autoPublishChannel.ts
@@ -29,7 +29,7 @@ export default class AutoPublishChannelCommand extends BushCommand {
name: 'channel',
description: 'What channel would you like me to send welcome messages in?',
type: 'CHANNEL',
- required: false
+ required: true
}
],
channel: 'guild',
@@ -39,13 +39,13 @@ export default class AutoPublishChannelCommand extends BushCommand {
}
public override async exec(message: BushMessage, { channel }: { channel: Channel }): Promise<unknown> {
- const autoPublishChannels = await message.guild.getSetting('autoPublishChannels');
+ const autoPublishChannels = await message.guild!.getSetting('autoPublishChannels');
const newValue = util.addOrRemoveFromArray(
autoPublishChannels.includes(channel.id) ? 'remove' : 'add',
autoPublishChannels,
channel.id
);
- await message.guild.setSetting('autoPublishChannels', newValue);
+ await message.guild!.setSetting('autoPublishChannels', newValue);
return await message.util.reply({
content: `${util.emojis.success} Successfully ${
autoPublishChannels.includes(channel.id) ? 'disabled' : 'enabled'
diff --git a/src/commands/config/blacklist.ts b/src/commands/config/blacklist.ts
index 864081c..57c3015 100644
--- a/src/commands/config/blacklist.ts
+++ b/src/commands/config/blacklist.ts
@@ -75,9 +75,12 @@ export default class BlacklistCommand extends BushCommand {
const targetID = target.id;
if (global) {
- if (action === 'toggle') {
- const blacklistedUsers = (await Global.findByPk(client.config.environment)).blacklistedUsers;
- const blacklistedChannels = (await Global.findByPk(client.config.environment)).blacklistedChannels;
+ if ((action as 'blacklist' | 'unblacklist' | 'toggle') === 'toggle') {
+ const globalDB =
+ (await Global.findByPk(client.config.environment)) ??
+ (await Global.create({ environment: client.config.environment }));
+ const blacklistedUsers = globalDB.blacklistedUsers;
+ const blacklistedChannels = globalDB.blacklistedChannels;
action = blacklistedUsers.includes(targetID) || blacklistedChannels.includes(targetID) ? 'unblacklist' : 'blacklist';
}
const success = await util
@@ -99,9 +102,11 @@ export default class BlacklistCommand extends BushCommand {
});
// guild disable
} else {
+ if (!message.guild)
+ return await message.util.reply(`${util.emojis.error} You have to be in a guild to disable commands.`);
const blacklistedChannels = (await message.guild.getSetting('blacklistedChannels')) ?? [];
const blacklistedUsers = (await message.guild.getSetting('blacklistedUsers')) ?? [];
- if (action === 'toggle') {
+ if ((action as 'blacklist' | 'unblacklist' | 'toggle') === 'toggle') {
action = blacklistedChannels.includes(targetID) ?? blacklistedUsers.includes(targetID) ? 'unblacklist' : 'blacklist';
}
const newValue = util.addOrRemoveFromArray(
diff --git a/src/commands/config/disable.ts b/src/commands/config/disable.ts
index a9318a5..bc6ed47 100644
--- a/src/commands/config/disable.ts
+++ b/src/commands/config/disable.ts
@@ -69,8 +69,11 @@ export default class DisableCommand extends BushCommand {
const commandID = (args.command as BushCommand).id;
if (global) {
- if (action === 'toggle') {
- const disabledCommands = (await Global.findByPk(client.config.environment)).disabledCommands;
+ if ((action as 'disable' | 'enable' | 'toggle') === 'toggle') {
+ const disabledCommands = (
+ (await Global.findByPk(client.config.environment)) ??
+ (await Global.create({ environment: client.config.environment }))
+ ).disabledCommands;
action = disabledCommands.includes(commandID) ? 'disable' : 'enable';
}
const success = await util
@@ -95,12 +98,12 @@ export default class DisableCommand extends BushCommand {
// guild disable
} else {
- const disabledCommands = await message.guild.getSetting('disabledCommands');
- if (action === 'toggle') {
+ const disabledCommands = await message.guild!.getSetting('disabledCommands');
+ if ((action as 'disable' | 'enable' | 'toggle') === 'toggle') {
action = disabledCommands.includes(commandID) ? 'disable' : 'enable';
}
const newValue = util.addOrRemoveFromArray(action === 'disable' ? 'remove' : 'add', disabledCommands, commandID);
- const success = await message.guild.setSetting('disabledCommands', newValue).catch(() => false);
+ const success = await message.guild!.setSetting('disabledCommands', newValue).catch(() => false);
if (!success)
return await message.util.reply({
content: `${util.emojis.error} There was an error **${action.substr(
diff --git a/src/commands/config/muteRole.ts b/src/commands/config/muteRole.ts
index dee5322..c7a6e75 100644
--- a/src/commands/config/muteRole.ts
+++ b/src/commands/config/muteRole.ts
@@ -38,7 +38,7 @@ export default class MuteRoleCommand extends BushCommand {
}
override async exec(message: BushMessage | BushSlashMessage, args: { role: Role }): Promise<void> {
- await message.guild.setSetting('muteRole', args.role.id);
+ await message.guild!.setSetting('muteRole', args.role.id);
await message.util.send({
content: `${util.emojis.success} Changed the server's mute role to <@&${args.role.id}>.`,
allowedMentions: AllowedMentions.none()
diff --git a/src/commands/config/prefix.ts b/src/commands/config/prefix.ts
index 9f80633..9d707e0 100644
--- a/src/commands/config/prefix.ts
+++ b/src/commands/config/prefix.ts
@@ -37,8 +37,8 @@ export default class PrefixCommand extends BushCommand {
}
override async exec(message: BushMessage | BushSlashMessage, args: { prefix?: string }): Promise<unknown> {
- const oldPrefix = await message.guild.getSetting('prefix');
- await message.guild.setSetting('prefix', args.prefix ?? client.config.prefix);
+ const oldPrefix = await message.guild!.getSetting('prefix');
+ await message.guild!.setSetting('prefix', args.prefix ?? client.config.prefix);
if (args.prefix) {
return await message.util.send({
content: `${util.emojis.success} changed the server's prefix ${oldPrefix ? `from \`${oldPrefix}\`` : ''} to \`${
diff --git a/src/commands/config/punishmentFooter.ts b/src/commands/config/punishmentFooter.ts
index d8daf77..d07ce4f 100644
--- a/src/commands/config/punishmentFooter.ts
+++ b/src/commands/config/punishmentFooter.ts
@@ -39,7 +39,7 @@ export default class PunishmentFooterCommand extends BushCommand {
}
override async exec(message: BushMessage | BushSlashMessage, args: { ending: string }): Promise<unknown> {
- await message.guild.setSetting('punishmentEnding', args.ending || null);
+ await message.guild!.setSetting('punishmentEnding', args.ending || '');
if (args.ending)
return await message.util.send({
content: `${util.emojis.success} Changed the server's punishment footer to \n\`\`\`${Util.cleanCodeBlockContent(
diff --git a/src/commands/config/welcomeChannel.ts b/src/commands/config/welcomeChannel.ts
index a662802..fc56607 100644
--- a/src/commands/config/welcomeChannel.ts
+++ b/src/commands/config/welcomeChannel.ts
@@ -37,8 +37,8 @@ export default class WelcomeChannelCommand extends BushCommand {
});
}
public override async exec(message: BushMessage | BushSlashMessage, args: { channel: Channel }): Promise<unknown> {
- const oldChannel = await message.guild.getSetting('welcomeChannel');
- await message.guild.setSetting('welcomeChannel', args.channel.id ?? undefined);
+ const oldChannel = await message.guild!.getSetting('welcomeChannel');
+ await message.guild!.setSetting('welcomeChannel', args.channel.id ?? undefined);
if (args.channel) {
return await message.util.send(
`${util.emojis.success} changed the server's welcome channel ${oldChannel ? `from <#${oldChannel}>` : ''} to <#${