const Core = require('./core');

class Discord extends Core {
  constructor() {
    super();
    this.dnsResolver = { resolve: function(address) {return {address: address} } };
  }

  async run(state) {
    this.usedTcp = true;
    const raw = await this.request({
      uri: 'https://discordapp.com/api/guilds/' + this.options.address + '/widget.json',
    });
    const json = JSON.parse(raw);
    state.name = json.name;
    if (json.instant_invite) {
      state.connect = json.instant_invite;
    } else {
      state.connect = 'https://discordapp.com/channels/' + this.options.address
    }
    state.players = json.members.map(v => {
      return {
        name: v.username + '#' + v.discriminator,
        username: v.username,
        discriminator: v.discriminator,
        team: v.status
      }
    });
    state.raw = json;
  }
}

module.exports = Discord;

const Core = require('./core');

class Discord extends Core {
  constructor() {
    super();
    this.dnsResolver = { resolve: function(address) {return {address: address} } };
  }

  async run(state) {
    this.usedTcp = true;
    const raw = await this.request({
      uri: 'https://discordapp.com/api/guilds/' + this.options.address + '/widget.json',
    });
    const json = JSON.parse(raw);
    state.name = json.name;
    if (json.instant_invite) {
      state.connect = json.instant_invite;
    } else {
      state.connect = 'https://discordapp.com/channels/' + this.options.address
    }
    state.players = json.members.map(v => {
      return {
        name: v.username + '#' + v.discriminator,
        username: v.username,
        discriminator: v.discriminator,
        team: v.status
      }
    });
    state.maxplayers = json.presence_count;
    state.raw = json;
  }
}

module.exports = Discord;

Set max players to total amount of members in server
Set max players to total amount of members in server
