Пример #1
0
        public async Task <FormattedEmbedBuilder> BuildForRoleAsync(LeagueRole role)
        {
            FormattedEmbedBuilder message = new FormattedEmbedBuilder();

            try
            {
                await this.LoadFromApi();

                if (LeagueRole.All.Equals(role))
                {
                    foreach (LeagueRole leagueRole in LeagueRole.Values())
                    {
                        this.AppendStatsOfRole(leagueRole, 3, message);
                    }
                }
                else
                {
                    this.AppendStatsOfRole(role, 6, message);
                }
                message.AppendTitle($"{XayahReaction.Clipboard} Winrates");
                ChampionStatsDto first = this._championStats.ElementAtOrDefault(0);
                if (first != null)
                {
                    message.AppendTitle($" for Patch {first.Patch}");
                }
                message.AppendDescription("Short explanation of the table: `Position - Win % - Play %` - Name", AppendOption.Italic);
            }
            catch (NoApiResultException)
            {
                message = new FormattedEmbedBuilder()
                          .AppendTitle($"{XayahReaction.Error} This didn't work")
                          .AppendDescription("Apparently some random API refuses cooperation. Have some patience while I convince them again...");
            }
            return(message);
        }
Пример #2
0
 public override bool Equals(object obj)
 {
     if (obj != null && obj is LeagueRole)
     {
         LeagueRole compObj = obj as LeagueRole;
         return(this.ApiRole.Equals(compObj.ApiRole));
     }
     return(false);
 }
Пример #3
0
 public static LeagueRole GetByApiRole(string role)
 {
     if (!string.IsNullOrWhiteSpace(role))
     {
         role = role.ToUpper();
         LeagueRole match = Values().FirstOrDefault(x => x.ApiRole.Equals(role));
         if (match != null)
         {
             return(match);
         }
     }
     throw new NotExistingException();
 }
Пример #4
0
 public static LeagueRole Get(string role)
 {
     if (!string.IsNullOrWhiteSpace(role))
     {
         role = role.ToLower();
         LeagueRole match = Values().FirstOrDefault(x => x._matches.Contains(role));
         if (match != null)
         {
             return(match);
         }
     }
     throw new NotExistingException();
 }
Пример #5
0
        private async Task ProcessWinrate(LeagueRole role)
        {
            try
            {
                if (role == null)
                {
                    role = LeagueRole.All;
                }
                ChampionStatsBuilder  statsBuilder = new ChampionStatsBuilder();
                FormattedEmbedBuilder message      = await statsBuilder.BuildForRoleAsync(role);

                message.CreateFooterIfNotDM(this.Context);
                await this.ReplyAsync(message);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }
Пример #6
0
        private void AppendStatsOfRole(LeagueRole role, int entryCount, FormattedEmbedBuilder message)
        {
            List <ChampionStatsDto> roleStats = this._championStats.Where(x => x.Role.Equals(role.ApiRole)).ToList();

            if (entryCount * 2 > roleStats.Count)
            {
                entryCount = (int)Math.Truncate(roleStats.Count / (decimal)2);
            }
            FormattedTextBuilder winrates = new FormattedTextBuilder();

            for (int i = 0; i < entryCount && i < roleStats.Count; i++)
            {
                ChampionStatsDto topX         = roleStats.ElementAt(i);
                string           championLine = this.BuildChampionStats(topX, i + 1);
                if (i > 0)
                {
                    winrates.AppendNewLine();
                }
                winrates.Append(championLine);
            }
            if (roleStats.Count > entryCount * 2)
            {
                winrates.AppendNewLine();
            }
            for (int i = roleStats.Count - entryCount; i >= 0 && i < roleStats.Count; i++)
            {
                ChampionStatsDto bottomX      = roleStats.ElementAt(i);
                string           championLine = this.BuildChampionStats(bottomX, i + 1);
                winrates.AppendNewLine().Append(championLine);
            }
            string resultText = winrates.ToString();

            if (string.IsNullOrWhiteSpace(resultText))
            {
                resultText = ". . .";
            }
            message.AddField(role.Name, resultText, new AppendOption[] { AppendOption.Underscore });
        }
Пример #7
0
 //[Command("stats")]
 public Task Stats([OverrideTypeReader(typeof(LeagueRoleTypeReader))] LeagueRole role, [Remainder] string name)
 {
     //Task.Run(() => this.ProcessStats());
     return(Task.CompletedTask);
 }
Пример #8
0
 //[Command("winrate")]
 public Task Winrate([OverrideTypeReader(typeof(LeagueRoleTypeReader))] LeagueRole role = null)
 {
     Task.Run(() => this.ProcessWinrate(role));
     return(Task.CompletedTask);
 }