Bugfixes
Fixed logic error in option parsing Allow commands command to run in dms
This commit is contained in:
parent
720738d7ab
commit
18fb92c3a0
@ -231,10 +231,10 @@ class DiscordClient extends Client
|
||||
// Needs to load in after connecting to discord
|
||||
await this.#moderationManager.initialise();
|
||||
|
||||
this.#setActivity();
|
||||
this.setActivity();
|
||||
this.#activityInterval = setInterval(() =>
|
||||
{
|
||||
this.#setActivity();
|
||||
this.setActivity();
|
||||
}, Util.random(5, 10) * 60 * 60 * 1000);
|
||||
|
||||
this.#built = true;
|
||||
@ -341,7 +341,7 @@ class DiscordClient extends Client
|
||||
return this.#options.logger;
|
||||
}
|
||||
|
||||
async #setActivity ()
|
||||
async setActivity ()
|
||||
{
|
||||
if (!this.shard || !this.user)
|
||||
throw new Error('Missing shard or user');
|
||||
|
@ -7,6 +7,7 @@ class ModerationModule extends SettingsCommand
|
||||
{
|
||||
super(client, {
|
||||
name: 'moderation',
|
||||
aliases: [ 'mod' ],
|
||||
description: 'Configure the moderation settings',
|
||||
moduleName: 'administration'
|
||||
});
|
||||
|
@ -23,20 +23,22 @@ class Commands extends SlashCommand
|
||||
description: [ 'List commands from a specific module' ]
|
||||
}],
|
||||
memberPermissions: [],
|
||||
guildOnly: true
|
||||
// guildOnly: true
|
||||
});
|
||||
}
|
||||
|
||||
async execute (invoker: InvokerWrapper, { module }: CommandParams)
|
||||
{
|
||||
const guild = invoker.guild!;
|
||||
const settings = await guild.settings();
|
||||
const { commands: { disabled } } = settings;
|
||||
const { guild } = invoker;
|
||||
const settings = await guild?.settings();
|
||||
let disabled: string[] = [];
|
||||
if (settings)
|
||||
({ commands: { disabled } } = settings);
|
||||
|
||||
|
||||
let commands: Collection<string, Command> | null = null;
|
||||
if (module)
|
||||
commands = module.asModule.components.filter<Command>((c): c is Command => c.type === 'command');
|
||||
// eslint-disable-next-line prefer-destructuring
|
||||
else
|
||||
({ commands } = this.client.registry);
|
||||
const amt = commands.size;
|
||||
@ -49,12 +51,12 @@ class Commands extends SlashCommand
|
||||
const _module = command.module.name;
|
||||
if (!modules[_module])
|
||||
modules[_module] = [];
|
||||
const emoji = disabled?.includes(command.resolveable) ? Emojis.failure : Emojis.success;
|
||||
const emoji = disabled?.includes(command.resolveable) || !guild && command.guildOnly ? Emojis.failure : Emojis.success;
|
||||
modules[_module].push(`${emoji} ${Util.capitalise(command.name)}`);
|
||||
}
|
||||
|
||||
const embed: APIEmbed = {
|
||||
title: guild.format('COMMAND_COMMANDS_TITLE'),
|
||||
title: invoker.format('COMMAND_COMMANDS_TITLE'),
|
||||
fields: [],
|
||||
footer: { text: `• ${amt} commands` }
|
||||
};
|
||||
|
@ -464,14 +464,13 @@ class CommandHandler extends Observer
|
||||
// Clean up params for option parsing
|
||||
for (const flag of Object.values(args))
|
||||
{
|
||||
// console.log('flags loop', flag.name, flag._rawValue);
|
||||
// console.log('flags loop', flag.name, flag.rawValue);
|
||||
const removed = await flag.parse();
|
||||
// console.log(removed);
|
||||
if (!(removed instanceof Array) && removed.error)
|
||||
{
|
||||
if (flag.choices.length)
|
||||
{
|
||||
return { error: true, index: 'O_COMMANDHANDLER_INVALID_CHOICE', params: { option: flag.name, value: flag.rawValue as string, choices: flag.choices.map((c) => c.value).join('`, `') } };
|
||||
}
|
||||
return { option: flag, ...removed };
|
||||
}
|
||||
for (const r of removed as string[])
|
||||
@ -512,7 +511,8 @@ class CommandHandler extends Observer
|
||||
}
|
||||
cloned.rawValue = params[index];
|
||||
removed = await cloned.parse();
|
||||
if (!(removed instanceof Array) && !removed.error)
|
||||
// Successfully parsed a value, move on to removing the raw value from the params
|
||||
if ((removed instanceof Array))
|
||||
break;
|
||||
index++;
|
||||
}
|
||||
@ -529,7 +529,6 @@ class CommandHandler extends Observer
|
||||
if (removed instanceof Array)
|
||||
for (const r of removed)
|
||||
params.splice(params.indexOf(r), 1, null);
|
||||
|
||||
}
|
||||
|
||||
const strings = [];
|
||||
@ -679,11 +678,8 @@ class CommandHandler extends Observer
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
return invoker.reply({ ...messages[info.type](), edit: invoker.replied });
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default CommandHandler;
|
@ -87,10 +87,11 @@ abstract class ModerationCommand extends SlashCommand
|
||||
if (opts.options?.some((opt) => opt.type === CommandOptionType.SUB_COMMAND))
|
||||
baseOptions = [];
|
||||
|
||||
const sorted = [ ...baseOptions, ...opts.options || [] ].sort((a) => a.type === CommandOptionType.STRING ? 0 : -1);
|
||||
super(client, {
|
||||
...opts,
|
||||
options: opts.overrideOptions
|
||||
? opts.options : [ ...baseOptions, ...opts.options || [] ]
|
||||
? opts.options : sorted
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -59,9 +59,15 @@ The members must be exact matches for this option.
|
||||
[O_COMMANDHANDLER_TYPETEXT_CHANNEL]
|
||||
The command option {option} requires a text channel.
|
||||
|
||||
[O_COMMANDHANDLER_TYPETEXT_CHANNELS]
|
||||
The command option {option} requires text channels.
|
||||
|
||||
[O_COMMANDHANDLER_TYPEVOICE_CHANNEL]
|
||||
The command option {option} requires a voice channel.
|
||||
|
||||
[O_COMMANDHANDLER_TYPEVOICE_CHANNELS]
|
||||
The command option {option} requires voice channels.
|
||||
|
||||
[O_COMMANDHANDLER_TYPECHANNELS]
|
||||
The command option {option} requires channels.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user