As an example here is the validation function for the admin:groups:del
async function validateAndParse(values) {
if (values === undefined || !values.length) {
throw new MissingArgumentError(MODULE_PATH);
}
const promises = values.map((name) => db.Group.findOne({ where: { name } }));
const groups = await Promise.all(promises);
// Check for invalid groups
groups.forEach((group, index) => {
if (group === null) {
throw new InvalidArgumentError(MODULE_PATH, `Group not found \`${values[index]}\``);
}
});
return groups;
}
This logic is duplicated/repeated all over the admin slash commands. It would be nice to find a way to abstract it in a way that is generic enough to re-use for most slash commands.
As an example here is the validation function for the
admin:groups:delThis logic is duplicated/repeated all over the admin slash commands. It would be nice to find a way to abstract it in a way that is generic enough to re-use for most slash commands.