Added IMessage.Emojis
This commit is contained in:
@@ -4,7 +4,7 @@ using Model = Discord.API.Attachment;
|
||||
namespace Discord
|
||||
{
|
||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||
public class RestAttachment : IAttachment
|
||||
public class Attachment : IAttachment
|
||||
{
|
||||
public ulong Id { get; }
|
||||
public string Filename { get; }
|
||||
@@ -14,7 +14,7 @@ namespace Discord
|
||||
public int? Height { get; }
|
||||
public int? Width { get; }
|
||||
|
||||
internal RestAttachment(ulong id, string filename, string url, string proxyUrl, int size, int? height, int? width)
|
||||
internal Attachment(ulong id, string filename, string url, string proxyUrl, int size, int? height, int? width)
|
||||
{
|
||||
Id = id;
|
||||
Filename = filename;
|
||||
@@ -24,9 +24,9 @@ namespace Discord
|
||||
Height = height;
|
||||
Width = width;
|
||||
}
|
||||
internal static RestAttachment Create(Model model)
|
||||
internal static Attachment Create(Model model)
|
||||
{
|
||||
return new RestAttachment(model.Id, model.Filename, model.Url, model.ProxyUrl, model.Size,
|
||||
return new Attachment(model.Id, model.Filename, model.Url, model.ProxyUrl, model.Size,
|
||||
model.Height.IsSpecified ? model.Height.Value : (int?)null,
|
||||
model.Width.IsSpecified ? model.Width.Value : (int?)null);
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using Model = Discord.API.Embed;
|
||||
namespace Discord
|
||||
{
|
||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||
public class RestEmbed : IEmbed
|
||||
public class Embed : IEmbed
|
||||
{
|
||||
public string Description { get; }
|
||||
public string Url { get; }
|
||||
@@ -13,7 +13,7 @@ namespace Discord
|
||||
public EmbedProvider? Provider { get; }
|
||||
public EmbedThumbnail? Thumbnail { get; }
|
||||
|
||||
internal RestEmbed(string type, string title, string description, string url, EmbedProvider? provider, EmbedThumbnail? thumbnail)
|
||||
internal Embed(string type, string title, string description, string url, EmbedProvider? provider, EmbedThumbnail? thumbnail)
|
||||
{
|
||||
Type = type;
|
||||
Title = title;
|
||||
@@ -22,9 +22,9 @@ namespace Discord
|
||||
Provider = provider;
|
||||
Thumbnail = thumbnail;
|
||||
}
|
||||
internal static RestEmbed Create(Model model)
|
||||
internal static Embed Create(Model model)
|
||||
{
|
||||
return new RestEmbed(model.Type, model.Title, model.Description, model.Url,
|
||||
return new Embed(model.Type, model.Title, model.Description, model.Url,
|
||||
model.Provider.IsSpecified ? EmbedProvider.Create(model.Provider.Value) : (EmbedProvider?)null,
|
||||
model.Thumbnail.IsSpecified ? EmbedThumbnail.Create(model.Thumbnail.Value) : (EmbedThumbnail?)null);
|
||||
}
|
||||
@@ -1,11 +1,18 @@
|
||||
using Discord.API.Rest;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Discord.Rest
|
||||
{
|
||||
internal static class MessageHelper
|
||||
{
|
||||
private static readonly Regex _emojiRegex = new Regex(@"<:(.+?):(\d+?)>", RegexOptions.Compiled);
|
||||
|
||||
public static async Task ModifyAsync(IMessage msg, BaseDiscordClient client, Action<ModifyMessageParams> func,
|
||||
RequestOptions options)
|
||||
{
|
||||
@@ -29,5 +36,18 @@ namespace Discord.Rest
|
||||
{
|
||||
await client.ApiClient.RemovePinAsync(msg.ChannelId, msg.Id, options);
|
||||
}
|
||||
|
||||
public static ImmutableArray<Emoji> GetEmojis(string text)
|
||||
{
|
||||
var matches = _emojiRegex.Matches(text);
|
||||
var builder = ImmutableArray.CreateBuilder<Emoji>(matches.Count);
|
||||
foreach (var match in matches.OfType<Match>())
|
||||
{
|
||||
ulong id;
|
||||
if (ulong.TryParse(match.Groups[2].Value, NumberStyles.None, CultureInfo.InvariantCulture, out id))
|
||||
builder.Add(new Emoji(id, match.Groups[1].Value, match.Index));
|
||||
}
|
||||
return builder.ToImmutable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,11 +19,12 @@ namespace Discord.Rest
|
||||
public virtual bool IsPinned => false;
|
||||
public virtual bool IsWebhook => false;
|
||||
public virtual DateTimeOffset? EditedTimestamp => null;
|
||||
public virtual IReadOnlyCollection<IAttachment> Attachments => ImmutableArray.Create<IAttachment>();
|
||||
public virtual IReadOnlyCollection<IEmbed> Embeds => ImmutableArray.Create<IEmbed>();
|
||||
public virtual IReadOnlyCollection<Attachment> Attachments => ImmutableArray.Create<Attachment>();
|
||||
public virtual IReadOnlyCollection<Embed> Embeds => ImmutableArray.Create<Embed>();
|
||||
public virtual IReadOnlyCollection<Emoji> Emojis => ImmutableArray.Create<Emoji>();
|
||||
public virtual IReadOnlyCollection<ulong> MentionedChannelIds => ImmutableArray.Create<ulong>();
|
||||
public virtual IReadOnlyCollection<IRole> MentionedRoles => ImmutableArray.Create<IRole>();
|
||||
public virtual IReadOnlyCollection<IUser> MentionedUsers => ImmutableArray.Create<IUser>();
|
||||
public virtual IReadOnlyCollection<RestRole> MentionedRoles => ImmutableArray.Create<RestRole>();
|
||||
public virtual IReadOnlyCollection<RestUser> MentionedUsers => ImmutableArray.Create<RestUser>();
|
||||
|
||||
public DateTimeOffset Timestamp => DateTimeUtils.FromTicks(_timestampTicks);
|
||||
|
||||
@@ -57,5 +58,9 @@ namespace Discord.Rest
|
||||
public override string ToString() => Content;
|
||||
|
||||
MessageType IMessage.Type => MessageType.Default;
|
||||
IReadOnlyCollection<IAttachment> IMessage.Attachments => Attachments;
|
||||
IReadOnlyCollection<IEmbed> IMessage.Embeds => Embeds;
|
||||
IReadOnlyCollection<IRole> IMessage.MentionedRoles => MentionedRoles;
|
||||
IReadOnlyCollection<IUser> IMessage.MentionedUsers => MentionedUsers;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,9 @@ namespace Discord.Rest
|
||||
{
|
||||
private bool _isMentioningEveryone, _isTTS, _isPinned;
|
||||
private long? _editedTimestampTicks;
|
||||
private ImmutableArray<RestAttachment> _attachments;
|
||||
private ImmutableArray<RestEmbed> _embeds;
|
||||
private ImmutableArray<Attachment> _attachments;
|
||||
private ImmutableArray<Embed> _embeds;
|
||||
private ImmutableArray<Emoji> _emojis;
|
||||
private ImmutableArray<ulong> _mentionedChannelIds;
|
||||
private ImmutableArray<RestRole> _mentionedRoles;
|
||||
private ImmutableArray<RestUser> _mentionedUsers;
|
||||
@@ -25,11 +26,12 @@ namespace Discord.Rest
|
||||
public override bool IsPinned => _isPinned;
|
||||
public override bool IsWebhook => WebhookId != null;
|
||||
public override DateTimeOffset? EditedTimestamp => DateTimeUtils.FromTicks(_editedTimestampTicks);
|
||||
public override IReadOnlyCollection<IAttachment> Attachments => _attachments;
|
||||
public override IReadOnlyCollection<IEmbed> Embeds => _embeds;
|
||||
public override IReadOnlyCollection<Attachment> Attachments => _attachments;
|
||||
public override IReadOnlyCollection<Embed> Embeds => _embeds;
|
||||
public override IReadOnlyCollection<Emoji> Emojis => _emojis;
|
||||
public override IReadOnlyCollection<ulong> MentionedChannelIds => _mentionedChannelIds;
|
||||
public override IReadOnlyCollection<IRole> MentionedRoles => _mentionedRoles;
|
||||
public override IReadOnlyCollection<IUser> MentionedUsers => _mentionedUsers;
|
||||
public override IReadOnlyCollection<RestRole> MentionedRoles => _mentionedRoles;
|
||||
public override IReadOnlyCollection<RestUser> MentionedUsers => _mentionedUsers;
|
||||
|
||||
internal RestUserMessage(BaseDiscordClient discord, ulong id, ulong channelId)
|
||||
: base(discord, id, channelId)
|
||||
@@ -62,13 +64,13 @@ namespace Discord.Rest
|
||||
var value = model.Attachments.Value;
|
||||
if (value.Length > 0)
|
||||
{
|
||||
var attachments = ImmutableArray.CreateBuilder<RestAttachment>(value.Length);
|
||||
var attachments = ImmutableArray.CreateBuilder<Attachment>(value.Length);
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
attachments.Add(RestAttachment.Create(value[i]));
|
||||
attachments.Add(Attachment.Create(value[i]));
|
||||
_attachments = attachments.ToImmutable();
|
||||
}
|
||||
else
|
||||
_attachments = ImmutableArray.Create<RestAttachment>();
|
||||
_attachments = ImmutableArray.Create<Attachment>();
|
||||
}
|
||||
|
||||
if (model.Embeds.IsSpecified)
|
||||
@@ -76,13 +78,13 @@ namespace Discord.Rest
|
||||
var value = model.Embeds.Value;
|
||||
if (value.Length > 0)
|
||||
{
|
||||
var embeds = ImmutableArray.CreateBuilder<RestEmbed>(value.Length);
|
||||
var embeds = ImmutableArray.CreateBuilder<Embed>(value.Length);
|
||||
for (int i = 0; i < value.Length; i++)
|
||||
embeds.Add(RestEmbed.Create(value[i]));
|
||||
embeds.Add(Embed.Create(value[i]));
|
||||
_embeds = embeds.ToImmutable();
|
||||
}
|
||||
else
|
||||
_embeds = ImmutableArray.Create<RestEmbed>();
|
||||
_embeds = ImmutableArray.Create<Embed>();
|
||||
}
|
||||
|
||||
ImmutableArray<RestUser> mentions = ImmutableArray.Create<RestUser>();
|
||||
@@ -105,6 +107,7 @@ namespace Discord.Rest
|
||||
_mentionedUsers = MentionUtils.GetUserMentions(text, null, mentions);
|
||||
_mentionedChannelIds = MentionUtils.GetChannelMentions(text, null);
|
||||
_mentionedRoles = MentionUtils.GetRoleMentions<RestRole>(text, null);
|
||||
_emojis = MessageHelper.GetEmojis(text);
|
||||
model.Content = text;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user