2020-01-04 02:03:02 +01:00
|
|
|
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 {
|
2020-01-04 14:53:36 +01:00
|
|
|
name: v.username,
|
2020-01-04 02:03:02 +01:00
|
|
|
team: v.status
|
|
|
|
}
|
|
|
|
});
|
2020-01-04 14:44:09 +01:00
|
|
|
state.maxplayers = json.presence_count;
|
2020-01-04 02:03:02 +01:00
|
|
|
state.raw = json;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Discord;
|