[Feature] Super reactions support (#2707)
* super reactions * add type to `GetReactionUsers` methods * add `MeBurst`
This commit is contained in:
@@ -1,14 +1,24 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API
|
||||
namespace Discord.API;
|
||||
|
||||
internal class Reaction
|
||||
{
|
||||
internal class Reaction
|
||||
{
|
||||
[JsonProperty("count")]
|
||||
public int Count { get; set; }
|
||||
[JsonProperty("me")]
|
||||
public bool Me { get; set; }
|
||||
[JsonProperty("emoji")]
|
||||
public Emoji Emoji { get; set; }
|
||||
}
|
||||
[JsonProperty("count")]
|
||||
public int Count { get; set; }
|
||||
|
||||
[JsonProperty("me")]
|
||||
public bool Me { get; set; }
|
||||
|
||||
[JsonProperty("me_burst")]
|
||||
public bool MeBurst { get; set; }
|
||||
|
||||
[JsonProperty("emoji")]
|
||||
public Emoji Emoji { get; set; }
|
||||
|
||||
[JsonProperty("count_details")]
|
||||
public ReactionCountDetails CountDetails { get; set; }
|
||||
|
||||
[JsonProperty("burst_colors")]
|
||||
public Color[] Colors { get; set; }
|
||||
}
|
||||
|
||||
12
src/Discord.Net.Rest/API/Common/ReactionCountDetails.cs
Normal file
12
src/Discord.Net.Rest/API/Common/ReactionCountDetails.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API;
|
||||
|
||||
internal class ReactionCountDetails
|
||||
{
|
||||
[JsonProperty("normal")]
|
||||
public int NormalCount { get; set;}
|
||||
|
||||
[JsonProperty("burst")]
|
||||
public int BurstCount { get; set;}
|
||||
}
|
||||
@@ -1143,7 +1143,8 @@ namespace Discord.API
|
||||
|
||||
await SendAsync("DELETE", () => $"channels/{channelId}/messages/{messageId}/reactions/{emoji}", ids, options: options).ConfigureAwait(false);
|
||||
}
|
||||
public async Task<IReadOnlyCollection<User>> GetReactionUsersAsync(ulong channelId, ulong messageId, string emoji, GetReactionUsersParams args, RequestOptions options = null)
|
||||
|
||||
public async Task<IReadOnlyCollection<User>> GetReactionUsersAsync(ulong channelId, ulong messageId, string emoji, GetReactionUsersParams args, ReactionType reactionType, RequestOptions options = null)
|
||||
{
|
||||
Preconditions.NotEqual(channelId, 0, nameof(channelId));
|
||||
Preconditions.NotEqual(messageId, 0, nameof(messageId));
|
||||
@@ -1158,9 +1159,10 @@ namespace Discord.API
|
||||
ulong afterUserId = args.AfterUserId.GetValueOrDefault(0);
|
||||
|
||||
var ids = new BucketIds(channelId: channelId);
|
||||
Expression<Func<string>> endpoint = () => $"channels/{channelId}/messages/{messageId}/reactions/{emoji}?limit={limit}&after={afterUserId}";
|
||||
Expression<Func<string>> endpoint = () => $"channels/{channelId}/messages/{messageId}/reactions/{emoji}?limit={limit}&after={afterUserId}&type={(int)reactionType}";
|
||||
return await SendAsync<IReadOnlyCollection<User>>("GET", endpoint, ids, options: options).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task AckMessageAsync(ulong channelId, ulong messageId, RequestOptions options = null)
|
||||
{
|
||||
Preconditions.NotEqual(channelId, 0, nameof(channelId));
|
||||
|
||||
@@ -164,7 +164,7 @@ namespace Discord.Rest
|
||||
}
|
||||
|
||||
public static IAsyncEnumerable<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IMessage msg, IEmote emote,
|
||||
int? limit, BaseDiscordClient client, RequestOptions options)
|
||||
int? limit, BaseDiscordClient client, ReactionType reactionType, RequestOptions options)
|
||||
{
|
||||
Preconditions.NotNull(emote, nameof(emote));
|
||||
var emoji = (emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name));
|
||||
@@ -181,7 +181,7 @@ namespace Discord.Rest
|
||||
if (info.Position != null)
|
||||
args.AfterUserId = info.Position.Value;
|
||||
|
||||
var models = await client.ApiClient.GetReactionUsersAsync(msg.Channel.Id, msg.Id, emoji, args, options).ConfigureAwait(false);
|
||||
var models = await client.ApiClient.GetReactionUsersAsync(msg.Channel.Id, msg.Id, emoji, args, reactionType, options).ConfigureAwait(false);
|
||||
return models.Select(x => RestUser.Create(client, x)).ToImmutableArray();
|
||||
},
|
||||
nextPage: (info, lastPage) =>
|
||||
|
||||
@@ -316,7 +316,14 @@ namespace Discord.Rest
|
||||
#endregion
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyDictionary<IEmote, ReactionMetadata> Reactions => _reactions.ToDictionary(x => x.Emote, x => new ReactionMetadata { ReactionCount = x.Count, IsMe = x.Me });
|
||||
public IReadOnlyDictionary<IEmote, ReactionMetadata> Reactions => _reactions.ToDictionary(x => x.Emote, x => new ReactionMetadata
|
||||
{
|
||||
ReactionCount = x.Count,
|
||||
IsMe = x.Me,
|
||||
BurstColors = x.BurstColors,
|
||||
BurstCount = x.BurstCount,
|
||||
NormalCount = x.NormalCount,
|
||||
});
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task AddReactionAsync(IEmote emote, RequestOptions options = null)
|
||||
@@ -334,7 +341,7 @@ namespace Discord.Rest
|
||||
public Task RemoveAllReactionsForEmoteAsync(IEmote emote, RequestOptions options = null)
|
||||
=> MessageHelper.RemoveAllReactionsForEmoteAsync(this, emote, Discord, options);
|
||||
/// <inheritdoc />
|
||||
public IAsyncEnumerable<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IEmote emote, int limit, RequestOptions options = null)
|
||||
=> MessageHelper.GetReactionUsersAsync(this, emote, limit, Discord, options);
|
||||
public IAsyncEnumerable<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IEmote emote, int limit, RequestOptions options = null, ReactionType type = ReactionType.Normal)
|
||||
=> MessageHelper.GetReactionUsersAsync(this, emote, limit, Discord, type, options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using Model = Discord.API.Reaction;
|
||||
|
||||
namespace Discord.Rest
|
||||
@@ -9,20 +10,44 @@ namespace Discord.Rest
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public IEmote Emote { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of reactions added.
|
||||
/// </summary>
|
||||
public int Count { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the reactions is added by the user.
|
||||
/// Gets whether the reaction is added by the user.
|
||||
/// </summary>
|
||||
public bool Me { get; }
|
||||
|
||||
internal RestReaction(IEmote emote, int count, bool me)
|
||||
/// <summary>
|
||||
/// Gets whether the super-reaction is added by the user.
|
||||
/// </summary>
|
||||
public bool MeBurst { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of burst reactions added.
|
||||
/// </summary>
|
||||
public int BurstCount { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of normal reactions added.
|
||||
/// </summary>
|
||||
public int NormalCount { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyCollection<Color> BurstColors { get; }
|
||||
|
||||
internal RestReaction(IEmote emote, int count, bool me, int burst, int normal, IReadOnlyCollection<Color> colors, bool meBurst)
|
||||
{
|
||||
Emote = emote;
|
||||
Count = count;
|
||||
Me = me;
|
||||
BurstCount = burst;
|
||||
NormalCount = normal;
|
||||
BurstColors = colors;
|
||||
MeBurst = meBurst;
|
||||
}
|
||||
internal static RestReaction Create(Model model)
|
||||
{
|
||||
@@ -31,7 +56,13 @@ namespace Discord.Rest
|
||||
emote = new Emote(model.Emoji.Id.Value, model.Emoji.Name, model.Emoji.Animated.GetValueOrDefault());
|
||||
else
|
||||
emote = new Emoji(model.Emoji.Name);
|
||||
return new RestReaction(emote, model.Count, model.Me);
|
||||
return new RestReaction(emote,
|
||||
model.Count,
|
||||
model.Me,
|
||||
model.CountDetails.BurstCount,
|
||||
model.CountDetails.NormalCount,
|
||||
model.Colors.ToReadOnlyCollection(),
|
||||
model.MeBurst);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
27
src/Discord.Net.Rest/Net/Converters/ColorConverter.cs
Normal file
27
src/Discord.Net.Rest/Net/Converters/ColorConverter.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using System.Globalization;
|
||||
using System;
|
||||
|
||||
namespace Discord.Net.Converters;
|
||||
|
||||
internal class ColorConverter : JsonConverter
|
||||
{
|
||||
public static readonly ColorConverter Instance = new ();
|
||||
|
||||
public override bool CanConvert(Type objectType) => true;
|
||||
public override bool CanRead => true;
|
||||
public override bool CanWrite => true;
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
if (reader.Value is null)
|
||||
return null;
|
||||
return new Color(uint.Parse(reader.Value.ToString()!.TrimStart('#'), NumberStyles.HexNumber));
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
writer.WriteValue($"#{(uint)value:X}");
|
||||
}
|
||||
}
|
||||
@@ -93,6 +93,8 @@ namespace Discord.Net.Converters
|
||||
return DiscordErrorConverter.Instance;
|
||||
if (type == typeof(GuildFeatures))
|
||||
return GuildFeaturesConverter.Instance;
|
||||
if(type == typeof(Color))
|
||||
return ColorConverter.Instance;
|
||||
|
||||
//Entities
|
||||
var typeInfo = type.GetTypeInfo();
|
||||
|
||||
Reference in New Issue
Block a user