'use strict';

const Command = require('../../models/Command');
const UserInfoEmbed = require('../../embeds/UserInfoEmbed');

/**
 * Get info about a user
 */
class UserInfo extends Command {
  /**
   * Constructs a callable command
   * @param {Bot} bot The bot object
   */
  constructor(bot) {
    super(bot, 'util.userinfo', 'userinfo', 'Get info about a user', 'UTIL');
    this.regex = new RegExp(`^${this.call}\\s*(?:(?:<@)(\\d+)(?:>))?`);
  }

  async run(message) {
    const params = message.strippedContent.match(this.regex);
    let user;
    let member;
    let mention;
    if (message.mentions.users) {
      const { a, b } = message.mentions.users.array();
      if (message.mentions.users.array().length > 1
        && message.mentions.users.array()[0].id === this.bot.client.id) {
        mention = b;
      } else {
        mention = a;
      }
    }

    if (params[1] || mention) {
      user = mention || this.bot.client.users.cache.get(params[1].trim());
    } else {
      user = message.author;
    }
    if (user && message.guild) {
      member = message.guild.members.cache.get(user.id);
    }
    if (!user) {
      this.messageManager.reply(message, 'can\'t find that user. Please specify another.', false, false);
      return this.messageManager.statuses.FAILURE;
    }

    const guildsWithUser = this.bot.client.guilds.cache
      .filter(guild => guild.members.cache.get(user.id));

    const guilds = guildsWithUser.length > 25
      ? guildsWithUser.splice(0, 24)
      : guildsWithUser;
    const embed = new UserInfoEmbed(this.bot, guilds, user, member, message);
    await message.reply({ embeds: [embed] });
    return this.messageManager.statuses.SUCCESS;
  }
}

module.exports = UserInfo;

@@ -584,32 +584,33 @@
 %0A    if (message
+?
 .mentions.users)
@@ -602,19 +602,22 @@
 mentions
-.us
+?.memb
 ers) %7B%0A 
@@ -631,16 +631,14 @@
 nst 
-%7B 
+%5B
 a, b
- %7D
+%5D
  = m
@@ -635,32 +635,33 @@
 %5Ba, b%5D = message
+?
 .mentions.users.
@@ -653,28 +653,32 @@
 mentions
-.users.array
+?.members.toJSON
 ();%0A    
@@ -686,24 +686,25 @@
  if (message
+?
 .mentions.us
@@ -704,33 +704,23 @@
 ions
-.users.array().length %3E 1
+?.members?.size
 %0A   
@@ -734,16 +734,17 @@
  message
+?
 .mention
@@ -748,25 +748,25 @@
 ions
-.users.array()%5B0%5D
+?.members.first()
 .id 
@@ -785,16 +785,21 @@
 .client.
+user.
 id) %7B%0A  
@@ -1146,42 +1146,38 @@
     
-this.
+await 
 message
-Manager.reply(message,
+.reply(%7B content:
  'ca
@@ -1225,22 +1225,10 @@
 er.'
-, false, false
+ %7D
 );%0A 
@@ -1437,14 +1437,12 @@
 ser.
-length
+size
  %3E 2
@@ -1466,16 +1466,25 @@
 ithUser.
+toJSON().
 splice(0

improve logic for userinfo