<commit_before>/**
 * @file commands command
 * @author <NAME> (a.k.a k3rn31p4nic)
 * @license GPL-3.0
 */

exports.exec = async (Bastion, message, args) => {
  try {
    let modules = [ ...new Set(Bastion.commands.map(c => c.config.module)) ];

    if (args.module) {
      args.module = args.module.join('_').toLowerCase();
      if (modules.includes(args.module)) {
        modules = [ args.module ];
      }
    }

    let fields = [];
    for (let i = 0; i < modules.length; i++) {
      let commands = Bastion.commands.filter(c => c.config.module === modules[i]).map(c => c.help.name);
      if (commands.length === 0) {
        continue;
      }

      fields.push({
        name: `${modules[i].replace('_', ' ').toTitleCase()} - ${commands.length} Commands`,
        value: `\`\`\`css\n${commands.join('\n')}\`\`\``
      });
    }

    let authorDMChannel = await message.author.createDM();
    await authorDMChannel.send({
      embed: {
        color: Bastion.colors.GOLD,
        title: 'List of Commands',
        description: 'To get a complete list of all the commands with details, visit [my website](https://bastionbot.org/) and check out the commands section: https://bastionbot.org/commands.',
        fields: fields,
        footer: {
          text: `A Total of ${Bastion.commands.size} Commands!`
        }
      }
    });

    await message.channel.send({
      embed: {
        description: `${message.author} Check your DM from me, I've sent you the list of commands${args.module ? ` in ${args.module} module` : ''}. You can also check out the commands section of [my website](https://bastionbot.org/) for the complete list of commands with details: https://bastionbot.org/commands`
      }
    }).catch(e => {
      Bastion.log.error(e);
    });
  }
  catch (e) {
    if (e.code === 50007) {
      await message.channel.send({
        embed: {
          color: Bastion.colors.RED,
          description: `${message.author} You need to **allow Direct Messages from your Privacy Settings** so that I'll be able to DM you with the commands.\nIf you don't prefer to change your privacy settings, you can check out the commands section of [my website](https://bastionbot.org/) for the complete list of commands with details: https://bastionbot.org/commands`
        }
      });
    }
    else {
      throw e;
    }
  }
};

exports.config = {
  aliases: [ 'cmds', 'modules' ],
  enabled: true,
  argsDefinitions: [
    { name: 'module', type: String, multiple: true, defaultOption: true }
  ]
};

exports.help = {
  name: 'commands',
  description: 'Direct Messages you with a list of all the commands, or the commands in specific modules.',
  botPermission: '',
  userTextPermission: '',
  userVoicePermission: '',
  usage: 'commands [module name]',
  example: [ 'commands', 'commands game stats', 'commands moderation' ]
};<commit_msg>commands: improvements to commands command<commit_after>/**
 * @file commands command
 * @author <NAME> (a.k.a k3rn31p4nic)
 * @license GPL-3.0
 */

exports.exec = async (Bastion, message, args) => {
  let categories = Bastion.commands.map(c => c.config.module.toLowerCase()).unique();

  if (!args.category) {
    return await message.channel.send({
      embed: {
        color: Bastion.colors.GOLD,
        title: 'List of Command Categories',
        description: 'To get a complete list of all the commands with details, visit [my website](https://bastionbot.org/) and check out the commands section: https://bastionbot.org/commands.',
        fields: [
          {
            name: 'Command Categories',
            value: categories.map(m => m.replace(/_/g, ' ').toTitleCase()).join('\n')
          }
        ],
        footer: {
          text: `Did you know? There are ${Bastion.commands.size} commands in this version of Bastion!`
        }
      }
    });
  }

  args.category = args.category.join('_').toLowerCase();
  if (!categories.includes(args.category)) {
    return await message.channel.send({
      embed: {
        color: Bastion.colors.RED,
        title: 'Invalid Command Cateogry',
        description: 'Use the `commands` command without any arguments to get a list of all the available command categories.'
      }
    });
  }

  let commands = Bastion.commands.filter(c => c.config.module === args.category);
  args.category = args.category.replace(/_/g, ' ').toTitleCase();

  await message.channel.send({
    embed: {
      color: Bastion.colors.GOLD,
      title: `List of Commands in ${args.category} category`,
      description: `Use the \`commands\` command to get a list of all the ${categories.length} command categories.`,
      fields: [
        {
          name: `${commands.size} ${args.category} Commands`,
          value: `\`\`\`css\n${commands.map(c => c.help.name).join('\n')}\`\`\``
        },
        {
          name: 'Need more details?',
          value: 'Check out the help message of the command, using the `help <command>` command.'
        },
        {
          name: 'Want the complete list?',
          value: 'To get a complete list of all the commands with details, visit [my website](https://bastionbot.org/) and check out the commands page: https://bastionbot.org/commands.'
        }
      ],
      footer: {
        text: `Did you know? There are ${Bastion.commands.size} commands in this version of Bastion!`
      }
    }
  });
};

exports.config = {
  aliases: [ 'cmds' ],
  enabled: true,
  argsDefinitions: [
    { name: 'category', type: String, multiple: true, defaultOption: true }
  ]
};

exports.help = {
  name: 'commands',
  description: 'Shows the list of command categories. And if a category is specified, Bastion will show a list of commands in that category.',
  botPermission: '',
  userTextPermission: '',
  userVoicePermission: '',
  usage: 'commands [category]',
  example: [ 'commands', 'commands game stats', 'commands moderation' ]
};
{'fraction_non_alphanumeric': 0.1474239074987247, 'fraction_numerical': 0.0032307430709063085, 'mean_word_length': 2.6854636591478696, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 16, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '781314', 'n_tokens_mistral': 1766, 'n_tokens_neox': 1751, 'n_words': 521}