aboutsummaryrefslogtreecommitdiff
path: root/src/commands/config
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/config')
-rw-r--r--src/commands/config/blacklist.ts7
-rw-r--r--src/commands/config/config.ts16
-rw-r--r--src/commands/config/disable.ts6
-rw-r--r--src/commands/config/features.ts9
-rw-r--r--src/commands/config/log.ts4
5 files changed, 27 insertions, 15 deletions
diff --git a/src/commands/config/blacklist.ts b/src/commands/config/blacklist.ts
index d210472..ba2d24a 100644
--- a/src/commands/config/blacklist.ts
+++ b/src/commands/config/blacklist.ts
@@ -1,4 +1,5 @@
import { AllowedMentions, BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib';
+import assert from 'assert';
import { ApplicationCommandOptionType, PermissionFlagsBits, User } from 'discord.js';
export default class BlacklistCommand extends BushCommand {
@@ -40,7 +41,6 @@ export default class BlacklistCommand extends BushCommand {
}
],
slash: true,
- channel: 'guild',
clientPermissions: (m) => util.clientSendAndPermCheck(m),
userPermissions: [PermissionFlagsBits.ManageGuild]
});
@@ -64,8 +64,11 @@ export default class BlacklistCommand extends BushCommand {
if (!target) return await message.util.reply(`${util.emojis.error} Choose a valid channel or user.`);
const targetID = target.id;
- if (!message.guild && global)
+ if (!message.inGuild() && !global)
return await message.util.reply(`${util.emojis.error} You have to be in a guild to disable commands.`);
+
+ if (!global) assert(message.inGuild());
+
const blacklistedUsers = global
? util.getGlobal('blacklistedUsers')
: (await message.guild!.getSetting('blacklistedChannels')) ?? [];
diff --git a/src/commands/config/config.ts b/src/commands/config/config.ts
index 2fae2fd..f860b30 100644
--- a/src/commands/config/config.ts
+++ b/src/commands/config/config.ts
@@ -208,8 +208,10 @@ export default class ConfigCommand extends BushCommand {
value: ArgType<'channel'> | ArgType<'role'> | string;
}
) {
- if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be used in servers.`);
- if (!message.member?.permissions.has(PermissionFlagsBits.ManageGuild) && !message.member?.user.isOwner())
+ assert(message.inGuild());
+ assert(message.member);
+
+ if (!message.member.permissions.has(PermissionFlagsBits.ManageGuild) && !message.member?.user.isOwner())
return await message.util.reply(`${util.emojis.error} You must have the **Manage Server** permission to run this command.`);
const setting = message.util.isSlash ? (_.camelCase(args.subcommandGroup)! as GuildSettings) : args.setting!;
const action = message.util.isSlash ? args.subcommand! : args.action!;
@@ -263,7 +265,8 @@ export default class ConfigCommand extends BushCommand {
collector.on('collect', async (interaction: MessageComponentInteraction) => {
if (interaction.user.id === message.author.id || client.config.owners.includes(interaction.user.id)) {
- if (!message.guild) throw new Error('message.guild is null');
+ assert(message.inGuild());
+
switch (interaction.customId) {
case 'command_settingsSel': {
if (!interaction.isSelectMenu()) return;
@@ -288,10 +291,11 @@ export default class ConfigCommand extends BushCommand {
message: BushMessage | BushSlashMessage,
setting?: undefined | keyof typeof guildSettingsObj
): Promise<MessageOptions & InteractionUpdateOptions> {
- if (!message.guild) throw new Error('message.guild is null');
+ assert(message.inGuild());
+
const settingsEmbed = new Embed().setColor(util.colors.default);
if (!setting) {
- settingsEmbed.setTitle(`${message.guild!.name}'s Settings`);
+ settingsEmbed.setTitle(`${message.guild.name}'s Settings`);
const desc = settingsArr.map((s) => `:wrench: **${guildSettingsObj[s].name}**`).join('\n');
settingsEmbed.setDescription(desc);
@@ -314,7 +318,7 @@ export default class ConfigCommand extends BushCommand {
} else {
settingsEmbed.setTitle(guildSettingsObj[setting].name);
const generateCurrentValue = async (type: GuildSettingType): Promise<string> => {
- const feat = await message.guild!.getSetting(setting);
+ const feat = await message.guild.getSetting(setting);
let func = (v: string) => v;
switch (type.replace('-array', '') as BaseSettingTypes) {
case 'string': {
diff --git a/src/commands/config/disable.ts b/src/commands/config/disable.ts
index a7ebfa2..db325fc 100644
--- a/src/commands/config/disable.ts
+++ b/src/commands/config/disable.ts
@@ -57,6 +57,8 @@ export default class DisableCommand extends BushCommand {
message: BushMessage | BushSlashMessage,
args: { action?: 'enable' | 'disable'; command: ArgType<'commandAlias'> | string; global: boolean }
) {
+ assert(message.inGuild());
+
let action = (args.action ?? message?.util?.parsed?.alias ?? 'toggle') as 'disable' | 'enable' | 'toggle';
const global = args.global && message.author.isOwner();
const commandID =
@@ -67,13 +69,13 @@ export default class DisableCommand extends BushCommand {
if (DisableCommand.blacklistedCommands.includes(commandID))
return message.util.send(`${util.emojis.error} the ${commandID} command cannot be disabled.`);
- const disabledCommands = global ? util.getGlobal('disabledCommands') : await message.guild!.getSetting('disabledCommands');
+ const disabledCommands = global ? util.getGlobal('disabledCommands') : await message.guild.getSetting('disabledCommands');
if (action === 'toggle') action = disabledCommands.includes(commandID) ? 'disable' : 'enable';
const newValue = util.addOrRemoveFromArray(action === 'disable' ? 'remove' : 'add', disabledCommands, commandID);
const success = global
? await util.setGlobal('disabledCommands', newValue).catch(() => false)
- : await message.guild!.setSetting('disabledCommands', newValue, message.member!).catch(() => false);
+ : await message.guild.setSetting('disabledCommands', newValue, message.member!).catch(() => false);
if (!success)
return await message.util.reply({
content: `${util.emojis.error} There was an error${global ? ' globally' : ''} **${action.substring(
diff --git a/src/commands/config/features.ts b/src/commands/config/features.ts
index 199f201..c9aebd3 100644
--- a/src/commands/config/features.ts
+++ b/src/commands/config/features.ts
@@ -6,6 +6,7 @@ import {
type BushSlashMessage,
type GuildFeatures
} from '#lib';
+import assert from 'assert';
import {
ActionRow,
ComponentType,
@@ -33,11 +34,11 @@ export default class FeaturesCommand extends BushCommand {
}
public override async exec(message: BushMessage | BushSlashMessage) {
- if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be used in servers.`);
+ assert(message.inGuild());
- const featureEmbed = new Embed().setTitle(`${message.guild!.name}'s Features`).setColor(util.colors.default);
+ const featureEmbed = new Embed().setTitle(`${message.guild.name}'s Features`).setColor(util.colors.default);
- const enabledFeatures = await message.guild!.getSetting('enabledFeatures');
+ const enabledFeatures = await message.guild.getSetting('enabledFeatures');
this.generateDescription(guildFeaturesArr, enabledFeatures, featureEmbed);
const components = this.generateComponents(guildFeaturesArr, false);
const msg = (await message.util.reply({ embeds: [featureEmbed], components: [components] })) as Message;
@@ -49,7 +50,7 @@ export default class FeaturesCommand extends BushCommand {
collector.on('collect', async (interaction: SelectMenuInteraction) => {
if (interaction.user.id === message.author.id || client.config.owners.includes(interaction.user.id)) {
- if (!message.guild) throw new Error('message.guild is null');
+ assert(message.inGuild());
const [selected]: GuildFeatures[] = interaction.values as GuildFeatures[];
diff --git a/src/commands/config/log.ts b/src/commands/config/log.ts
index 79f9258..f99f007 100644
--- a/src/commands/config/log.ts
+++ b/src/commands/config/log.ts
@@ -1,4 +1,5 @@
import { BushCommand, guildLogsArr, type ArgType, type BushMessage, type BushSlashMessage, type GuildLogType } from '#lib';
+import assert from 'assert';
import { ArgumentGeneratorReturn } from 'discord-akairo';
import { ApplicationCommandOptionType, ChannelType, PermissionFlagsBits } from 'discord.js';
@@ -72,7 +73,8 @@ export default class LogCommand extends BushCommand {
message: BushMessage | BushSlashMessage,
args: { log_type: GuildLogType; channel: ArgType<'textChannel'> }
) {
- if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be used in servers.`);
+ assert(message.inGuild());
+
const currentLogs = await message.guild.getSetting('logChannels');
const oldChannel = currentLogs[args.log_type] ?? undefined;