Skip to content

Find a way to abstract slash command validation #3

@Bwen

Description

@Bwen

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions