Feature: CustomStatusGame Activity (#1406)
* Implement CustomStatusGame activity Adds the CustomStatusGame class, which is the activity corresponding to the custom status feature. * Remove unused import from Game.cs
This commit is contained in:
committed by
Christopher F
parent
5439cbad5a
commit
79a0ea9de3
@@ -20,6 +20,10 @@ namespace Discord
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The user is watching some form of media.
|
/// The user is watching some form of media.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Watching = 3
|
Watching = 3,
|
||||||
|
/// <summary>
|
||||||
|
/// The user has set a custom status.
|
||||||
|
/// </summary>
|
||||||
|
CustomStatus = 4,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
40
src/Discord.Net.Core/Entities/Activities/CustomStatusGame.cs
Normal file
40
src/Discord.Net.Core/Entities/Activities/CustomStatusGame.cs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace Discord
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A user's activity for their custom status.
|
||||||
|
/// </summary>
|
||||||
|
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||||
|
public class CustomStatusGame : Game
|
||||||
|
{
|
||||||
|
internal CustomStatusGame() { }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the emote, if it is set.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// An <see cref="IEmote"/> containing the <see cref="Emoji"/> or <see cref="GuildEmote"/> set by the user.
|
||||||
|
/// </returns>
|
||||||
|
public IEmote Emote { get; internal set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the timestamp of when this status was created.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// A <see cref="DateTimeOffset"/> containing the time when this status was created.
|
||||||
|
/// </returns>
|
||||||
|
public DateTimeOffset CreatedAt { get; internal set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the state of the status.
|
||||||
|
/// </summary>
|
||||||
|
public string State { get; internal set; }
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
=> $"{Emote} {State}";
|
||||||
|
|
||||||
|
private string DebuggerDisplay => $"{Name}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,6 +35,12 @@ namespace Discord.API
|
|||||||
public Optional<string> SessionId { get; set; }
|
public Optional<string> SessionId { get; set; }
|
||||||
[JsonProperty("Flags")]
|
[JsonProperty("Flags")]
|
||||||
public Optional<ActivityProperties> Flags { get; set; }
|
public Optional<ActivityProperties> Flags { get; set; }
|
||||||
|
[JsonProperty("id")]
|
||||||
|
public Optional<string> Id { get; set; }
|
||||||
|
[JsonProperty("emoji")]
|
||||||
|
public Optional<Emoji> Emoji { get; set; }
|
||||||
|
[JsonProperty("created_at")]
|
||||||
|
public Optional<long> CreatedAt { get; set; }
|
||||||
|
|
||||||
[OnError]
|
[OnError]
|
||||||
internal void OnError(StreamingContext context, ErrorContext errorContext)
|
internal void OnError(StreamingContext context, ErrorContext errorContext)
|
||||||
|
|||||||
@@ -5,6 +5,13 @@ namespace Discord.Rest
|
|||||||
{
|
{
|
||||||
internal static class EntityExtensions
|
internal static class EntityExtensions
|
||||||
{
|
{
|
||||||
|
public static IEmote ToIEmote(this API.Emoji model)
|
||||||
|
{
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
return model.ToEntity();
|
||||||
|
return new Emoji(model.Name);
|
||||||
|
}
|
||||||
|
|
||||||
public static GuildEmote ToEntity(this API.Emoji model)
|
public static GuildEmote ToEntity(this API.Emoji model)
|
||||||
=> new GuildEmote(model.Id.Value,
|
=> new GuildEmote(model.Id.Value,
|
||||||
model.Name,
|
model.Name,
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
using Discord.Rest;
|
||||||
|
using System;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
@@ -7,6 +9,19 @@ namespace Discord.WebSocket
|
|||||||
{
|
{
|
||||||
public static IActivity ToEntity(this API.Game model)
|
public static IActivity ToEntity(this API.Game model)
|
||||||
{
|
{
|
||||||
|
// Custom Status Game
|
||||||
|
if (model.Id.IsSpecified)
|
||||||
|
{
|
||||||
|
return new CustomStatusGame()
|
||||||
|
{
|
||||||
|
Type = ActivityType.CustomStatus,
|
||||||
|
Name = model.Name,
|
||||||
|
State = model.State.IsSpecified ? model.State.Value : null,
|
||||||
|
Emote = model.Emoji.IsSpecified ? model.Emoji.Value.ToIEmote() : null,
|
||||||
|
CreatedAt = DateTimeOffset.FromUnixTimeMilliseconds(model.CreatedAt.Value),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Spotify Game
|
// Spotify Game
|
||||||
if (model.SyncId.IsSpecified)
|
if (model.SyncId.IsSpecified)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user