Added IMessage.Emojis
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user