Browse Source

Several Game fixes

pull/73/merge
RogueException 9 years ago
parent
commit
d0f6e70dbc
9 changed files with 46 additions and 23 deletions
  1. +6
    -1
      src/Discord.Net.Net45/Discord.Net.csproj
  2. +2
    -2
      src/Discord.Net/API/Client/Common/Game.cs
  3. +1
    -1
      src/Discord.Net/API/Client/Common/MemberPresence.cs
  4. +1
    -1
      src/Discord.Net/API/Client/GatewaySocket/Commands/UpdateStatus.cs
  5. +9
    -8
      src/Discord.Net/DiscordClient.cs
  6. +17
    -4
      src/Discord.Net/Models/Game.cs
  7. +1
    -1
      src/Discord.Net/Models/Profile.cs
  8. +6
    -3
      src/Discord.Net/Models/User.cs
  9. +3
    -2
      src/Discord.Net/Net/WebSockets/GatewaySocket.cs

+ 6
- 1
src/Discord.Net.Net45/Discord.Net.csproj View File

@@ -70,6 +70,9 @@
<Compile Include="..\Discord.Net\API\Client\Common\ExtendedMember.cs">
<Link>API\Client\Common\ExtendedMember.cs</Link>
</Compile>
<Compile Include="..\Discord.Net\API\Client\Common\Game.cs">
<Link>API\Client\Common\Game.cs</Link>
</Compile>
<Compile Include="..\Discord.Net\API\Client\Common\Guild.cs">
<Link>API\Client\Common\Guild.cs</Link>
</Compile>
@@ -520,6 +523,9 @@
<Compile Include="..\Discord.Net\Models\Color.cs">
<Link>Models\Color.cs</Link>
</Compile>
<Compile Include="..\Discord.Net\Models\Game.cs">
<Link>Models\Game.cs</Link>
</Compile>
<Compile Include="..\Discord.Net\Models\Invite.cs">
<Link>Models\Invite.cs</Link>
</Compile>
@@ -602,7 +608,6 @@
<Link>TaskManager.cs</Link>
</Compile>
<Compile Include="Enums\GameType.cs" />
<Compile Include="Models\Game.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>


src/Discord.Net.Net45/Models/Game.cs → src/Discord.Net/API/Client/Common/Game.cs View File

@@ -1,8 +1,8 @@
using Newtonsoft.Json;

namespace Discord
namespace Discord.API.Client
{
public class GameInfo
public class Game
{
[JsonProperty("game")]
public string Name { get; set; }

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

@@ -6,7 +6,7 @@ namespace Discord.API.Client
public class MemberPresence : MemberReference
{
[JsonProperty("game")]
public GameInfo Game { get; set; }
public Game Game { get; set; }
[JsonProperty("status")]
public string Status { get; set; }
[JsonProperty("roles"), JsonConverter(typeof(LongStringArrayConverter))]


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

@@ -12,6 +12,6 @@ namespace Discord.API.Client.GatewaySocket
[JsonProperty("idle_since")]
public long? IdleSince { get; set; }
[JsonProperty("game")]
public GameInfo Game { get; set; }
public Game Game { get; set; }
}
}

+ 9
- 8
src/Discord.Net/DiscordClient.cs View File

@@ -65,7 +65,7 @@ namespace Discord
/// <summary> Gets the status of the current user. </summary>
public UserStatus Status { get; private set; }
/// <summary> Gets the game the current user is displayed as playing. </summary>
public GameInfo CurrentGame { get; private set; }
public Game CurrentGame { get; private set; }

/// <summary> Gets a collection of all extensions added to this DiscordClient. </summary>
public IEnumerable<IService> Services => _services;
@@ -319,18 +319,19 @@ namespace Discord
Status = status;
SendStatus();
}
public void SetGame(GameInfo game)
public void SetGame(Game game)
{
CurrentGame = game;
SendStatus();
}
public void SetGame(string game, string url = null, GameType type = GameType.Default)
public void SetGame(string game)
{
CurrentGame = new GameInfo() {
Name = game,
Url = url ?? CurrentGame?.Url,
Type = type
};
CurrentGame = new Game(game);
SendStatus();
}
public void SetGame(string game, GameType type, string url)
{
CurrentGame = new Game(game, type, url);
SendStatus();
}
private void SendStatus()


+ 17
- 4
src/Discord.Net/Models/Game.cs View File

@@ -1,9 +1,22 @@
namespace Discord
{
public class GameInfo
public struct Game
{
public string Name { get; set; }
public string Url { get; set; }
public GameType Type { get; set; }
public string Name { get; }
public string Url { get; }
public GameType Type { get; }

public Game(string name)
{
Name = name;
Url = null;
Type = GameType.Default;
}
public Game(string name, GameType type, string url)
{
Name = name;
Url = url;
Type = type;
}
}
}

+ 1
- 1
src/Discord.Net/Models/Profile.cs View File

@@ -23,7 +23,7 @@ namespace Discord
/// <summary> Gets an id uniquely identifying from others with the same name. </summary>
public ushort Discriminator => Client.PrivateUser.Discriminator;
/// <summary> Gets the name of the game this user is currently playing. </summary>
public GameInfo CurrentGame => Client.PrivateUser.CurrentGame;
public Game? CurrentGame => Client.PrivateUser.CurrentGame;
/// <summary> Gets the current status for this user. </summary>
public UserStatus Status => Client.PrivateUser.Status;
/// <summary> Returns the string used to mention this user. </summary>


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

@@ -63,7 +63,7 @@ namespace Discord
/// <summary> Gets the unique identifier for this user's current avatar. </summary>
public string AvatarId { get; private set; }
/// <summary> Gets the name of the game this user is currently playing. </summary>
public GameInfo CurrentGame { get; internal set; }
public Game? CurrentGame { get; internal set; }
/// <summary> Determines whether this user is a Bot account. </summary>
public bool IsBot { get; internal set; }
/// <summary> Gets the current status for this user. </summary>
@@ -207,8 +207,11 @@ namespace Discord
if (Status == UserStatus.Offline)
_lastOnline = DateTime.UtcNow;
}
CurrentGame = model.Game; //Allows null

if (model.Game != null)
CurrentGame = new Game(model.Game.Name, model.Game.Type, model.Game.Url);
else
CurrentGame = null;
}
internal void Update(MemberVoiceState model)
{


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

@@ -11,6 +11,7 @@ using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using APIGame = Discord.API.Client.Game;

namespace Discord.Net.WebSockets
{
@@ -167,11 +168,11 @@ namespace Discord.Net.WebSockets
=> QueueMessage(new ResumeCommand { SessionId = SessionId, Sequence = _lastSequence });
public override void SendHeartbeat()
=> QueueMessage(new HeartbeatCommand());
public void SendUpdateStatus(long? idleSince, GameInfo game)
public void SendUpdateStatus(long? idleSince, Game? game)
=> QueueMessage(new UpdateStatusCommand
{
IdleSince = idleSince,
Game = game != null ? new GameInfo { Name = game.Name, Url = game.Url, Type = game.Type } : null
Game = game != null ? new APIGame { Name = game.Value.Name, Type = game.Value.Type, Url = game.Value.Url } : null
});
public void SendUpdateVoice(ulong? serverId, ulong? channelId, bool isSelfMuted, bool isSelfDeafened)
=> QueueMessage(new UpdateVoiceCommand { GuildId = serverId, ChannelId = channelId, IsSelfMuted = isSelfMuted, IsSelfDeafened = isSelfDeafened });


Loading…
Cancel
Save