this is all really brokentags/1.0-rc
| @@ -36,5 +36,7 @@ namespace Discord.API | |||||
| public Optional<Embed[]> Embeds { get; set; } | public Optional<Embed[]> Embeds { get; set; } | ||||
| [JsonProperty("pinned")] | [JsonProperty("pinned")] | ||||
| public Optional<bool> Pinned { get; set; } | 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 System.Threading.Tasks; | ||||
| using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
| namespace Discord.API.Common | |||||
| namespace Discord.API | |||||
| { | { | ||||
| public class Reaction | 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")] | [JsonProperty("emoji")] | ||||
| public Emoji Emoji { get; set; } | public Emoji Emoji { get; set; } | ||||
| [JsonProperty("channel_id")] | |||||
| public ulong ChannelId { get; set; } | |||||
| } | } | ||||
| } | } | ||||
| @@ -31,6 +31,8 @@ namespace Discord | |||||
| IReadOnlyCollection<IAttachment> Attachments { get; } | IReadOnlyCollection<IAttachment> Attachments { get; } | ||||
| /// <summary> Returns all embeds included in this message. </summary> | /// <summary> Returns all embeds included in this message. </summary> | ||||
| IReadOnlyCollection<IEmbed> Embeds { get; } | 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> | /// <summary> Returns all tags included in this message's content. </summary> | ||||
| IReadOnlyCollection<ITag> Tags { get; } | IReadOnlyCollection<ITag> Tags { get; } | ||||
| /// <summary> Returns the ids of channels mentioned in this message. </summary> | /// <summary> Returns the ids of channels mentioned in this message. </summary> | ||||
| @@ -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<ulong> MentionedRoleIds => ImmutableArray.Create<ulong>(); | ||||
| public virtual IReadOnlyCollection<RestUser> MentionedUsers => ImmutableArray.Create<RestUser>(); | public virtual IReadOnlyCollection<RestUser> MentionedUsers => ImmutableArray.Create<RestUser>(); | ||||
| public virtual IReadOnlyCollection<ITag> Tags => ImmutableArray.Create<ITag>(); | public virtual IReadOnlyCollection<ITag> Tags => ImmutableArray.Create<ITag>(); | ||||
| public virtual IReadOnlyCollection<IReaction> Reactions => ImmutableArray.Create<RestReaction>(); | |||||
| public virtual ulong? WebhookId => null; | public virtual ulong? WebhookId => null; | ||||
| public bool IsWebhook => WebhookId != null; | public bool IsWebhook => WebhookId != null; | ||||
| @@ -70,5 +71,6 @@ namespace Discord.Rest | |||||
| IReadOnlyCollection<IAttachment> IMessage.Attachments => Attachments; | IReadOnlyCollection<IAttachment> IMessage.Attachments => Attachments; | ||||
| IReadOnlyCollection<IEmbed> IMessage.Embeds => Embeds; | IReadOnlyCollection<IEmbed> IMessage.Embeds => Embeds; | ||||
| IReadOnlyCollection<ulong> IMessage.MentionedUserIds => MentionedUsers.Select(x => x.Id).ToImmutableArray(); | IReadOnlyCollection<ulong> IMessage.MentionedUserIds => MentionedUsers.Select(x => x.Id).ToImmutableArray(); | ||||
| IReadOnlyCollection<IReaction> IMessage.Reactions => Reactions; | |||||
| } | } | ||||
| } | } | ||||
| @@ -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<Attachment> _attachments; | ||||
| private ImmutableArray<Embed> _embeds; | private ImmutableArray<Embed> _embeds; | ||||
| private ImmutableArray<ITag> _tags; | private ImmutableArray<ITag> _tags; | ||||
| private ImmutableArray<RestReaction> _reactions; | |||||
| public override bool IsTTS => _isTTS; | public override bool IsTTS => _isTTS; | ||||
| public override bool IsPinned => _isPinned; | 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<ulong> MentionedRoleIds => MessageHelper.FilterTagsByKey(TagType.RoleMention, _tags); | ||||
| public override IReadOnlyCollection<RestUser> MentionedUsers => MessageHelper.FilterTagsByValue<RestUser>(TagType.UserMention, _tags); | public override IReadOnlyCollection<RestUser> MentionedUsers => MessageHelper.FilterTagsByValue<RestUser>(TagType.UserMention, _tags); | ||||
| public override IReadOnlyCollection<ITag> Tags => _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) | internal RestUserMessage(BaseDiscordClient discord, ulong id, IMessageChannel channel, RestUser author, IGuild guild) | ||||
| : base(discord, id, channel, author, 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) | if (model.Content.IsSpecified) | ||||
| { | { | ||||
| var text = model.Content.Value; | var text = model.Content.Value; | ||||
| @@ -28,6 +28,7 @@ namespace Discord.Rpc | |||||
| public virtual IReadOnlyCollection<ulong> MentionedRoleIds => ImmutableArray.Create<ulong>(); | public virtual IReadOnlyCollection<ulong> MentionedRoleIds => ImmutableArray.Create<ulong>(); | ||||
| public virtual IReadOnlyCollection<ulong> MentionedUserIds => ImmutableArray.Create<ulong>(); | public virtual IReadOnlyCollection<ulong> MentionedUserIds => ImmutableArray.Create<ulong>(); | ||||
| public virtual IReadOnlyCollection<ITag> Tags => ImmutableArray.Create<ITag>(); | public virtual IReadOnlyCollection<ITag> Tags => ImmutableArray.Create<ITag>(); | ||||
| public virtual IReadOnlyCollection<IReaction> Reactions => ImmutableArray.Create<IReaction>(); | |||||
| public virtual ulong? WebhookId => null; | public virtual ulong? WebhookId => null; | ||||
| public bool IsWebhook => WebhookId != null; | public bool IsWebhook => WebhookId != null; | ||||
| @@ -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<SocketRole> MentionedRoles => ImmutableArray.Create<SocketRole>(); | ||||
| public virtual IReadOnlyCollection<SocketUser> MentionedUsers => ImmutableArray.Create<SocketUser>(); | public virtual IReadOnlyCollection<SocketUser> MentionedUsers => ImmutableArray.Create<SocketUser>(); | ||||
| public virtual IReadOnlyCollection<ITag> Tags => ImmutableArray.Create<ITag>(); | public virtual IReadOnlyCollection<ITag> Tags => ImmutableArray.Create<ITag>(); | ||||
| public virtual IReadOnlyCollection<IReaction> Reactions => ImmutableArray.Create<IReaction>(); | |||||
| public virtual ulong? WebhookId => null; | public virtual ulong? WebhookId => null; | ||||
| public bool IsWebhook => 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.Collections.Immutable; | ||||
| using System.Diagnostics; | using System.Diagnostics; | ||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| using Discord.API.Gateway; | |||||
| using Model = Discord.API.Message; | using Model = Discord.API.Message; | ||||
| namespace Discord.WebSocket | namespace Discord.WebSocket | ||||
| @@ -18,6 +19,7 @@ namespace Discord.WebSocket | |||||
| private ImmutableArray<Attachment> _attachments; | private ImmutableArray<Attachment> _attachments; | ||||
| private ImmutableArray<Embed> _embeds; | private ImmutableArray<Embed> _embeds; | ||||
| private ImmutableArray<ITag> _tags; | private ImmutableArray<ITag> _tags; | ||||
| private ImmutableArray<IReaction> _reactions; | |||||
| public override bool IsTTS => _isTTS; | public override bool IsTTS => _isTTS; | ||||
| public override bool IsPinned => _isPinned; | 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<SocketGuildChannel> MentionedChannels => MessageHelper.FilterTagsByValue<SocketGuildChannel>(TagType.ChannelMention, _tags); | ||||
| public override IReadOnlyCollection<SocketRole> MentionedRoles => MessageHelper.FilterTagsByValue<SocketRole>(TagType.RoleMention, _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<SocketUser> MentionedUsers => MessageHelper.FilterTagsByValue<SocketUser>(TagType.UserMention, _tags); | ||||
| public override IReadOnlyCollection<IReaction> Reactions => _reactions; | |||||
| internal SocketUserMessage(DiscordSocketClient discord, ulong id, ISocketMessageChannel channel, SocketUser author) | internal SocketUserMessage(DiscordSocketClient discord, ulong id, ISocketMessageChannel channel, SocketUser author) | ||||
| : base(discord, id, channel, 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) | if (model.Content.IsSpecified) | ||||
| { | { | ||||
| var text = model.Content.Value; | var text = model.Content.Value; | ||||