Esempio n. 1
0
        /// <summary>
        /// Updates the information for an entire guild on realm.
        /// </summary>
        /// <param name="guild">The guild to update.</param>
        /// <returns>Output string designed to be sent to the channel.</returns>
        private async Task <CommandResult> UpdateGuild(GuildInfo guild)
        {
            // time how long it takes me to get everyone.
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();

            // refresh and report
            bool refresh_successful = await guild.Refresh(s => Log(s));

            if (refresh_successful)
            {
                // build output string
                StringBuilder sb = new StringBuilder();
                sb.AppendLine($"`{guild.Guild}` has {guild.CharacterCount} characters, {guild.TargetLevelCharacterCount} are level {guild.TargetLevel}.");

                if (guild.TargetLevelCharacterCount == 0)
                {
                    sb.AppendLine($"Since none are {guild.TargetLevel}, I won't bother looking up their item levels. :wink:");
                    return(new CommandResult(sb.ToString()));
                }

                int number_shown = Math.Min(guild.GuildMembers.Count, _config.MaxGuildCharacters);

                sb.AppendLine($"Here's the top {number_shown} ('in bags' ilvl in parenthesis)");

                // asciidoc code blocks have some nice syntax highlighting I can abuse.
                // lines starting "<text> :: <text>" will have the first text and double colon turned red.
                // lines with a line of dashes or equals under them will be blue (with the dashed line)
                // lines with text like "[<text>]" will be red, as will ":<text>:"
                // lines starting with * or - will have the * or - colored red.
                // some basic markdown shows too, (without eating characters) which is neat.
                sb.AppendLine("```asciidoc");

                sb.AppendLine($"{guild.Guild}");
                sb.AppendLine("-----");

                // include the top maxMembers characters
                int count = 0;
                foreach (var c in guild.GuildMembers)
                {
                    sb.AppendLine($"{c.character.items.calculatedItemLevel:0.00} ({c.character.items.averageItemLevel}) :: {c.guildCharacter.name}");

                    ++count;
                    if (count >= _config.MaxGuildCharacters)
                    {
                        break;
                    }
                }

                // let them know about anyone I failed to get information on.
                if (guild.FailedCharacters.Count > 0)
                {
                    sb.AppendLine("");
                    sb.Append("I had a problem getting info for: ");
                    foreach (var f in guild.FailedCharacters)
                    {
                        sb.Append(f + ", ");
                    }

                    sb.Remove(sb.Length - 2, 2);
                }

                // close the code block.
                sb.AppendLine("```");

                var secondsS = (int)sw.Elapsed.TotalSeconds != 1 ? "s" : "";
                sb.AppendLine($"It took me {sw.Elapsed.TotalSeconds:0} second{secondsS} to look everyone up.");

                // build a nice embed to wrap it all up in.
                EmbedFooterBuilder efb = new EmbedFooterBuilder()
                                         .WithText(AssemblyExtensions.ShortName);

                DateTimeOffset dto = DateTime.SpecifyKind(guild.LastRefresh, DateTimeKind.Local);

                EmbedBuilder builder = new EmbedBuilder()
                {
                    // title/url for wowprogress
                    Title = $"{guild.Guild} Item Level Report",
                    //Url = "maybe get an armory url here...",

                    // some general pretty
                    Color = Color.DarkPurple,

                    // description is my primary output
                    Description = sb.ToString(),

                    // footer for timestamp and appname
                    Footer = efb,

                    // and the date/time.
                    Timestamp = dto,
                };

                return(new CommandResult(builder.Build()));
            }

            // something went wrong, report the error.
            return(new CommandResult($"There was an issue getting the info: {guild.LastError}"));
        }