Exemple #1
0
        public async Task GetShopAsync()
        {
            string url = "https://fortnite-api.theapinetwork.com/store/get";

            // Set up http client
            HttpClient _httpClient = new HttpClient();

            _httpClient = ApiHandler.InitClient();

            string json;
            HttpResponseMessage res = await _httpClient.GetAsync(url);

            json = res.Content.ReadAsStringAsync().Result;

            Rootobject shop = JsonConvert.DeserializeObject <Rootobject>(json);

            for (int i = 0; i < shop.data.Length; i++)
            {
                var embed = new EmbedBuilder();
                embed.WithTitle(shop.data[i].item.name)
                .AddField("VBucks", shop.data[i].store.cost)
                .WithDescription(shop.data[i].item.description)
                .WithColor(Color.Magenta)
                .ThumbnailUrl = shop.data[i].item.images.icon;
                await Context.Channel.SendMessageAsync(embed : embed.Build());
            }
        }
Exemple #2
0
        public async Task GetStatsAsync([Remainder][Summary("Platform/User")] string args)
        {
            ////////
            Console.WriteLine(args);

            string platform = args.Split('"')[2].TrimStart();
            string user     = args.Split('"')[1];
            string url      = $"https://api.fortnitetracker.com/v1/profile/{platform}/{user}";
            string json;

            Console.WriteLine("User: "******"Platform: " + platform);

            Console.WriteLine("Retrieving Stats from API...");
            HttpClient _httpClient = new HttpClient();

            _httpClient = ApiHandler.InitClient();
            HttpResponseMessage res = await _httpClient.GetAsync(url);

            json = res.Content.ReadAsStringAsync().Result;

            JObject apiResults = JObject.Parse(json);
            JToken  kills      = apiResults["lifeTimeStats"][10]["value"];
            JToken  wins       = apiResults["lifeTimeStats"][8]["value"];
            JToken  kd         = apiResults["lifeTimeStats"][11]["value"];
            JToken  winP       = apiResults["lifeTimeStats"][9]["value"];

            FNStatsDTO stats = new FNStatsDTO();

            stats.kills = kills.ToObject <double>();
            stats.wins  = wins.ToObject <double>();
            stats.kd    = kd.ToObject <double>();
            stats.winP  = winP.ToObject <string>();
            string _user = Regex.Replace(user, "[(/)]", "");

            var embed = new EmbedBuilder();

            embed.WithTitle(_user + "'s Lifetime Stats:")
            .AddField("Total Kills", stats.kills)
            .AddField("Total Wins", stats.wins)
            .AddField("Kill/Death Ratio", stats.kd)
            .AddField("Win Percentage", stats.winP)
            .WithColor(Color.Magenta);

            Console.WriteLine($"Stats Fetched..");
            await Context.Channel.SendMessageAsync(embed : embed.Build());
        }
Exemple #3
0
        public async Task GetVideoAsync([Remainder][Summary("Query")] string args)
        {
            Console.WriteLine(args);

            string key   = "AIzaSyABeXIVpaTxdoZMKySRAxyyFMpKhgToHo0";
            string query = args.Replace(" ", "%20");

            Console.WriteLine("query term: " + query);
            string apiUrl =
                $"https://www.googleapis.com/youtube/v3/search?part=snippet&q={query}&key={key}";
            // replace whitespace in query with '%20'

            // Set up http Client
            HttpClient _httpClient = new HttpClient();

            _httpClient = ApiHandler.InitClient();
            HttpResponseMessage res = await _httpClient.GetAsync(apiUrl);

            // Create string from json response
            string json = res.Content.ReadAsStringAsync().Result;


            // Create results object from json (str) results
            Rootobject results = JsonConvert.DeserializeObject <Rootobject>(json);

            // Create Video object from first (most relevant) result
            Item Video = new Item();

            Video = Array.Find(results.items, f => f.id.kind == "youtube#video");

            var embed = new EmbedBuilder();

            embed.WithTitle(Video.snippet.title)
            .AddField("Channel", Video.snippet.channelTitle)
            .WithDescription(Video.snippet.description)
            .WithColor(Color.DarkTeal)
            .WithUrl($"https://www.youtube.com/watch?v={Video.id.videoId}")
            .WithImageUrl(Video.snippet.thumbnails.high.url);

            await Context.Channel.SendMessageAsync(embed : embed.Build());
        }