Пример #1
0
        public async Task HandleMessageAsync(SocketUserMessage message)
        {
            var reacts = await GetMatchingReacts(message);

            if (reacts.Count == 0)
            {
                return;
            }

            var emojis = reacts.Select(react => react.Emoji);

            foreach (var emoji in emojis)
            {
                var emote = client.GetEmote(emoji);

                if (!emote.IsSuccess)
                {
                    var basicEmoji = new Emoji(emoji);
                    await message.AddReactionAsync(basicEmoji);

                    continue;
                }

                await message.AddReactionAsync(emote.Value);
            }
        }
Пример #2
0
        /// <summary>
        /// Replace all custom emotes (such as :pog:) with the actual emote, if found by the bot.
        /// </summary>
        /// <param name="client">The discord client.</param>
        /// <param name="msg">The message.</param>
        /// <returns>The message with all found emotes replaced.</returns>
        public static string ReplaceEmojis(this DiscordSocketClient client, string msg)
        {
            var matches = Regex.Matches(msg, ":(.+?):")
                          .GroupBy(match => new { match.Value })
                          .Select(o => o.FirstOrDefault());

            foreach (Match match in matches)
            {
                var emoteName = match.Captures[0].Value.Trim(':');
                var emote     = client.GetEmote(emoteName);

                if (!emote.IsSuccess)
                {
                    continue;
                }

                msg = msg.Replace(match.Value, emote.Value.ToString());
            }

            return(msg);
        }