Refactor Games, support reading Rich Presences (#877)
* Add API-level support for Rich Presences * Add library-level support for Game presences * Add model conversions for outgoing+incoming rich presences * Refactored Game into Activities * Integrated Activities with user entities rebase hell from 5f3cb947a92f4fd01cc4df47ca548180036b47f3 * Fix JSON converters for Activities * Finish rebase, activity should be set on BaseSocketClient * Use ApplicationId to define a rich presence * Added SetActivityAsync to Base and Sharded Socket clients * Remove public parameterless Game constructor * Remove GameAssets, refactored to GameAsset * Hide constructors for types that should be read-only * Revert changes to Discord.Net.sln got damned visual studio caching * Refactor GameParty to use dedicated current/capacity values Per feedback from @khionu
This commit is contained in:
@@ -22,7 +22,7 @@ namespace Discord.WebSocket
|
||||
/// <summary> Gets the estimated round-trip latency, in milliseconds, to the gateway server. </summary>
|
||||
public override int Latency { get => GetLatency(); protected set { } }
|
||||
public override UserStatus Status { get => _shards[0].Status; protected set { } }
|
||||
public override Game? Game { get => _shards[0].Game; protected set { } }
|
||||
public override IActivity Activity { get => _shards[0].Activity; protected set { } }
|
||||
|
||||
internal new DiscordSocketApiClient ApiClient => base.ApiClient as DiscordSocketApiClient;
|
||||
public override IReadOnlyCollection<SocketGuild> Guilds => GetGuilds().ToReadOnlyCollection(() => GetGuildCount());
|
||||
@@ -239,9 +239,18 @@ namespace Discord.WebSocket
|
||||
await _shards[i].SetStatusAsync(status).ConfigureAwait(false);
|
||||
}
|
||||
public override async Task SetGameAsync(string name, string streamUrl = null, StreamType streamType = StreamType.NotStreaming)
|
||||
{
|
||||
IActivity activity = null;
|
||||
if (streamUrl != null)
|
||||
activity = new StreamingGame(name, streamUrl, streamType);
|
||||
else if (name != null)
|
||||
activity = new Game(name);
|
||||
await SetActivityAsync(activity).ConfigureAwait(false);
|
||||
}
|
||||
public override async Task SetActivityAsync(IActivity activity)
|
||||
{
|
||||
for (int i = 0; i < _shards.Length; i++)
|
||||
await _shards[i].SetGameAsync(name, streamUrl, streamType).ConfigureAwait(false);
|
||||
await _shards[i].SetActivityAsync(activity).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private void RegisterEvents(DiscordSocketClient client, bool isPrimary)
|
||||
|
||||
Reference in New Issue
Block a user