Added IMessage.Emojis

This commit is contained in:
RogueException
2016-10-06 05:37:57 -03:00
parent 0b47d5bd2e
commit 9e982ccd4a
10 changed files with 115 additions and 51 deletions

View File

@@ -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();
}
}
}