コード例 #1
0
        static async Task NotifyActionLogsMentionsFound(Dictionary <ulong, List <DiscordMessage> > warnDict, DiscordChannel channel)
        {
            foreach (ulong snowflake in warnDict.Keys)
            {   // Iterate through each user snowflake logged in the dictionary.
                // Only make an embed if there are actually mentions.
                if (warnDict[snowflake].Count > 0)
                {
                    var mentionList = warnDict[snowflake];

                    var embed         = new DiscordEmbedBuilder();
                    var stringBuilder = new StringBuilder();

                    // Build header.
                    stringBuilder.Append($"__**{Generics.GetMention(snowflake)} has had {mentionList.Count + 1} total mention{(mentionList.Count == 1 ? String.Empty : @"s")} (including the most recent one)" +
                                         $"in {channel.Mention} in the last {Program.Settings.MaxActionAgeMonths} months:**__\n");

                    // Build link list.
                    stringBuilder.AppendJoin(' ',
                                             Generics.BuildLimitedLinkList(
                                                 links: mentionList
                                                 .Select(a => Generics.GetMessageUrl(a))
                                                 .ToArray(),
                                                 endMessage: @"... Too many to display...",
                                                 maxLength: 2000 - stringBuilder.Length));

                    embed.WithDescription(stringBuilder.ToString());
                    embed.WithTitle($"Previous mention{(mentionList.Count == 1 ? String.Empty : @"s")} found");
                    embed.WithColor(DiscordColor.Red);

                    await channel.SendMessageAsync(embed : embed);
                } // end if
            }     // end foreach
        }