From 8ad0fbc87b1ca779918a1244f4ea5a09a1140a83 Mon Sep 17 00:00:00 2001 From: Tom <25043847+Douile@users.noreply.github.com> Date: Sat, 4 Jan 2020 01:03:02 +0000 Subject: [PATCH] Add discord protocol --- README.md | 7 ++++++- games.txt | 1 + protocols/discord.js | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 protocols/discord.js diff --git a/README.md b/README.md index 8f961db..5348f93 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,7 @@ Games List | `devastation` | Devastation (2003) | `dinodday` | Dino D-Day (2011) | `dirttrackracing2` | Dirt Track Racing 2 (2002) +| `discord` | Discord | [Notes](#discord) | `doom3` | Doom 3 (2004) | `dota2` | Dota 2 (2013) | `drakan` | Drakan: Order of the Flame (1999) @@ -451,6 +452,10 @@ For teamspeak 3 queries to work correctly, the following permissions must be ava Requires tshock server mod, and a REST user token, which can be passed to GameDig with the additional option: token +### Discord +You must set host to the server's guild ID instead of IP, this can be found in server widget settings (Server ID) or by enabling developer mode in client settings and right-clicking the server's icon. +In order to retrieve information from discord server's they must have the Enable server widget option enabled. + Usage from Command Line --- @@ -547,7 +552,7 @@ Changelog ##### Breaking API changes * **Node 8 is now required** -* Removed the `port_query` option. You can now pass either the server's game port **or** query port in the `port` option, and +* Removed the `port_query` option. You can now pass either the server's game port **or** query port in the `port` option, and GameDig will automatically discover the proper port to query. Passing the query port is more likely be successful in unusual cases, as otherwise it must be automatically derived from the game port. * Removed `callback` parameter from Gamedig.query. Only promises are now supported. If you would like to continue diff --git a/games.txt b/games.txt index 9f31c25..7d19884 100644 --- a/games.txt +++ b/games.txt @@ -87,6 +87,7 @@ deusex|Deus Ex (2000)|gamespy2|port=7791,port_query_offset=1 devastation|Devastation (2003)|unreal2|port=7777,port_query_offset=1 dinodday|Dino D-Day (2011)|valve|port=27015 dirttrackracing2|Dirt Track Racing 2 (2002)|gamespy1|port=32240,port_query_offset=-100 +discord|Discord|discord|port=443 dnl|Dark and Light (2017)|valve|port=7777,port_query=27015 dod|Day of Defeat (2003)|valve|port=27015 dods|Day of Defeat: Source (2005)|valve|port=27015 diff --git a/protocols/discord.js b/protocols/discord.js new file mode 100644 index 0000000..d79c140 --- /dev/null +++ b/protocols/discord.js @@ -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;