Fix outgoing activity sending (#916)

This change resolves #916

Discord requires the {"type": 0} payload for all non-streaming
activities. This change fixes a bug where name-only games would fail to
include this payload, causing the presence change to be discarded by
Discord.
This commit is contained in:
Christopher F
2018-01-06 23:20:21 -05:00
parent d5e9d6f9c1
commit fdd2c80d2b

View File

@@ -1,4 +1,4 @@
#pragma warning disable CS0618 #pragma warning disable CS0618
using Discord.API; using Discord.API;
using Discord.API.Gateway; using Discord.API.Gateway;
using Discord.Logging; using Discord.Logging;
@@ -328,9 +328,9 @@ namespace Discord.WebSocket
} }
public override async Task SetGameAsync(string name, string streamUrl = null, StreamType streamType = StreamType.NotStreaming) public override async Task SetGameAsync(string name, string streamUrl = null, StreamType streamType = StreamType.NotStreaming)
{ {
if (streamUrl != null) if (!string.IsNullOrEmpty(streamUrl))
Activity = new StreamingGame(name, streamUrl, streamType); Activity = new StreamingGame(name, streamUrl, streamType);
else if (name != null) else if (!string.IsNullOrEmpty(name))
Activity = new Game(name); Activity = new Game(name);
else else
Activity = null; Activity = null;
@@ -346,21 +346,24 @@ namespace Discord.WebSocket
{ {
if (CurrentUser == null) if (CurrentUser == null)
return; return;
var activity = Activity;
var status = Status; var status = Status;
var statusSince = _statusSince; var statusSince = _statusSince;
CurrentUser.Presence = new SocketPresence(status, activity); CurrentUser.Presence = new SocketPresence(status, Activity);
var gameModel = new GameModel(); var gameModel = new GameModel();
// Discord only accepts rich presence over RPC, don't even bother building a payload // Discord only accepts rich presence over RPC, don't even bother building a payload
if (activity is RichGame game) throw new NotSupportedException("Outgoing Rich Presences are not supported"); if (Activity is RichGame game)
if (activity is StreamingGame stream) throw new NotSupportedException("Outgoing Rich Presences are not supported");
else if (Activity is StreamingGame stream)
{ {
gameModel.StreamUrl = stream.Url; gameModel.StreamUrl = stream.Url;
gameModel.StreamType = stream.StreamType; gameModel.StreamType = stream.StreamType;
} }
else if (activity != null) else if (Activity != null)
gameModel.Name = activity.Name; {
gameModel.Name = Activity.Name;
gameModel.StreamType = StreamType.NotStreaming;
}
await ApiClient.SendStatusUpdateAsync( await ApiClient.SendStatusUpdateAsync(
status, status,