"""Support""" the 'reactions' field on message objects
this is all really broken
This commit is contained in:
@@ -36,5 +36,7 @@ namespace Discord.API
|
||||
public Optional<Embed[]> Embeds { get; set; }
|
||||
[JsonProperty("pinned")]
|
||||
public Optional<bool> Pinned { get; set; }
|
||||
[JsonProperty("reactions")]
|
||||
public Optional<Reaction[]> Reactions { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,17 +4,15 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Common
|
||||
namespace Discord.API
|
||||
{
|
||||
public class Reaction
|
||||
{
|
||||
[JsonProperty("user_id")]
|
||||
public ulong UserId { get; set; }
|
||||
[JsonProperty("message_id")]
|
||||
public ulong MessageId { get; set; }
|
||||
[JsonProperty("count")]
|
||||
public int Count { get; set; }
|
||||
[JsonProperty("me")]
|
||||
public bool Me { get; set; }
|
||||
[JsonProperty("emoji")]
|
||||
public Emoji Emoji { get; set; }
|
||||
[JsonProperty("channel_id")]
|
||||
public ulong ChannelId { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ namespace Discord
|
||||
IReadOnlyCollection<IAttachment> Attachments { get; }
|
||||
/// <summary> Returns all embeds included in this message. </summary>
|
||||
IReadOnlyCollection<IEmbed> Embeds { get; }
|
||||
/// <summary> Returns all reactions included in this message. </summary>
|
||||
IReadOnlyCollection<IReaction> Reactions { get; }
|
||||
/// <summary> Returns all tags included in this message's content. </summary>
|
||||
IReadOnlyCollection<ITag> Tags { get; }
|
||||
/// <summary> Returns the ids of channels mentioned in this message. </summary>
|
||||
|
||||
12
src/Discord.Net.Core/Entities/Messages/IReaction.cs
Normal file
12
src/Discord.Net.Core/Entities/Messages/IReaction.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Discord
|
||||
{
|
||||
public interface IReaction
|
||||
{
|
||||
API.Emoji Emoji { get; }
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace Discord.Rpc
|
||||
public virtual IReadOnlyCollection<ulong> MentionedRoleIds => ImmutableArray.Create<ulong>();
|
||||
public virtual IReadOnlyCollection<ulong> MentionedUserIds => ImmutableArray.Create<ulong>();
|
||||
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;
|
||||
|
||||
|
||||
20
src/Discord.Net.WebSocket/API/Gateway/GatewayReaction.cs
Normal file
20
src/Discord.Net.WebSocket/API/Gateway/GatewayReaction.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user