"""Support""" the 'reactions' field on message objects

this is all really broken
This commit is contained in:
Christopher F
2016-10-31 21:00:35 -04:00
parent 838d60e2c2
commit 7018bc9c58
12 changed files with 128 additions and 7 deletions

View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace Discord.API.Gateway
{
public class GatewayReaction : Reaction
{
[JsonProperty("user_id")]
public ulong UserId { get; set; }
[JsonProperty("message_id")]
public ulong MessageId { get; set; }
[JsonProperty("channel_id")]
public ulong ChannelId { get; set; }
[JsonProperty("emoji")]
public Discord.API.Emoji Emoji { get; set; }
}
}

View File

@@ -27,6 +27,7 @@ namespace Discord.WebSocket
public virtual IReadOnlyCollection<SocketRole> MentionedRoles => ImmutableArray.Create<SocketRole>();
public virtual IReadOnlyCollection<SocketUser> MentionedUsers => ImmutableArray.Create<SocketUser>();
public virtual IReadOnlyCollection<ITag> Tags => ImmutableArray.Create<ITag>();
public virtual IReadOnlyCollection<IReaction> Reactions => ImmutableArray.Create<IReaction>();
public virtual ulong? WebhookId => null;
public bool IsWebhook => WebhookId != null;

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Model = Discord.API.Gateway.GatewayReaction;
namespace Discord.WebSocket
{
public class SocketReaction : IReaction
{
internal SocketReaction(Model model)
{
UserId = model.UserId;
MessageId = model.MessageId;
ChannelId = model.ChannelId;
Emoji = model.Emoji;
}
public ulong UserId { get; internal set; }
public ulong MessageId { get; internal set; }
public ulong ChannelId { get; internal set; }
public API.Emoji Emoji { get; internal set; }
}
}

View File

@@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Threading.Tasks;
using Discord.API.Gateway;
using Model = Discord.API.Message;
namespace Discord.WebSocket
@@ -18,6 +19,7 @@ namespace Discord.WebSocket
private ImmutableArray<Attachment> _attachments;
private ImmutableArray<Embed> _embeds;
private ImmutableArray<ITag> _tags;
private ImmutableArray<IReaction> _reactions;
public override bool IsTTS => _isTTS;
public override bool IsPinned => _isPinned;
@@ -29,6 +31,7 @@ namespace Discord.WebSocket
public override IReadOnlyCollection<SocketGuildChannel> MentionedChannels => MessageHelper.FilterTagsByValue<SocketGuildChannel>(TagType.ChannelMention, _tags);
public override IReadOnlyCollection<SocketRole> MentionedRoles => MessageHelper.FilterTagsByValue<SocketRole>(TagType.RoleMention, _tags);
public override IReadOnlyCollection<SocketUser> MentionedUsers => MessageHelper.FilterTagsByValue<SocketUser>(TagType.UserMention, _tags);
public override IReadOnlyCollection<IReaction> Reactions => _reactions;
internal SocketUserMessage(DiscordSocketClient discord, ulong id, ISocketMessageChannel channel, SocketUser author)
: base(discord, id, channel, author)
@@ -101,6 +104,20 @@ namespace Discord.WebSocket
}
}
if (model.Reactions.IsSpecified)
{
var value = model.Reactions.Value;
if (value.Length > 0)
{
var reactions = ImmutableArray.CreateBuilder<IReaction>(value.Length);
for (int i = 0; i < value.Length; i++)
reactions.Add(new SocketReaction(value[i] as GatewayReaction));
_reactions = reactions.ToImmutable();
}
else
_reactions = ImmutableArray.Create<IReaction>();
}
if (model.Content.IsSpecified)
{
var text = model.Content.Value;