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

exports.run = async (Bastion, message, args) => {
  let guildSettings = await Bastion.db.get(`SELECT whitelistDomains FROM guildSettings WHERE guildID=${message.guild.id}`).catch(e => {
    Bastion.log.error(e);
  });

  if (!guildSettings || guildSettings.whitelistDomains === '[]') {
    /**
    * Error condition is encountered.
    * @fires error
    */
    return Bastion.emit('error', Bastion.strings.error(message.guild.language, 'notFound'), Bastion.strings.error(message.guild.language, 'notSet', true, 'whitelisted domain'), message.channel);
  }

  let whitelistDomains = JSON.parse(guildSettings.whitelistDomains);
  whitelistDomains = [ ...new Set(whitelistDomains) ];

  whitelistDomains = whitelistDomains.map((r, i) => `${i + 1}. ${r}`);

  let noOfPages = whitelistDomains.length / 10;
  let i = (args.page > 0 && args.page < noOfPages + 1) ? args.page : 1;
  i = i - 1;

  message.channel.send({
    embed: {
      color: Bastion.colors.BLUE,
      title: 'Whitelisted Domains',
      description: whitelistDomains.slice(i * 10, (i * 10) + 10).join('\n'),
      footer: {
        text: `Page: ${i + 1} of ${noOfPages > parseInt(noOfPages) ? parseInt(noOfPages) + 1 : parseInt(noOfPages)}`
      }
    }
  }).catch(e => {
    Bastion.log.error(e);
  });
};

exports.config = {
  aliases: [],
  enabled: true,
  argsDefinitions: [
    { name: 'page', type: Number, alias: 'p', defaultOption: true, defaultValue: 1 }
  ]
};

exports.help = {
  name: 'listWhitelistDomains',
  botPermission: '',<commit_msg>Improvements to listWhitelistDomains command * Restricted the command to administrators * Code improvements<commit_after>/**
 * @file listWhitelistDomains command
 * @author <NAME> (a.k.a k3rn31p4nic)
 * @license MIT
 */

exports.run = async (Bastion, message, args) => {
  try {
    if (!message.member.hasPermission(this.help.userPermission)) {
      /**
      * User has missing permissions.
      * @fires userMissingPermissions
      */
      return Bastion.emit('userMissingPermissions', this.help.userPermission);
    }

    let guildSettings = await Bastion.db.get(`SELECT whitelistDomains FROM guildSettings WHERE guildID=${message.guild.id}`);

    if (!guildSettings || guildSettings.whitelistDomains === '[]') {
      /**
      * Error condition is encountered.
      * @fires error
      */
      return Bastion.emit('error', Bastion.strings.error(message.guild.language, 'notFound'), Bastion.strings.error(message.guild.language, 'notSet', true, 'whitelisted domain'), message.channel);
    }

    let whitelistDomains = JSON.parse(guildSettings.whitelistDomains);
    whitelistDomains = [ ...new Set(whitelistDomains) ];

    whitelistDomains = whitelistDomains.map((r, i) => `${i + 1}. ${r}`);

    let noOfPages = whitelistDomains.length / 10;
    let i = (args.page > 0 && args.page < noOfPages + 1) ? args.page : 1;
    i = i - 1;

    message.channel.send({
      embed: {
        color: Bastion.colors.BLUE,
        title: 'Whitelisted Domains',
        description: whitelistDomains.slice(i * 10, (i * 10) + 10).join('\n'),
        footer: {
          text: `Page: ${i + 1} of ${noOfPages > parseInt(noOfPages) ? parseInt(noOfPages) + 1 : parseInt(noOfPages)}`
        }
      }
    }).catch(e => {
      Bastion.log.error(e);
    });
  }
  catch (e) {
    Bastion.log.error(e);
  }
};

exports.config = {
  aliases: [],
  enabled: true,
  argsDefinitions: [
    { name: 'page', type: Number, alias: 'p', defaultOption: true, defaultValue: 1 }
  ]
};

exports.help = {
  name: 'listWhitelistDomains',
  botPermission: '',
{'fraction_non_alphanumeric': 0.16032608695652173, 'fraction_numerical': 0.010869565217391304, 'mean_word_length': 3.280232558139535, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4031807', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1239, 'n_words': 258}