Exemplo n.º 1
0
        public static async Task <PlayerModel> GetPlayerInfoFromR6DB(string text, string baseUrl, string xAppId)
        {
            var requestUri = $"{baseUrl}/Players";

            var region            = regionEnum.GetAttribute <RegionInformation>().Description;
            var platform          = platformEnum.GetAttribute <PlatformInformation>().Description;
            var technicalPlatform = platformEnum.GetAttribute <PlatformInformation>().TechnicalName;

            var queryParams = new List <KeyValuePair <string, string> >();

            queryParams.Add(new KeyValuePair <string, string>("name", text));
            queryParams.Add(new KeyValuePair <string, string>("platform", technicalPlatform));
            queryParams.Add(new KeyValuePair <string, string>("exact", "true")); //to make sure the name is exactly this. TODO: change this later into less exact with intelligence for questions like "did you mean.... "

            var response = await HttpRequestFactory.Get(requestUri, xAppId, queryParams);

            var responseString = await response.Content.ReadAsStringAsync();

            var jsonSerializerSettings = new JsonSerializerSettings
            {
                MissingMemberHandling = MissingMemberHandling.Ignore
            };
            var outputModel = JsonConvert.DeserializeObject <IList <PlayerModel> >(responseString, jsonSerializerSettings);

            if (outputModel.Count == 0)
            {
                return(null);
            }

            //Find the best match, if there isn't anyone with this exact name, than return the first one we found (likely to be the best)
            var model = new PlayerModel();

            model = outputModel.Where(m => m.name.ToLower() == text.ToLower()).FirstOrDefault();
            if (model == null)
            {
                //await ReplyAsync($"We found **{outputModel.Count}** likely results for the name **{text}** if the folowing stats are not the once you are looking for, please be more specific with the name/region/platform.");
                model         = outputModel.FirstOrDefault();
                model.guessed = new GuessedModel
                {
                    IsGuessed    = true,
                    PlayersFound = outputModel.Count
                };
            }

            var playerURL = $"{baseUrl}/Players/{model.id}";

            var queryParams2 = new List <KeyValuePair <string, string> >();
            var response2    = await HttpRequestFactory.Get(playerURL, xAppId, queryParams2);

            var responseString2 = await response2.Content.ReadAsStringAsync();

            var jsonSerializerSettings2 = new JsonSerializerSettings
            {
                MissingMemberHandling = MissingMemberHandling.Ignore
            };
            var fullModel = JsonConvert.DeserializeObject <PlayerModel>(responseString2, jsonSerializerSettings2);

            fullModel.guessed = model.guessed;
            return(fullModel);
        }
Exemplo n.º 2
0
        private async Task SendCasualInformationMessage(PlayerModel model, RegionInfo regionInfo)
        {
            var builder = new EmbedBuilder();

            var region   = regionEnum.GetAttribute <RegionInformation>().Description;
            var platform = platformEnum.GetAttribute <PlatformInformation>().Description;

            builder.AddField("General Information", "**Level:** " + model?.level);

            if (model?.stats?.casual != null)
            {
                TimeSpan timePlayed = TimeSpan.FromSeconds((double)model?.stats?.casual?.timePlayed);

                builder.AddInlineField(region + " All Time", "**Total Played: ** " + model?.stats?.casual?.played + Environment.NewLine +
                                       "**Total W/L (Ratio):** " + model?.stats?.casual?.won + " / " + model?.stats?.casual?.lost + " **(" + GetRatio(model?.stats?.casual?.won, model?.stats?.casual?.lost) + ")**" + Environment.NewLine +
                                       "**Total K/D (Ratio):** " + model?.stats?.casual?.kills + " / " + model?.stats?.casual?.deaths + " **(" + GetRatio(model?.stats?.casual?.kills, model?.stats?.casual?.deaths) + ")**");
            }

            if (model?.lastPlayed != null)
            {
                TimeSpan casualSeconds = TimeSpan.FromSeconds((double)model?.lastPlayed?.casual);

                builder.AddInlineField("**Play Time**", ToReadableString(casualSeconds));
                builder.AddInlineField("**Last Played**", model?.lastPlayed.last_played?.ToString("dd MMMM yyyy hh:mm:ss"));
            }

            builder.ImageUrl    = "https://ubistatic-a.akamaihd.net/0058/prod/assets/images/season5-casual20.f31680a7.svg";
            builder.Description = region + " Casual information on " + platform + " for **" + model.name + "**";

            builder.Author = new EmbedAuthorBuilder
            {
                IconUrl = "https://i.redd.it/iznunq2m8vgy.png",
                Name    = platform + " " + region + " Casual Information",
                Url     = "http://r6db.com/player/" + model.id
            };

            builder.Footer = new EmbedFooterBuilder
            {
                IconUrl = "https://i.redd.it/iznunq2m8vgy.png",
                Text    = "Created by Dakpan#6955"
            };

            builder.ThumbnailUrl = "https://cdn.thingiverse.com/renders/7b/83/18/94/0c/f3106dba9117e872f7f57f851a95bba5_preview_card.jpg";
            builder.Timestamp    = DateTime.UtcNow;
            builder.Url          = "http://r6db.com/player/" + model.id;

            builder.WithColor(Color.Orange);

            await ReplyAsync(string.Empty, false, builder);
        }
        private async Task SendPlayerInformationMessage(PlayerModel model)
        {
            var rankNr  = 0;
            var builder = new EmbedBuilder();

            var region   = regionEnum.GetAttribute <RegionInformation>().Description;
            var platform = platformEnum.GetAttribute <PlatformInformation>().Description;

            var placementInfo = "";

            if (model?.placements != null)
            {
                placementInfo = Environment.NewLine +
                                "**Global Rank:** " + model?.placements?.global ?? " not placed " + Environment.NewLine +
                                "**Europe Rank:** " + model?.placements?.emea ?? " not placed " + Environment.NewLine +
                                "**America Rank:** " + model?.placements?.ncsa ?? " not placed " + Environment.NewLine +
                                "**Asia Rank:** " + model?.placements?.apac ?? " not placed " + Environment.NewLine;
            }

            builder.AddField("General Information", "**Level:** " + model?.level + placementInfo);


            builder.AddField("Technical Information", "**ID:** " + model?.id + Environment.NewLine +
                             "**UserID:** " + model?.userId ?? "Unkown" + Environment.NewLine +
                             "**Profile Added:** " + model?.created_at.ToString("dd MMMM yyyy hh:mm:ss") + Environment.NewLine +
                             "**Last Played:** " + model?.lastPlayed.last_played?.ToString("dd MMMM yyyy hh:mm:ss") + Environment.NewLine);

            if (model?.aliases != null)
            {
                var aliases = "";
                foreach (var alias in model?.aliases)
                {
                    aliases += alias.name + Environment.NewLine + "    `" + alias.created_at.ToString("dd MMMM yyyy hh:mm:ss") + "`" + Environment.NewLine + Environment.NewLine;
                }
                builder.AddField("Aliases", aliases);
            }

            builder.ImageUrl    = "https://ubistatic-a.akamaihd.net/0058/prod/assets/images/season5-rank20.f31680a7.svg";
            builder.Description = region + " Player Profile information on " + platform + " for **" + model.name + "**";

            builder.Author = new EmbedAuthorBuilder
            {
                IconUrl = "https://i.redd.it/iznunq2m8vgy.png",
                Name    = platform + " " + region + " Player Profile",
                Url     = "http://r6db.com/player/" + model.id
            };

            builder.Footer = new EmbedFooterBuilder
            {
                IconUrl = "https://i.redd.it/iznunq2m8vgy.png",
                Text    = "Created by Dakpan#6955"
            };

            builder.ThumbnailUrl = GetRankImage(rankNr);
            builder.Timestamp    = DateTime.UtcNow;
            builder.Url          = "http://r6db.com/player/" + model.id;

            builder.WithColor(Color.Orange);

            await ReplyAsync(string.Empty, false, builder);
        }
        private async Task SendRankedInformationMessage(PlayerModel model, RegionInfo regionInfo)
        {
            var rankNr  = 0;
            var builder = new EmbedBuilder();

            var region   = regionEnum.GetAttribute <RegionInformation>().Description;
            var platform = platformEnum.GetAttribute <PlatformInformation>().Description;

            builder.AddField("General Information", "**Level:** " + model?.level);

            if (regionInfo != null)
            {
                builder.AddInlineField(region + " Current Season", "**Rank:** " + ToReadableRank(regionInfo.rank) + Environment.NewLine +
                                       "**MMR:** " + regionInfo.mmr + Environment.NewLine +
                                       "**Highest MMR:** " + regionInfo.max_mmr + Environment.NewLine +
                                       "**Next Rank:** " + CeilingRankMMR(regionInfo.rank) + Environment.NewLine +
                                       "**W/L/A:** " + regionInfo.wins + "/" + regionInfo.losses + "/" + regionInfo.abandons + Environment.NewLine +
                                       "**W/L Ratio:** **" + GetRatio(regionInfo.wins, regionInfo.losses) + "**");

                if (rankNr < regionInfo.rank)
                {
                    rankNr = regionInfo.rank;
                }
            }

            if (model?.stats?.ranked != null)
            {
                TimeSpan timePlayed = TimeSpan.FromSeconds((double)model?.stats?.ranked?.timePlayed);

                builder.AddInlineField(region + " All Time", "**Total Played: ** " + model?.stats?.ranked?.played + Environment.NewLine +
                                       "**Total W/L (Ratio):** " + model?.stats?.ranked?.won + " / " + model?.stats?.ranked?.lost + " **(" + GetRatio(model?.stats?.ranked?.won, model?.stats?.ranked?.lost) + ")**" + Environment.NewLine +
                                       "**Total K/D (Ratio):** " + model?.stats?.ranked?.kills + " / " + model?.stats?.ranked?.deaths + " **(" + GetRatio(model?.stats?.ranked?.kills, model?.stats?.ranked?.deaths) + ")**");
            }

            if (model?.lastPlayed != null)
            {
                TimeSpan rankSeconds = TimeSpan.FromSeconds((double)model?.lastPlayed?.ranked);

                builder.AddInlineField("**Play Time**", ToReadableString(rankSeconds));
                builder.AddInlineField("**Last Played**", model?.lastPlayed.last_played?.ToString("dd MMMM yyyy hh:mm:ss"));
            }

            builder.ImageUrl    = "https://ubistatic-a.akamaihd.net/0058/prod/assets/images/season5-rank20.f31680a7.svg";
            builder.Description = region + " Ranked information on " + platform + " for **" + model.name + "**";

            builder.Author = new EmbedAuthorBuilder
            {
                IconUrl = "https://i.redd.it/iznunq2m8vgy.png",
                Name    = platform + " " + region + " Ranked Information",
                Url     = "http://r6db.com/player/" + model.id
            };

            builder.Footer = new EmbedFooterBuilder
            {
                IconUrl = "https://i.redd.it/iznunq2m8vgy.png",
                Text    = "Created by Dakpan#6955"
            };

            builder.ThumbnailUrl = GetRankImage(rankNr);
            builder.Timestamp    = DateTime.UtcNow;
            builder.Url          = "http://r6db.com/player/" + model.id;

            builder.WithColor(Color.Orange);

            await ReplyAsync(string.Empty, false, builder);
        }