/**
 * @file listWarns command
 * @author Sankarsan Kampa (a.k.a k3rn31p4nic)
 * @license GPL-3.0
 */

exports.exec = async (Bastion, message) => {
  try {
    if (!message.guild.warns || Object.keys(message.guild.warns).length <= 0) {
      return message.channel.send({
        embed: {
          color: Bastion.colors.GREEN,
          description: 'No one has been warned yet.'
        }
      }).catch(e => {
        Bastion.log.error(e);
      });
    }

    let warnedUsers = [];
    for (let userID of Object.keys(message.guild.warns)) {
      let member = await message.guild.fetchMember(userID).catch((e) => {
        if (e.code !== 10007) {
          Bastion.log.error(e);
        }
      });
      if (member) {
        warnedUsers.push(`${member.user.tag} - ${message.guild.warns[userID]} Warnings`);
      }
      else {
        // TODO: Remove userID from warn list
      }
    }

    message.channel.send({
      embed: {
        color: Bastion.colors.ORANGE,
        title: 'Warning List',
        description: warnedUsers.length ? warnedUsers.join('\n') : 'No one has been warned yet.'
      }
    }).catch(e => {
      Bastion.log.error(e);
    });
  }
  catch (e) {
    Bastion.log.error(e);
  }
};

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

exports.help = {
  name: 'listWarns',
  description: 'Lists all the warned users of your Discord Server.',
  botPermission: '',
  userTextPermission: 'KICK_MEMBERS',
  userVoicePermission: '',
  usage: 'listWarns',
  example: []
};

@@ -157,76 +157,377 @@
     
-if (!message.guild.warns %7C%7C Object.keys(message.guild.warns)
+let guildMemberModel = await message.client.database.models.guildMember.findAll(%7B%0A      attributes: %5B 'userID', 'warnings' %5D,%0A      where: %7B%0A        guildID: message.guild.id,%0A        warnings: %7B%0A          %5BBastion.database.Op.not%5D: null%0A        %7D%0A      %7D%0A    %7D);%0A%0A    let warnedMembers = guildMemberModel.map(model =%3E model.dataValues);%0A%0A%0A    if (warnedMembers
 .length 
 %3C= 0
@@ -526,9 +526,10 @@
 gth 
-%3C
+==
 = 0)
@@ -755,24 +755,25 @@
 %0A    %7D%0A%0A
+%0A
     let 
 warnedUs
@@ -764,27 +764,27 @@
     let 
-warnedUsers
+membersList
  = %5B%5D;%0A 
@@ -799,79 +799,45 @@
 let 
-userID of Object.keys(message.guild.warns)) %7B%0A      let member = await 
+member of warnedMembers) %7B%0A      if (
 mess
@@ -850,182 +850,107 @@
 ild.
-fetchM
+members.has(m
 ember
-(
+.
 userID)
-.catch((e) =%3E %7B%0A        if (e.code !== 10007) %7B%0A          Bastion.log.error(e);%0A        %7D%0A      %7D);%0A      if (member) %7B%0A        warnedUsers.push(%60$%7B
+) %7B%0A        membersList.push(%60$%7Bmessage.guild.members.get(
 member.
+userID).
 user
@@ -965,33 +965,28 @@
 $%7Bme
-ssage.guild.warns%5BuserID%5D
+mber.warnings.length
 %7D Wa
@@ -1028,45 +1028,82 @@
     
-// TODO: Remove userID from warn list
+membersList.push(%60$%7Bmember.userID%7D - $%7Bmember.warnings.length%7D Warnings%60);
 %0A   
@@ -1114,16 +1114,17 @@
 %0A    %7D%0A%0A
+%0A
     mess
@@ -1251,83 +1251,30 @@
 on: 
-warnedUsers.length ? warnedUsers.join('%5Cn') : 'No one has been warned yet.'
+membersList.join('%5Cn')
 %0A   

rewrite listWarns command