예제 #1
0
        public static async Task <GetBuildInfoResults> GetBuildInfoAsync(CommandContext context, [CallerMemberName] string callerMethodName = "")
        {
            await context.TriggerTypingAsync();

            var prefix = (callerMethodName == "NewBuild") ? _required : "";

            var message = await context.RespondAsync($"{prefix}Enter the http://www.grimtools.com/calc/ for the build");

            var response = await Program.Interactivity.WaitForMessageAsync(m => m.Author.Id == context.User.Id &&
                                                                           m.Channel.Id == context.Channel.Id);

            await message.DeleteAsync();

            if (response == null)
            {
                await context.TriggerTypingAsync();

                message = await context.RespondAsync("Command Timeout");

                await Task.Delay(5000)
                .ContinueWith(t => message.DeleteAsync())
                .ContinueWith(t => context.Message.DeleteAsync());

                return(null);
            }

            await response.Message.DeleteAsync();

            var buildUrl = await ValidateBuildUrlAsync(context, response.Message.Content);

            var grimToolsBuild = await GrimToolsCalc.GetGrimToolsCalcAsync(buildUrl);

            var mastery = grimToolsBuild.GetMasteryCombination();

            return(new GetBuildInfoResults {
                BuildUrl = buildUrl, Mastery = mastery
            });
        }
예제 #2
0
        public static async Task GrimToolsCalcHandler(MessageCreateEventArgs e)
        {
            if (e.Author.IsBot)
            {
                return;
            }

            var match = new Regex(@"(?<=(http://)?(www.)?grimtools.com/calc/)[a-zA-Z0-9]{8}(?!>)").Match(e.Message.Content);

            if (!match.Success)
            {
                return;
            }

            var url = $"http://www.grimtools.com/calc/{match.Value}";

            var calc = await GrimToolsCalc.GetGrimToolsCalcAsync(url);

            var masteryCombo = calc.GetMasteryCombination();

            var embed = new DiscordEmbedBuilder
            {
                Url          = url,
                ThumbnailUrl = masteryCombo.GetAttribute <MasteryInfoAttribute>().ImageUrl,

                Title = $"Level {calc.Data.Info.Level} " +
                        $"{Regex.Replace(masteryCombo.ToString(), @"(\B[A-Z])", " $1")}",

                Description = $"`Physique` {((calc.Data.Info.Physique - 50) / 8).ToString()}\n" +
                              $"`Cunning` {((calc.Data.Info.Cunning - 50) / 8).ToString()}\n" +
                              $"`Spirit` {((calc.Data.Info.Spirit - 50) / 8).ToString()}"
            };

            foreach (var mastery in calc.Data.Masteries.OrderByDescending(m => m.Value))
            {
                embed.AddField(mastery.Key.ToString(), mastery.Value.ToString(), true);
            }

            var sb           = new StringBuilder();
            var sortedSkills = calc.Data.Skills.OrderByDescending(s => s.Value).ToList();

            for (int i = 0; i < 10 && i < sortedSkills.Count; i++)
            {
                try
                {
                    var skillEmoji = EnumExtensions.GetValueFromDescription <SkillEmoji>(sortedSkills[i].Key);
                    sb.Append(DiscordEmoji.FromGuildEmote(Program.Client, (ulong)skillEmoji).ToString());
                }
                catch (ArgumentException)
                {
                    sortedSkills.RemoveAt(i);
                    i--;
                }
            }

            if (sb.Length > 0)
            {
                embed.AddField("Top Skill(s)", sb.ToString());
            }

            embed.WithFooter($"Game version: {calc.GameVersion}");

            embed.WithColor(new DiscordColor(masteryCombo.GetAttribute <MasteryInfoAttribute>().Color));

            await e.Message.RespondAsync("", false, embed.Build());
        }