Browse Source

Added support for new game format

tags/docs-0.9
RogueException 9 years ago
parent
commit
7da2f4e516
5 changed files with 28 additions and 13 deletions
  1. +7
    -2
      src/Discord.Net/API/Client/Common/MemberPresence.cs
  2. +8
    -2
      src/Discord.Net/API/Client/GatewaySocket/Commands/UpdateStatus.cs
  3. +5
    -5
      src/Discord.Net/DiscordClient.cs
  4. +2
    -2
      src/Discord.Net/Models/User.cs
  5. +6
    -2
      src/Discord.Net/Net/WebSockets/GatewaySocket.cs

+ 7
- 2
src/Discord.Net/API/Client/Common/MemberPresence.cs View File

@@ -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))]


+ 8
- 2
src/Discord.Net/API/Client/GatewaySocket/Commands/UpdateStatus.cs View File

@@ -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; }
}
}

+ 5
- 5
src/Discord.Net/DiscordClient.cs View File

@@ -60,8 +60,8 @@ namespace Discord
public string SessionId { get; private set; }
/// <summary> Gets the status of the current user. </summary>
public UserStatus Status { get; private set; }
/// <summary> Gets the game this current user is reported as playing. </summary>
public int? CurrentGameId { get; private set; }
/// <summary> Gets the game the current user is displayed as playing. </summary>
public string CurrentGame { get; private set; }

/// <summary> Gets a collection of all servers this client is a member of. </summary>
public IEnumerable<Server> 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;
}



+ 2
- 2
src/Discord.Net/Models/User.cs View File

@@ -59,7 +59,7 @@ namespace Discord
/// <summary> Gets the unique identifier for this user's current avatar. </summary>
public string AvatarId { get; private set; }
/// <summary> Gets the id for the game this user is currently playing. </summary>
public string GameId { get; private set; }
public string GameName { get; private set; }
/// <summary> Gets the current status for this user. </summary>
public UserStatus Status { get; private set; }
/// <summary> Gets the datetime that this user joined this server. </summary>
@@ -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)
{


+ 6
- 2
src/Discord.Net/Net/WebSockets/GatewaySocket.cs View File

@@ -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)


Loading…
Cancel
Save