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.tags/2.0.0-beta
@@ -0,0 +1,10 @@ | |||||
namespace Discord | |||||
{ | |||||
public enum ActivityType | |||||
{ | |||||
Playing = 0, | |||||
Streaming = 1, | |||||
Listening = 2, | |||||
Watching = 3 | |||||
} | |||||
} |
@@ -6,11 +6,13 @@ namespace Discord | |||||
public class Game : IActivity | public class Game : IActivity | ||||
{ | { | ||||
public string Name { get; internal set; } | public string Name { get; internal set; } | ||||
public ActivityType Type { get; internal set; } | |||||
internal Game() { } | internal Game() { } | ||||
public Game(string name) | |||||
public Game(string name, ActivityType type = ActivityType.Playing) | |||||
{ | { | ||||
Name = name; | Name = name; | ||||
Type = type; | |||||
} | } | ||||
public override string ToString() => Name; | public override string ToString() => Name; | ||||
@@ -1,13 +1,8 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Text; | |||||
using System.Threading.Tasks; | |||||
namespace Discord | |||||
namespace Discord | |||||
{ | { | ||||
public interface IActivity | public interface IActivity | ||||
{ | { | ||||
string Name { get; } | string Name { get; } | ||||
ActivityType Type { get; } | |||||
} | } | ||||
} | } |
@@ -6,15 +6,14 @@ namespace Discord | |||||
public class StreamingGame : Game | public class StreamingGame : Game | ||||
{ | { | ||||
public string Url { get; internal set; } | public string Url { get; internal set; } | ||||
public StreamType StreamType { get; internal set; } | |||||
public StreamingGame(string name, string url, StreamType streamType) | |||||
public StreamingGame(string name, string url) | |||||
{ | { | ||||
Name = name; | Name = name; | ||||
Url = url; | Url = url; | ||||
StreamType = streamType; | |||||
Type = ActivityType.Streaming; | |||||
} | } | ||||
public override string ToString() => Name; | public override string ToString() => Name; | ||||
private string DebuggerDisplay => $"{Name} ({Url})"; | private string DebuggerDisplay => $"{Name} ({Url})"; | ||||
} | } |
@@ -1,8 +0,0 @@ | |||||
namespace Discord | |||||
{ | |||||
public enum StreamType | |||||
{ | |||||
NotStreaming = 0, | |||||
Twitch = 1 | |||||
} | |||||
} |
@@ -12,7 +12,7 @@ namespace Discord.API | |||||
[JsonProperty("url")] | [JsonProperty("url")] | ||||
public Optional<string> StreamUrl { get; set; } | public Optional<string> StreamUrl { get; set; } | ||||
[JsonProperty("type")] | [JsonProperty("type")] | ||||
public Optional<StreamType?> StreamType { get; set; } | |||||
public Optional<ActivityType?> Type { get; set; } | |||||
[JsonProperty("details")] | [JsonProperty("details")] | ||||
public Optional<string> Details { get; set; } | public Optional<string> Details { get; set; } | ||||
[JsonProperty("state")] | [JsonProperty("state")] | ||||
@@ -44,7 +44,7 @@ namespace Discord.WebSocket | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public abstract Task StopAsync(); | public abstract Task StopAsync(); | ||||
public abstract Task SetStatusAsync(UserStatus status); | 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 SetActivityAsync(IActivity activity); | ||||
public abstract Task DownloadUsersAsync(IEnumerable<IGuild> guilds); | public abstract Task DownloadUsersAsync(IEnumerable<IGuild> guilds); | ||||
@@ -1,4 +1,4 @@ | |||||
using Discord.API; | |||||
using Discord.API; | |||||
using Discord.Rest; | using Discord.Rest; | ||||
using System; | using System; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
@@ -238,13 +238,13 @@ namespace Discord.WebSocket | |||||
for (int i = 0; i < _shards.Length; i++) | for (int i = 0; i < _shards.Length; i++) | ||||
await _shards[i].SetStatusAsync(status).ConfigureAwait(false); | 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; | 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); | await SetActivityAsync(activity).ConfigureAwait(false); | ||||
} | } | ||||
public override async Task SetActivityAsync(IActivity activity) | public override async Task SetActivityAsync(IActivity activity) | ||||
@@ -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; | ||||
@@ -326,12 +326,12 @@ namespace Discord.WebSocket | |||||
_statusSince = null; | _statusSince = null; | ||||
await SendStatusAsync().ConfigureAwait(false); | 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)) | if (!string.IsNullOrEmpty(streamUrl)) | ||||
Activity = new StreamingGame(name, streamUrl, streamType); | |||||
Activity = new StreamingGame(name, streamUrl); | |||||
else if (!string.IsNullOrEmpty(name)) | else if (!string.IsNullOrEmpty(name)) | ||||
Activity = new Game(name); | |||||
Activity = new Game(name, type); | |||||
else | else | ||||
Activity = null; | Activity = null; | ||||
await SendStatusAsync().ConfigureAwait(false); | 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 | // Discord only accepts rich presence over RPC, don't even bother building a payload | ||||
if (Activity is RichGame game) | if (Activity is RichGame game) | ||||
throw new NotSupportedException("Outgoing Rich Presences are not supported"); | 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.Name = Activity.Name; | ||||
gameModel.StreamType = StreamType.NotStreaming; | |||||
gameModel.Type = Activity.Type; | |||||
if (Activity is StreamingGame streamGame) | |||||
gameModel.StreamUrl = streamGame.Url; | |||||
} | } | ||||
await ApiClient.SendStatusUpdateAsync( | await ApiClient.SendStatusUpdateAsync( | ||||
@@ -27,11 +27,10 @@ | |||||
{ | { | ||||
return new StreamingGame( | return new StreamingGame( | ||||
model.Name, | model.Name, | ||||
model.StreamUrl.Value, | |||||
model.StreamType.Value.GetValueOrDefault()); | |||||
model.StreamUrl.Value); | |||||
} | } | ||||
// Normal Game | // Normal Game | ||||
return new Game(model.Name); | |||||
return new Game(model.Name, model.Type.GetValueOrDefault() ?? ActivityType.Playing); | |||||
} | } | ||||
// (Small, Large) | // (Small, Large) | ||||