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

exports.exec = async (Bastion, message, args) => {
  try {
    let user;
    if (message.mentions.users.size) {
      user = message.mentions.users.first();
    }
    else if (args.id) {
      user = await Bastion.fetchUser(args.id);
    }
    if (!user) {
      /**
      * The command was ran with invalid parameters.
      * @fires commandUsage
      */
      return Bastion.emit('commandUsage', message, this.help);
    }

    let member = await message.guild.fetchMember(user.id);
    if (message.author.id !== message.guild.ownerID && message.member.highestRole.comparePositionTo(member.highestRole) <= 0) return Bastion.log.info(Bastion.strings.error(message.guild.language, 'lowerRole', true));

    args.reason = args.reason.join(' ');

    if (!message.guild.warns) {
      message.guild.warns = {};
    }
    if (!message.guild.warns.hasOwnProperty(user.id)) {
      message.guild.warns[user.id] = 1;
    }
    else {
      if (message.guild.warns[user.id] >= 2) {
        let guildSettings = await Bastion.db.get(`SELECT warnAction FROM guildSettings WHERE guildID='${message.guild.id}'`);

        if (guildSettings.warnAction) {
          let action;
          if (guildSettings.warnAction === 'kick') {
            if (!member.kickable) {
              /**
              * Error condition is encountered.
              * @fires error
              */
              return Bastion.emit('error', Bastion.strings.error(message.guild.language, 'forbidden'), `I don't have permissions to kick ${user}.`, message.channel);
            }
            await member.kick('Warned 3 times!');
            action = 'Kicked';
          }
          if (guildSettings.warnAction === 'softban') {
            if (!member.bannable) {
              /**
              * Error condition is encountered.
              * @fires error
              */
              return Bastion.emit('error', Bastion.strings.error(message.guild.language, 'forbidden'), `I don't have permissions to soft-ban ${user}.`, message.channel);
            }
            await member.ban('Warned 3 times!');
            await message.guild.unban(member.id);
            action = 'Soft-Banned';
          }
          if (guildSettings.warnAction === 'ban') {
            if (!member.bannable) {
              /**
              * Error condition is encountered.
              * @fires error
              */
              return Bastion.emit('error', Bastion.strings.error(message.guild.language, 'forbidden'), `I don't have permissions to ban ${user}.`, message.channel);
            }
            await member.ban('Warned 3 times!');
            action = 'Banned';
          }

          delete message.guild.warns[user.id];
          message.channel.send({
            embed: {
              color: Bastion.colors.RED,
              title: action,
              fields: [
                {
                  name: 'User',
                  value: user.tag,
                  inline: true
                },
                {
                  name: 'ID',
                  value: user.id,
                  inline: true
                },
                {
                  name: 'Reason',
                  value: 'Warned 3 times!',
                  inline: false
                }
              ]
            }
          }).catch(e => {
            Bastion.log.error(e);
          });

          Bastion.emit('moderationLog', message.guild, message.author, guildSettings.warnAction, user, 'Warned 3 times!');

          member.send({
            embed: {
              color: Bastion.colors.RED,
              title: `${action} from ${message.guild.name} Server`,
              fields: [
                {
                  name: 'Reason',
                  value: 'You have been warned 3 times!'
                }
              ]
            }
          }).catch(e => {
            Bastion.log.error(e);
          });
        }
      }
      else {
        message.guild.warns[user.id] += 1;
      }
    }

    message.channel.send({
      embed: {
        color: Bastion.colors.ORANGE,
        description: Bastion.strings.info(message.guild.language, 'warn', message.author.tag, user.tag, args.reason)
      }
    }).catch(e => {
      Bastion.log.error(e);<commit_msg>Implemented new DB in warn command<commit_after>/**
 * @file warn command
 * @author <NAME> (a.k.a k3rn31p4nic)
 * @license MIT
 */

exports.exec = async (Bastion, message, args) => {
  try {
    let user;
    if (message.mentions.users.size) {
      user = message.mentions.users.first();
    }
    else if (args.id) {
      user = await Bastion.fetchUser(args.id);
    }
    if (!user) {
      /**
      * The command was ran with invalid parameters.
      * @fires commandUsage
      */
      return Bastion.emit('commandUsage', message, this.help);
    }

    let member = await message.guild.fetchMember(user.id);
    if (message.author.id !== message.guild.ownerID && message.member.highestRole.comparePositionTo(member.highestRole) <= 0) return Bastion.log.info(Bastion.strings.error(message.guild.language, 'lowerRole', true));

    args.reason = args.reason.join(' ');

    if (!message.guild.warns) {
      message.guild.warns = {};
    }
    if (!message.guild.warns.hasOwnProperty(user.id)) {
      message.guild.warns[user.id] = 1;
    }
    else {
      if (message.guild.warns[user.id] >= 2) {
        let guildModel = await message.client.database.models.guild.findOne({
          attributes: [ 'warnAction' ],
          where: {
            guildID: message.guild.id
          }
        });
        if (!guildModel || !guildModel.dataValues.warnAction) return;

        if (guildModel.dataValues.warnAction) {
          let action;
          if (guildModel.dataValues.warnAction === 'kick') {
            if (!member.kickable) {
              /**
              * Error condition is encountered.
              * @fires error
              */
              return Bastion.emit('error', Bastion.strings.error(message.guild.language, 'forbidden'), `I don't have permissions to kick ${user}.`, message.channel);
            }
            await member.kick('Warned 3 times!');
            action = 'Kicked';
          }
          if (guildModel.dataValues.warnAction === 'softban') {
            if (!member.bannable) {
              /**
              * Error condition is encountered.
              * @fires error
              */
              return Bastion.emit('error', Bastion.strings.error(message.guild.language, 'forbidden'), `I don't have permissions to soft-ban ${user}.`, message.channel);
            }
            await member.ban('Warned 3 times!');
            await message.guild.unban(member.id);
            action = 'Soft-Banned';
          }
          if (guildModel.dataValues.warnAction === 'ban') {
            if (!member.bannable) {
              /**
              * Error condition is encountered.
              * @fires error
              */
              return Bastion.emit('error', Bastion.strings.error(message.guild.language, 'forbidden'), `I don't have permissions to ban ${user}.`, message.channel);
            }
            await member.ban('Warned 3 times!');
            action = 'Banned';
          }

          delete message.guild.warns[user.id];
          message.channel.send({
            embed: {
              color: Bastion.colors.RED,
              title: action,
              fields: [
                {
                  name: 'User',
                  value: user.tag,
                  inline: true
                },
                {
                  name: 'ID',
                  value: user.id,
                  inline: true
                },
                {
                  name: 'Reason',
                  value: 'Warned 3 times!',
                  inline: false
                }
              ]
            }
          }).catch(e => {
            Bastion.log.error(e);
          });

          Bastion.emit('moderationLog', message.guild, message.author, guildModel.dataValues.warnAction, user, 'Warned 3 times!');

          member.send({
            embed: {
              color: Bastion.colors.RED,
              title: `${action} from ${message.guild.name} Server`,
              fields: [
                {
                  name: 'Reason',
                  value: 'You have been warned 3 times!'
                }
              ]
            }
          }).catch(e => {
            Bastion.log.error(e);
          });
        }
      }
      else {
        message.guild.warns[user.id] += 1;
      }
    }

    message.channel.send({
      embed: {
        color: Bastion.colors.ORANGE,
        description: Bastion.strings.info(message.guild.language, 'warn', message.author.tag, user.tag, args.reason)
      }
    }).catch(e => {
      Bastion.log.error(e);
{'fraction_non_alphanumeric': 0.13211153586687654, 'fraction_numerical': 0.0031481897908702495, 'mean_word_length': 1.4874161073825503, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '2330076', 'n_tokens_mistral': 2568, 'n_tokens_neox': 2490, 'n_words': 500}