コード例 #1
0
        public static async Task <FormattedEmbedBuilder> BuildAsync(string name)
        {
            name = name.Trim();
            ChampionDataBuilder   championBuilder = new ChampionDataBuilder();
            FormattedEmbedBuilder message         = new FormattedEmbedBuilder();

            try
            {
                List <ChampionDto> matches = await championBuilder.GetMatchingChampionsAsync(name);

                if (matches.Count == 0)
                {
                    message
                    .AppendTitle($"{XayahReaction.Error} This didn't work")
                    .AppendDescription($"Oops! Your bad. I couldn't find a champion (fully or partially) named `{name}`.");
                }
                else if (matches.Count > 1)
                {
                    message
                    .AppendTitle($"{XayahReaction.Warning} This didn't went as expected")
                    .AppendDescription($"I found more than one champion (fully or partially) named `{name}`.");
                    foreach (ChampionDto champion in matches)
                    {
                        message.AppendDescription(Environment.NewLine + champion.Name);
                    }
                }
                else
                {
                    ChampionDto champion = await championBuilder.GetChampionAsync(matches.First().Id);

                    championBuilder.AppendMiscData(champion, message);
                    championBuilder.AppendStatisticData(champion, message);
                    championBuilder.AppendSpellData(champion, message);
                    championBuilder.AppendSkinData(champion, message);
                }
            }
            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
ファイル: CRiotData.cs プロジェクト: viktor-mains/XayahBot
        private async Task ProcessChamp(string name)
        {
            try
            {
                if (this.IsDisabled())
                {
                    this.NotifyDisabledCommand();
                    return;
                }
                IMessageChannel channel = await ChannelProvider.GetDMChannelAsync(this.Context);

                FormattedEmbedBuilder message = await ChampionDataBuilder.BuildAsync(name);

                await channel.SendEmbedAsync(message);

                await this.Context.Message.AddReactionIfNotDMAsync(this.Context, XayahReaction.Envelope);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }