"""Support""" the 'reactions' field on message objects
this is all really broken
This commit is contained in:
@@ -27,6 +27,7 @@ namespace Discord.Rest
|
||||
public virtual IReadOnlyCollection<ulong> MentionedRoleIds => ImmutableArray.Create<ulong>();
|
||||
public virtual IReadOnlyCollection<RestUser> MentionedUsers => ImmutableArray.Create<RestUser>();
|
||||
public virtual IReadOnlyCollection<ITag> Tags => ImmutableArray.Create<ITag>();
|
||||
public virtual IReadOnlyCollection<IReaction> Reactions => ImmutableArray.Create<RestReaction>();
|
||||
public virtual ulong? WebhookId => null;
|
||||
public bool IsWebhook => WebhookId != null;
|
||||
|
||||
@@ -70,5 +71,6 @@ namespace Discord.Rest
|
||||
IReadOnlyCollection<IAttachment> IMessage.Attachments => Attachments;
|
||||
IReadOnlyCollection<IEmbed> IMessage.Embeds => Embeds;
|
||||
IReadOnlyCollection<ulong> IMessage.MentionedUserIds => MentionedUsers.Select(x => x.Id).ToImmutableArray();
|
||||
IReadOnlyCollection<IReaction> IMessage.Reactions => Reactions;
|
||||
}
|
||||
}
|
||||
|
||||
26
src/Discord.Net.Rest/Entities/Messages/RestReaction.cs
Normal file
26
src/Discord.Net.Rest/Entities/Messages/RestReaction.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Model = Discord.API.Reaction;
|
||||
|
||||
namespace Discord
|
||||
{
|
||||
public class RestReaction : IReaction
|
||||
{
|
||||
internal RestReaction(Model model)
|
||||
{
|
||||
_emoji = model.Emoji;
|
||||
_count = model.Count;
|
||||
|
||||
}
|
||||
|
||||
internal readonly API.Emoji _emoji;
|
||||
internal readonly int _count;
|
||||
internal readonly bool _me;
|
||||
|
||||
public API.Emoji Emoji => _emoji;
|
||||
public int Count => _count;
|
||||
public bool Me => _me;
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ namespace Discord.Rest
|
||||
private ImmutableArray<Attachment> _attachments;
|
||||
private ImmutableArray<Embed> _embeds;
|
||||
private ImmutableArray<ITag> _tags;
|
||||
private ImmutableArray<RestReaction> _reactions;
|
||||
|
||||
public override bool IsTTS => _isTTS;
|
||||
public override bool IsPinned => _isPinned;
|
||||
@@ -29,6 +30,7 @@ namespace Discord.Rest
|
||||
public override IReadOnlyCollection<ulong> MentionedRoleIds => MessageHelper.FilterTagsByKey(TagType.RoleMention, _tags);
|
||||
public override IReadOnlyCollection<RestUser> MentionedUsers => MessageHelper.FilterTagsByValue<RestUser>(TagType.UserMention, _tags);
|
||||
public override IReadOnlyCollection<ITag> Tags => _tags;
|
||||
public override IReadOnlyCollection<IReaction> Reactions => _reactions;
|
||||
|
||||
internal RestUserMessage(BaseDiscordClient discord, ulong id, IMessageChannel channel, RestUser author, IGuild guild)
|
||||
: base(discord, id, channel, author, guild)
|
||||
@@ -103,6 +105,20 @@ namespace Discord.Rest
|
||||
}
|
||||
}
|
||||
|
||||
if (model.Reactions.IsSpecified)
|
||||
{
|
||||
var value = model.Reactions.Value;
|
||||
if (value.Length > 0)
|
||||
{
|
||||
var reactions = ImmutableArray.CreateBuilder<RestReaction>(value.Length);
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
reactions.Add(new RestReaction(value[i]));
|
||||
_reactions = reactions.ToImmutable();
|
||||
}
|
||||
else
|
||||
_reactions = ImmutableArray.Create<RestReaction>();
|
||||
}
|
||||
|
||||
if (model.Content.IsSpecified)
|
||||
{
|
||||
var text = model.Content.Value;
|
||||
|
||||
Reference in New Issue
Block a user