mirror of
https://github.com/tribufu/node-gamedig
synced 2026-05-06 15:17:36 +00:00
Bring discord protocol up to date with gamedig 3.0
This commit is contained in:
parent
d9310db38b
commit
fe124a4487
6 changed files with 43 additions and 29 deletions
|
|
@ -146,7 +146,10 @@ class Core extends EventEmitter {
|
|||
}
|
||||
|
||||
assertValidPort(port) {
|
||||
if (!port || port < 1 || port > 65535) {
|
||||
if (!port) {
|
||||
throw new Error("Could not determine port to query. Did you provide a port?");
|
||||
}
|
||||
if (port < 1 || port > 65535) {
|
||||
throw new Error("Invalid tcp/ip port: " + port);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +1,31 @@
|
|||
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
|
||||
async run(state) {
|
||||
const guildId = this.options.guildId;
|
||||
if (typeof guildId !== 'string') {
|
||||
throw new Error('guildId option must be set when querying discord. Ensure the guildId is a string and not a number.'
|
||||
+ " (It's too large of a number for javascript to store without losing precision)");
|
||||
}
|
||||
this.usedTcp = true;
|
||||
const raw = await this.request({
|
||||
url: 'https://discordapp.com/api/guilds/' + guildId + '/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/' + guildId;
|
||||
}
|
||||
for (const member of json.members) {
|
||||
const {username: name, ...rest} = member;
|
||||
state.players.push({ name, ...rest });
|
||||
}
|
||||
delete json.members;
|
||||
state.maxplayers = 500000;
|
||||
state.raw = json;
|
||||
}
|
||||
state.players = json.members.map(v => {
|
||||
return {
|
||||
name: v.username,
|
||||
team: v.status
|
||||
}
|
||||
});
|
||||
state.maxplayers = json.presence_count;
|
||||
state.raw = json;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Discord;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue