mirror of
https://github.com/tribufu/node-gamedig
synced 2026-05-18 09:35:50 +00:00
Add discord protocol
This commit is contained in:
parent
211c2d1635
commit
8ad0fbc87b
3 changed files with 42 additions and 1 deletions
35
protocols/discord.js
Normal file
35
protocols/discord.js
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
const Core = require('./core');
|
||||
|
||||
class Discord extends Core {
|
||||
constructor() {
|
||||
super();
|
||||
this.dnsResolver = { resolve: function(address) {return {address: address} } };
|
||||
}
|
||||
|
||||
async run(state) {
|
||||
console.log('SENDING HTTP Request');
|
||||
this.usedTcp = true;
|
||||
console.log(this.options);
|
||||
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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue