Skip to content

Commit

Permalink
Fix outgoing activity sending (#916)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
foxbot committed Jan 7, 2018
1 parent d5e9d6f commit fdd2c80
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/Discord.Net.WebSocket/DiscordSocketClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS0618
#pragma warning disable CS0618
using Discord.API;
using Discord.API.Gateway;
using Discord.Logging;
Expand Down Expand Up @@ -328,9 +328,9 @@ public override async Task SetStatusAsync(UserStatus status)
}
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);
else if (name != null)
else if (!string.IsNullOrEmpty(name))
Activity = new Game(name);
else
Activity = null;
Expand All @@ -346,21 +346,24 @@ private async Task SendStatusAsync()
{
if (CurrentUser == null)
return;
var activity = Activity;
var status = Status;
var statusSince = _statusSince;
CurrentUser.Presence = new SocketPresence(status, activity);
CurrentUser.Presence = new SocketPresence(status, Activity);

var gameModel = new GameModel();
// 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 StreamingGame stream)
if (Activity is RichGame game)
throw new NotSupportedException("Outgoing Rich Presences are not supported");
else if (Activity is StreamingGame stream)
{
gameModel.StreamUrl = stream.Url;
gameModel.StreamType = stream.StreamType;
}
else if (activity != null)
gameModel.Name = activity.Name;
else if (Activity != null)
{
gameModel.Name = Activity.Name;
gameModel.StreamType = StreamType.NotStreaming;
}

await ApiClient.SendStatusUpdateAsync(
status,
Expand Down

0 comments on commit fdd2c80

Please sign in to comment.