Browse Source

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.
tags/2.0.0-beta
Christopher F 7 years ago
parent
commit
a384ce02ab
10 changed files with 37 additions and 42 deletions
  1. +10
    -0
      src/Discord.Net.Core/Entities/Activities/ActivityType.cs
  2. +3
    -1
      src/Discord.Net.Core/Entities/Activities/Game.cs
  3. +2
    -7
      src/Discord.Net.Core/Entities/Activities/IActivity.cs
  4. +3
    -4
      src/Discord.Net.Core/Entities/Activities/StreamingGame.cs
  5. +0
    -8
      src/Discord.Net.Core/Entities/Users/StreamType.cs
  6. +1
    -1
      src/Discord.Net.Rest/API/Common/Game.cs
  7. +1
    -1
      src/Discord.Net.WebSocket/BaseSocketClient.cs
  8. +6
    -6
      src/Discord.Net.WebSocket/DiscordShardedClient.cs
  9. +9
    -11
      src/Discord.Net.WebSocket/DiscordSocketClient.cs
  10. +2
    -3
      src/Discord.Net.WebSocket/Extensions/EntityExtensions.cs

+ 10
- 0
src/Discord.Net.Core/Entities/Activities/ActivityType.cs View File

@@ -0,0 +1,10 @@
namespace Discord
{
public enum ActivityType
{
Playing = 0,
Streaming = 1,
Listening = 2,
Watching = 3
}
}

+ 3
- 1
src/Discord.Net.Core/Entities/Activities/Game.cs View File

@@ -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;


+ 2
- 7
src/Discord.Net.Core/Entities/Activities/IActivity.cs View File

@@ -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; }
} }
} }

+ 3
- 4
src/Discord.Net.Core/Entities/Activities/StreamingGame.cs View File

@@ -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})";
} }

+ 0
- 8
src/Discord.Net.Core/Entities/Users/StreamType.cs View File

@@ -1,8 +0,0 @@
namespace Discord
{
public enum StreamType
{
NotStreaming = 0,
Twitch = 1
}
}

+ 1
- 1
src/Discord.Net.Rest/API/Common/Game.cs View File

@@ -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")]


+ 1
- 1
src/Discord.Net.WebSocket/BaseSocketClient.cs View File

@@ -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);




+ 6
- 6
src/Discord.Net.WebSocket/DiscordShardedClient.cs View File

@@ -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)


+ 9
- 11
src/Discord.Net.WebSocket/DiscordSocketClient.cs 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;
@@ -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(


+ 2
- 3
src/Discord.Net.WebSocket/Extensions/EntityExtensions.cs View File

@@ -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)


Loading…
Cancel
Save