<commit_before>/**
 * @file quotes command
 * @author <NAME> (a.k.a k3rn31p4nic)
 * @license MIT
 */

const getRandomInt = require('../../functions/getRandomInt');
const quotes = require('../../data/quotes.json');

exports.run = (Bastion, message, args) => {
  let index = getRandomInt(1, Object.keys(quotes).length);
  if (!isNaN(args[0])) {
    if (args[0] >= 1 && args[0] <= Object.keys(quotes).length) index = args[0];
  }
  else {
    let n = [];
    for (let i = 1; i <= Object.keys(quotes).length; i++) {
      if (quotes[i].author.search(new RegExp(args.join(' '), 'i')) !== -1) {
        n.push(i);
      }
    }
    if (n.length > 0) {
      index = n[Math.floor(Math.random() * n.length)];
      // index = n.random();
    }
  }

  message.channel.send({
    embed: {
      color: Bastion.colors.blue,
      description: `*"${quotes[index].quote}"*\n\n**${quotes[index].author}**`,
      footer: {
        text: `Quote: ${index}`
      }
    }
  }).catch(e => {
    Bastion.log.error(e.stack);
  });
};

exports.config = {
  aliases: [ 'q' ],
  enabled: true
};

exports.help = {
  name: 'quotes',
  description: 'Shows a quote to get you inspired. Search a quote by it\'s index no. or by the author. If none is provided, shows a random quote.',
  botPermission: '',
  userPermission: '',
  usage: 'quotes <number|author>',
  example: [ 'quotes', 'quotes 189', 'quotes <NAME>' ]
};<commit_msg>Rewritten quotes command<commit_after>/**
 * @file quotes command
 * @author <NAME> (a.k.a k3rn31p4nic)
 * @license MIT
 */

const getRandomInt = require('../../functions/getRandomInt');
const quotes = require('../../data/quotes.json');

exports.run = (Bastion, message, args) => {
  /*
   * Get a random quote
   */
  let index = getRandomInt(1, Object.keys(quotes).length);

  /**
   * If a quote number is provided, use that number.
   */
  if (!isNaN(args.number)) {
    /**
     * If the quote number exists
     */
    if (args.number >= 1 && args.number <= Object.keys(quotes).length) {
      index = args.number;
    }
  }
  /**
   * If a author is provided, use that author.
   */
  else if (args.author) {
    let authorQuoteIDs = [];
    /**
     * If the quotes list has a quote from the specified author, store it.
     */
    for (let i = 1; i <= Object.keys(quotes).length; i++) {
      if (quotes[i].author.search(new RegExp(args.author.join(' '), 'i')) !== -1) {
        authorQuoteIDs.push(i);
      }
    }
    /**
     * If the author has at least 1 quote, get a random quote number from it.
     */
    if (authorQuoteIDs.length > 0) {
      index = authorQuoteIDs[Math.floor(Math.random() * authorQuoteIDs.length)];
    }
  }

  message.channel.send({
    embed: {
      color: Bastion.colors.blue,
      description: `*"${quotes[index].quote}"*\n\n**${quotes[index].author}**`,
      footer: {
        text: `Quote Number: ${index}`
      }
    }
  }).catch(e => {
    Bastion.log.error(e.stack);
  });
};

exports.config = {
  aliases: [ 'q' ],
  enabled: true,
  argsDefinitions: [
    { name: 'number', type: Number, alias: 'n' },
    { name: 'author', type: String, alias: 'a', multiple: true }
  ]
};

exports.help = {
  name: 'quotes',
  description: 'Shows a quote to get you inspired. Search a quote by it\'s index no. or by the author. If none is provided, shows a random quote.',
  botPermission: '',
  userPermission: '',
  usage: 'quotes [ -n | -a Author Name]',
  example: [ 'quotes', 'quotes -n 189', 'quotes -a <NAME>' ]
};
{'fraction_non_alphanumeric': 0.18961038961038962, 'fraction_numerical': 0.00836940836940837, 'mean_word_length': 2.6716101694915255, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 16, 'https://': 0, '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': '4586987', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1204, 'n_words': 307}