private string FormatBeholdLine(SocketUserMessage message, CrewData crew)
        {
            List <string> result = new List <string>();

            result.Add($"[Full details for {crew.name}]({_datacoreURL}crew/{crew.symbol}/)");

            result.Add(FormatCrewStatsWithEmotes(message, crew));

            var rankLine = $"Voyage #{crew.ranks.voyRank}, Gauntlet #{crew.ranks.gauntletRank}, {(crew.events.HasValue ? crew.events.Value : 0)} events, {crew.collections.Count()} collections";

            if (crew.bigbook_tier.HasValue)
            {
                rankLine += $", Big book **tier {crew.bigbook_tier.Value}**";
            }
            result.Add(rankLine);

            var coolRanks = CrewFormatter.FormatCrewCoolRanks(crew, true);

            if (!string.IsNullOrEmpty(coolRanks))
            {
                result.Add($"*{coolRanks}*");
            }

            return(string.Join("\n", result));
        }
Beispiel #2
0
        private string FormatReplyPost(SearchResults result, string postTitle)
        {
            CrewData[] crew = { _botHelper.GetCrew(result.crew1.symbol), _botHelper.GetCrew(result.crew2.symbol), _botHelper.GetCrew(result.crew3.symbol) };

            if ((crew[0] == null) || (crew[1] == null) || (crew[2] == null))
            {
                return(string.Empty);
            }

            string title;
            var    best = BeholdFormatter.GetBest(result, crew, out title);

            var c1s = CrewFormatter.FormatCrewStats(crew[0], false);
            var c2s = CrewFormatter.FormatCrewStats(crew[1], false);
            var c3s = CrewFormatter.FormatCrewStats(crew[2], false);

            DateTime FutureDate = new DateTime(2020, 3, 1);
            DateTime TodayDate  = DateTime.Now;
            int      days       = (FutureDate - TodayDate).Days;

            if (days <= 0)
            {
                return(string.Empty);
            }

            if (postTitle.StartsWith("Behold", StringComparison.CurrentCultureIgnoreCase) && (postTitle.Split(',').Length > 1))
            {
                // Appears to have correct title format
                Func <int, string> perCrewFormat = index =>
                {
                    var mainRanks = $@"Voyage #{crew[index].ranks.voyRank} | Gauntlet #{crew[index].ranks.gauntletRank}";
                    var statLine  = string.Join(" | ", CrewFormatter.FormatCrewStats(crew[index], true));
                    return($@"# [{crew[index].name}]({_datacoreURL}crew/{crew[index].symbol})

Big Book {(crew[index].bigbook_tier.HasValue ? $"**Tier {crew[index].bigbook_tier.Value}**" : "unranked")} | {mainRanks} | {CrewFormatter.FormatCrewCoolRanks(crew[index], false, " | ")} | {crew[index].collections.Length} collection(s) | {(crew[index].events.HasValue ? $"{crew[index].events.Value} event(s)" : "No events")}

{statLine}

{crew[index].markdownContent}");
                };

                return($@"{title} (but read the [detailed comparison]({_datacoreURL}behold/?crew={crew[0].symbol}&crew={crew[1].symbol}&crew={crew[2].symbol}) to see what makes sense for your roster).

{perCrewFormat(0)}

{perCrewFormat(1)}

{perCrewFormat(2)}

Talk to TemporalAgent7 if you have questions or comments!

**The bot will stop replying in {days} days. Please use [Discord](https://discord.gg/8Du7ZtJ); read [here](https://www.reddit.com/r/StarTrekTimelines/comments/eryf5l/reddit_behold_bot_retiring/) for details.**
");
            }

            return($@"This post appears to be a behold, but it doesn't follow the [subreddit rule](https://www.reddit.com/r/StarTrekTimelines/comments/cgf25y/new_subreddit_rule_regarding_behold_posts/) for Behold posts; your post title should be `Behold! {crew[0].name}, {crew[1].name}, {crew[2].name}`. You can delete it and repost if you want me to reply with details. I'll stop replying in {days} days.");
        }
 private static string FormatCrewStatsWithEmotes(SocketUserMessage message, CrewData crew, int raritySearch = 0, bool forGauntlet = false)
 {
     return(string.Join(" ", CrewFormatter.FormatCrewStats(crew, true, raritySearch, forGauntlet).Select(s => $"{s.Replace("^", " ")}"))
            .Replace("SCI", GetEmoteOrString(message, "sci", "SCI"))
            .Replace("SEC", GetEmoteOrString(message, "sec", "SEC"))
            .Replace("ENG", GetEmoteOrString(message, "eng", "ENG"))
            .Replace("DIP", GetEmoteOrString(message, "dip", "DIP"))
            .Replace("CMD", GetEmoteOrString(message, "cmd", "CMD"))
            .Replace("MED", GetEmoteOrString(message, "med", "MED")));
 }
        private async Task HandleMessageStats(string searchString, SocketUserMessage message, bool extended)
        {
            int raritySearch = 0;

            if (searchString.IndexOf("-s") > 4)
            {
                var paramStart = searchString.IndexOf("-s");
                var paramValue = searchString.Substring(paramStart + 2);
                searchString = searchString.Substring(0, paramStart);

                if (int.TryParse(paramValue.Trim(), out int pv))
                {
                    raritySearch = pv;
                }
            }

            if ((raritySearch < 0) || (raritySearch > 5))
            {
                await message.Channel.SendMessageAsync($"If you're looking for stats at a specific number of stars, use a valid number for the -s option ({raritySearch} is invalid)");

                return;
            }

            var results = _botHelper.SearchCrew(searchString);

            if (results.Count == 0)
            {
                await message.Channel.SendMessageAsync($"Sorry, I couldn't find a crew matching '{searchString}'");
            }
            else if (results.Count == 1)
            {
                var crew  = results[0];
                var embed = new EmbedBuilder()
                {
                    Title        = crew.name,
                    Color        = FromRarity(crew.max_rarity),
                    ThumbnailUrl = $"{_datacoreURL}media/assets/{crew.imageUrlPortrait}",
                    Url          = $"{_datacoreURL}crew/{crew.symbol}/"
                };

                embed = embed.AddField("Traits", $"{string.Join(", ", crew.traits_named)}*, {string.Join(", ", crew.traits_hidden)}*");

                if ((raritySearch <= 0) || (raritySearch >= crew.max_rarity))
                {
                    raritySearch = 1;
                }

                string statLine = new string('тнР', raritySearch) + new string('X', crew.max_rarity - raritySearch).Replace("X", "ЁЯМС") + " " + FormatCrewStatsWithEmotes(message, crew, raritySearch) + "\n\n" +
                                  new string('тнР', crew.max_rarity) + " " + FormatCrewStatsWithEmotes(message, crew);

                embed = embed.AddField("Stats", statLine)
                        .AddField("Voyage Rank", $"{crew.ranks.voyRank} of {_botHelper.TotalCrew()}", true)
                        .AddField("Gauntlet Rank", $"{crew.ranks.gauntletRank} of {_botHelper.TotalCrew()}", true)
                        .AddField("Estimated Cost", $"{crew.totalChronCost} {GetEmoteOrString(message, "chrons", "chrons")}, {crew.factionOnlyTotal} faction", true)
                        .AddField("Difficulty", $"{(100 - (crew.ranks.chronCostRank * 100) / _botHelper.TotalCrew())}%", true)
                        .WithFooter(footer => footer.Text = CrewFormatter.FormatCrewCoolRanks(crew));

                if (crew.bigbook_tier.HasValue && crew.events.HasValue)
                {
                    embed = embed.AddField("Bigbook Tier", crew.bigbook_tier.Value, true)
                            .AddField("Events", crew.events.Value, true);
                }

                if (crew.collections.Count() > 0)
                {
                    embed = embed.AddField("Collections", string.Join(", ", crew.collections.Select(c => $"[{c}]({_datacoreURL}collection/{c.Replace(" ", "%20")}/)")));
                }

                if (extended && !string.IsNullOrEmpty(crew.markdownContent) && (crew.markdownContent.Length < 980))
                {
                    embed = embed.AddField("Book contents", crew.markdownContent);
                }

                await message.Channel.SendMessageAsync("", false, embed.Build());

                if (extended && !string.IsNullOrEmpty(crew.markdownContent) && (crew.markdownContent.Length >= 980))
                {
                    await message.Channel.SendMessageAsync(crew.markdownContent);
                }
            }
            else
            {
                await message.Channel.SendMessageAsync($"There is more than one crew matching that: {string.Join(", ", results.Take(10).Select(crew => crew.name))}. Which one did you mean?");
            }
        }
        private async Task HandleMessageStats(string searchString, SocketUserMessage message, bool extended)
        {
            int raritySearch = 0;

            if (searchString.IndexOf("-s") > 4)
            {
                var paramStart = searchString.IndexOf("-s");
                var paramValue = searchString.Substring(paramStart + 2);
                searchString = searchString.Substring(0, paramStart);

                if (int.TryParse(paramValue.Trim(), out int pv))
                {
                    raritySearch = pv;
                }
            }

            if ((raritySearch < 0) || (raritySearch > 5))
            {
                await message.Channel.SendMessageAsync($"If you're looking for stats at a specific number of stars, use a valid number for the -s option ({raritySearch} is invalid)");

                return;
            }

            var results = _botHelper.SearchCrew(searchString);

            if (results.Count == 0)
            {
                await message.Channel.SendMessageAsync($"Sorry, I couldn't find a crew matching '{searchString}'");
            }
            else if (results.Count == 1)
            {
                var crew  = results[0];
                var embed = new EmbedBuilder()
                {
                    Title        = crew.name,
                    Color        = FromRarity(crew.max_rarity),
                    ThumbnailUrl = $"{_datacoreURL}media/assets/{crew.imageUrlPortrait}",
                    Url          = $"{_datacoreURL}crew/{crew.symbol}/"
                };

                embed = embed.AddField("Traits", $"{string.Join(", ", crew.traits_named)}*, {string.Join(", ", crew.traits_hidden)}*");

                if ((raritySearch <= 0) || (raritySearch >= crew.max_rarity))
                {
                    raritySearch = 1;
                }

                string statLine = new string('тнР', raritySearch) + new string('X', crew.max_rarity - raritySearch).Replace("X", "ЁЯМС") + " " + FormatCrewStatsWithEmotes(message, crew, raritySearch) + "\n\n" +
                                  new string('тнР', crew.max_rarity) + " " + FormatCrewStatsWithEmotes(message, crew);

                embed = embed.AddField("Stats", statLine)
                        .AddField("Voyage Rank", $"{crew.ranks.voyRank} of {_botHelper.TotalCrew()}", true)
                        .AddField("Gauntlet Rank", $"{crew.ranks.gauntletRank} of {_botHelper.TotalCrew()}", true)
                        .AddField("Estimated Cost", $"{crew.totalChronCost} {GetEmoteOrString(message, "chrons", "chrons")}, {crew.factionOnlyTotal} faction", true)
                        .AddField("Difficulty", $"{(100 - (crew.ranks.chronCostRank * 100) / _botHelper.TotalCrew())}%", true)
                        .WithFooter(footer => footer.Text = CrewFormatter.FormatCrewCoolRanks(crew));

                if (crew.bigbook_tier.HasValue && crew.events.HasValue)
                {
                    embed = embed.AddField("Bigbook Tier", crew.bigbook_tier.Value, true)
                            .AddField("Events", crew.events.Value, true);
                }

                if (extended)
                {
                    StringBuilder shipAbilities = new StringBuilder();
                    shipAbilities.AppendLine($"+{crew.action.bonus_amount} {crew.action.GetBonusType(crew.action.bonus_type)} | **Initialize:** {crew.action.initial_cooldown}s | **Duration:** {crew.action.duration}s | **Cooldown:** {crew.action.cooldown}s");

                    if (crew.action.ability != null)
                    {
                        shipAbilities.AppendLine($"**Bonus Ability: **{crew.action.ability.ToString()}");
                    }

                    if ((crew.action.charge_phases != null) && (crew.action.charge_phases.Length > 0))
                    {
                        var cps = crew.action.GetChargePhases();
                        for (var i = 0; i < cps.Length; i++)
                        {
                            shipAbilities.AppendLine($"**Charge Phase {i + 1}:** {cps[i]}");
                        }
                    }

                    if (crew.action.limit.HasValue)
                    {
                        shipAbilities.AppendLine($"**Uses:** {crew.action.limit.Value}");
                    }

                    embed = embed.AddField("Ship Abilities", shipAbilities.ToString());
                }

                if (crew.collections.Count() > 0)
                {
                    embed = embed.AddField("Collections", string.Join(", ", crew.collections.Select(c => $"[{c}]({_datacoreURL}collections#{c.Replace(" ", "%20")}/)")));
                }

                if (extended && !string.IsNullOrEmpty(crew.markdownContent) && (crew.markdownContent.Length < 980))
                {
                    embed = embed.AddField("Book contents", crew.markdownContent);
                }

                await message.Channel.SendMessageAsync("", false, embed.Build());

                if (extended && !string.IsNullOrEmpty(crew.markdownContent) && (crew.markdownContent.Length >= 980))
                {
                    if (crew.markdownContent.Length < 2048)
                    {
                        embed = new EmbedBuilder()
                        {
                            Title       = $"Big book details for {crew.name}",
                            Color       = FromRarity(crew.max_rarity),
                            Url         = $"{_datacoreURL}crew/{crew.symbol}/",
                            Description = crew.markdownContent
                        };

                        await message.Channel.SendMessageAsync("", false, embed.Build());
                    }
                    else
                    {
                        // The Big Book text is simply too long, it may need to be broken down into different messages (perhaps at paragraph breaks)
                        await message.Channel.SendMessageAsync(crew.markdownContent);
                    }
                }
            }
            else
            {
                await message.Channel.SendMessageAsync($"There is more than one crew matching that: {string.Join(", ", results.Take(10).Select(crew => crew.name))}. Which one did you mean?");
            }
        }