/// <summary>Attempts to parse a unicode or guild emoji from its mention</summary>
        public static DiscordEmoji ToEmoji(this string text)
        {
            text = text.Trim();
            var match = Regex.Match(text, @"^<?a?:?([a-zA-Z0-9_]+):([0-9]+)>?$");

            if (!match.Success)
            {
                return(DiscordEmoji.TryFromUnicode(text, out var emoji) ? emoji : null);
            }
            string json = $"{{\"name\":\"{match.Groups[1].Value}\", \"id\":{match.Groups[2].Value}," +
                          $"\"animated\":{text.StartsWith("<a:").ToString().ToLower()}, \"require_colons\":true, \"available\":true}}";

            return(JsonConvert.DeserializeObject <DiscordEmoji>(json));
        }
Exemple #2
0
    public async Task InitReactionsAsync(CommandContext context, DiscordMessage message)
    {
        RoleMessage tracked = await _service.GetTrackedMessageAsync(message);

        foreach (string reaction in tracked.Roles.Keys)
        {
            if (!DiscordEmoji.TryFromUnicode(context.Client, reaction, out DiscordEmoji emoji))
            {
                DiscordEmoji.TryFromName(context.Client, $":{reaction}:", out emoji);
            }

            await message.CreateReactionAsync(emoji);
        }

        await message.RespondAsync("Reactions initialized.");
    }