From 7da2f4e5160c25569f6d920eec7c66a001a7b279 Mon Sep 17 00:00:00 2001 From: RogueException Date: Wed, 23 Dec 2015 22:09:37 -0400 Subject: [PATCH] Added support for new game format --- src/Discord.Net/API/Client/Common/MemberPresence.cs | 9 +++++++-- .../API/Client/GatewaySocket/Commands/UpdateStatus.cs | 10 ++++++++-- src/Discord.Net/DiscordClient.cs | 10 +++++----- src/Discord.Net/Models/User.cs | 4 ++-- src/Discord.Net/Net/WebSockets/GatewaySocket.cs | 8 ++++++-- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/Discord.Net/API/Client/Common/MemberPresence.cs b/src/Discord.Net/API/Client/Common/MemberPresence.cs index 87e488c2d..283b9a1d1 100644 --- a/src/Discord.Net/API/Client/Common/MemberPresence.cs +++ b/src/Discord.Net/API/Client/Common/MemberPresence.cs @@ -5,8 +5,13 @@ namespace Discord.API.Client { public class MemberPresence : MemberReference { - [JsonProperty("game_id")] - public string GameId { get; set; } + public sealed class GameInfo + { + [JsonProperty("name")] + public string Name { get; set; } + } + [JsonProperty("game")] + public GameInfo Game { get; set; } [JsonProperty("status")] public string Status { get; set; } [JsonProperty("roles"), JsonConverter(typeof(LongStringArrayConverter))] diff --git a/src/Discord.Net/API/Client/GatewaySocket/Commands/UpdateStatus.cs b/src/Discord.Net/API/Client/GatewaySocket/Commands/UpdateStatus.cs index be90e2efc..75bfce892 100644 --- a/src/Discord.Net/API/Client/GatewaySocket/Commands/UpdateStatus.cs +++ b/src/Discord.Net/API/Client/GatewaySocket/Commands/UpdateStatus.cs @@ -9,9 +9,15 @@ namespace Discord.API.Client.GatewaySocket object IWebSocketMessage.Payload => this; bool IWebSocketMessage.IsPrivate => false; + public sealed class GameInfo + { + [JsonProperty("name")] + public string Name { get; set; } + } + [JsonProperty("idle_since")] public long? IdleSince { get; set; } - [JsonProperty("game_id")] - public int? GameId { get; set; } + [JsonProperty("game")] + public GameInfo Game { get; set; } } } diff --git a/src/Discord.Net/DiscordClient.cs b/src/Discord.Net/DiscordClient.cs index 92f0fbe26..c541fa5a2 100644 --- a/src/Discord.Net/DiscordClient.cs +++ b/src/Discord.Net/DiscordClient.cs @@ -60,8 +60,8 @@ namespace Discord public string SessionId { get; private set; } /// Gets the status of the current user. public UserStatus Status { get; private set; } - /// Gets the game this current user is reported as playing. - public int? CurrentGameId { get; private set; } + /// Gets the game the current user is displayed as playing. + public string CurrentGame { get; private set; } /// Gets a collection of all servers this client is a member of. public IEnumerable Servers => _servers.Select(x => x.Value); @@ -297,14 +297,14 @@ namespace Discord Status = status; return SendStatus(); } - public Task SetGame(int? gameId) + public Task SetGame(string game) { - CurrentGameId = gameId; + CurrentGame = game; return SendStatus(); } private Task SendStatus() { - GatewaySocket.SendUpdateStatus(Status == UserStatus.Idle ? EpochTime.GetMilliseconds() - (10 * 60 * 1000) : (long?)null, CurrentGameId); + GatewaySocket.SendUpdateStatus(Status == UserStatus.Idle ? EpochTime.GetMilliseconds() - (10 * 60 * 1000) : (long?)null, CurrentGame); return TaskHelper.CompletedTask; } diff --git a/src/Discord.Net/Models/User.cs b/src/Discord.Net/Models/User.cs index 779c2005c..b3912774b 100644 --- a/src/Discord.Net/Models/User.cs +++ b/src/Discord.Net/Models/User.cs @@ -59,7 +59,7 @@ namespace Discord /// Gets the unique identifier for this user's current avatar. public string AvatarId { get; private set; } /// Gets the id for the game this user is currently playing. - public string GameId { get; private set; } + public string GameName { get; private set; } /// Gets the current status for this user. public UserStatus Status { get; private set; } /// Gets the datetime that this user joined this server. @@ -195,7 +195,7 @@ namespace Discord _lastOnline = DateTime.UtcNow; } - GameId = model.GameId; //Allows null + GameName = model.Game?.Name; //Allows null } internal void Update(MemberVoiceState model) { diff --git a/src/Discord.Net/Net/WebSockets/GatewaySocket.cs b/src/Discord.Net/Net/WebSockets/GatewaySocket.cs index 71d7d356e..9e4fd573e 100644 --- a/src/Discord.Net/Net/WebSockets/GatewaySocket.cs +++ b/src/Discord.Net/Net/WebSockets/GatewaySocket.cs @@ -137,8 +137,12 @@ namespace Discord.Net.WebSockets => QueueMessage(new ResumeCommand { SessionId = _sessionId, Sequence = _lastSequence }); public override void SendHeartbeat() => QueueMessage(new HeartbeatCommand()); - public void SendUpdateStatus(long? idleSince, int? gameId) - => QueueMessage(new UpdateStatusCommand { IdleSince = idleSince, GameId = gameId }); + public void SendUpdateStatus(long? idleSince, string gameName) + => QueueMessage(new UpdateStatusCommand + { + IdleSince = idleSince, + Game = gameName != null ? new UpdateStatusCommand.GameInfo { Name = gameName } : null + }); public void SendUpdateVoice(ulong serverId, ulong channelId, bool isSelfMuted, bool isSelfDeafened) => QueueMessage(new UpdateVoiceCommand { GuildId = serverId, ChannelId = channelId, IsSelfMuted = isSelfMuted, IsSelfDeafened = isSelfDeafened }); public void SendRequestMembers(ulong serverId, string query, int limit)