Example #1
0
        public async Task <Discord.Embed> GetPlayerDetails(MembershipData player)
        {
            Console.WriteLine("getting player details: " + player.DisplayName);
            var queryType = platformLookup[player.MembershipType];
            HttpResponseMessage response = await QueryApi(String.Format("Destiny2/{0}/Profile/{1}{2}", queryType, player.MembershipId, "?components=200"));

            Console.WriteLine("done player details: " + player.DisplayName);

            var result         = response.Content.ReadAsStringAsync().Result;
            var responseObject = JObject.Parse(result);

            if ((int)responseObject["ErrorCode"] != 1)
            {
                return(null);
            }

            var data      = (JObject)responseObject["Response"]["characters"]["data"];
            var character = (JObject)data.Values <JToken>()
                            .Select(p => p.FirstOrDefault())
                            .OrderByDescending(p => DateTime.Parse((string)p["dateLastPlayed"])).First();

            Console.WriteLine("rendering view: " + player.DisplayName);

            return(viewBuilder.PlayerView(character, player.DisplayName));
        }