Support listening/watching activity types

This resolves #931

As part of this change, StreamingType has been refactored to realign
with how Discord seems to define the 'type' field on activities now.

StreamType is renamed to ActivityType, and the following properties have
been changed:
- NotStreaming -> Playing
- Twitch -> Streaming

Additionally, the StreamType property/parameter has been removed from
StreamingGame, and moved up a scope to Game.

Normal Games may now set their type, to line up with changes in
Discord's official clients.
This commit is contained in:
Christopher F
2018-01-13 23:20:04 -05:00
parent f69ef2a8ca
commit a384ce02ab
10 changed files with 37 additions and 42 deletions

View File

@@ -44,7 +44,7 @@ namespace Discord.WebSocket
/// <inheritdoc />
public abstract Task StopAsync();
public abstract Task SetStatusAsync(UserStatus status);
public abstract Task SetGameAsync(string name, string streamUrl = null, StreamType streamType = StreamType.NotStreaming);
public abstract Task SetGameAsync(string name, string streamUrl = null, ActivityType type = ActivityType.Playing);
public abstract Task SetActivityAsync(IActivity activity);
public abstract Task DownloadUsersAsync(IEnumerable<IGuild> guilds);

View File

@@ -1,4 +1,4 @@
using Discord.API;
using Discord.API;
using Discord.Rest;
using System;
using System.Collections.Generic;
@@ -238,13 +238,13 @@ namespace Discord.WebSocket
for (int i = 0; i < _shards.Length; i++)
await _shards[i].SetStatusAsync(status).ConfigureAwait(false);
}
public override async Task SetGameAsync(string name, string streamUrl = null, StreamType streamType = StreamType.NotStreaming)
public override async Task SetGameAsync(string name, string streamUrl = null, ActivityType type = ActivityType.Playing)
{
IActivity activity = null;
if (streamUrl != null)
activity = new StreamingGame(name, streamUrl, streamType);
else if (name != null)
activity = new Game(name);
if (!string.IsNullOrEmpty(streamUrl))
activity = new StreamingGame(name, streamUrl);
else if (!string.IsNullOrEmpty(name))
activity = new Game(name, type);
await SetActivityAsync(activity).ConfigureAwait(false);
}
public override async Task SetActivityAsync(IActivity activity)

View File

@@ -1,4 +1,4 @@
#pragma warning disable CS0618
#pragma warning disable CS0618
using Discord.API;
using Discord.API.Gateway;
using Discord.Logging;
@@ -326,12 +326,12 @@ namespace Discord.WebSocket
_statusSince = null;
await SendStatusAsync().ConfigureAwait(false);
}
public override async Task SetGameAsync(string name, string streamUrl = null, StreamType streamType = StreamType.NotStreaming)
public override async Task SetGameAsync(string name, string streamUrl = null, ActivityType type = ActivityType.Playing)
{
if (!string.IsNullOrEmpty(streamUrl))
Activity = new StreamingGame(name, streamUrl, streamType);
Activity = new StreamingGame(name, streamUrl);
else if (!string.IsNullOrEmpty(name))
Activity = new Game(name);
Activity = new Game(name, type);
else
Activity = null;
await SendStatusAsync().ConfigureAwait(false);
@@ -354,15 +354,13 @@ namespace Discord.WebSocket
// 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");
else if (Activity is StreamingGame stream)
{
gameModel.StreamUrl = stream.Url;
gameModel.StreamType = stream.StreamType;
}
else if (Activity != null)
if (Activity != null)
{
gameModel.Name = Activity.Name;
gameModel.StreamType = StreamType.NotStreaming;
gameModel.Type = Activity.Type;
if (Activity is StreamingGame streamGame)
gameModel.StreamUrl = streamGame.Url;
}
await ApiClient.SendStatusUpdateAsync(

View File

@@ -27,11 +27,10 @@
{
return new StreamingGame(
model.Name,
model.StreamUrl.Value,
model.StreamType.Value.GetValueOrDefault());
model.StreamUrl.Value);
}
// Normal Game
return new Game(model.Name);
return new Game(model.Name, model.Type.GetValueOrDefault() ?? ActivityType.Playing);
}
// (Small, Large)