Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.67 KB | None | 0 0
  1. [Command("twitchuser")]
  2.         public async Task twitchAsync(string username = "")
  3.         {
  4.            
  5.             if(username == "")
  6.             {
  7.                 await Context.Channel.SendMessageAsync("You need to give me an Channel Name to search for.");
  8.             }
  9.  
  10.             using (var client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }))
  11.             {
  12.                 string websiteurl = $"https://api.twitch.tv/kraken/channels/{username}?client_id=g8vz0dctlo417o6dz3gvol1ssws1ih";
  13.                 client.BaseAddress = new Uri(websiteurl);
  14.                 HttpResponseMessage response = client.GetAsync("").Result;
  15.                 response.EnsureSuccessStatusCode();
  16.                 string result = await response.Content.ReadAsStringAsync();
  17.                 var json = JObject.Parse(result);
  18.                
  19.                 string name = json["display_name"].ToString();
  20.                 string bio = json["status"].ToString();
  21.                 string created_at = json["created_at"].ToString();
  22.                 string logo = json["logo"].ToString();
  23.                 string updated_at = json["updated_at"].ToString();
  24.                 string views = json["views"].ToString();
  25.                 string followers = json["followers"].ToString();
  26.                 string game = json["game"].ToString();
  27.                 string url = json["url"].ToString();
  28.  
  29.                 string live = "";
  30.                 string playing_game = "";
  31.                 string viewers = "";
  32.                 string avg_fps = "";
  33.  
  34.                 using (var clientel = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }))
  35.                 {
  36.                     string weburl = $"https://api.twitch.tv/kraken/streams/{username}?client_id=g8vz0dctlo417o6dz3gvol1ssws1ih";
  37.                     clientel.BaseAddress = new Uri(weburl);
  38.                     HttpResponseMessage responds = clientel.GetAsync("").Result;
  39.                     responds.EnsureSuccessStatusCode();
  40.                     string results = await responds.Content.ReadAsStringAsync();
  41.                     var jsun = JObject.Parse(results);
  42.  
  43.                     var embed = new EmbedBuilder();
  44.  
  45.                     if (jsun["stream"] != null)
  46.                     {
  47.                         live = "Online";
  48.                         playing_game = jsun["stream"]["game"].ToString();
  49.                         viewers = jsun["stream"]["viewers"].ToString();
  50.                         avg_fps = jsun["stream"]["average_fps"].ToString();
  51.  
  52.                         embed.WithAuthor(author =>
  53.                         {
  54.                             author.WithName($"{name}'s Channel Info")
  55.                                    .WithUrl($"{url}")
  56.                                     .WithIconUrl($"https://seeklogo.com/images/T/twitch-tv-logo-51C922E0F0-seeklogo.com.png");
  57.                         })
  58.                         .WithDescription($"**Username:** {name}"
  59.                                    + "\n" +
  60.                                    $"**Bio:** {bio}"
  61.                                    + "\n" +
  62.                                    $"**Created At:** {created_at}"
  63.                                    + "\n" +
  64.                                    $"**Last Updated At:** {updated_at}"
  65.                                    + "\n" +
  66.                                    $"**Total Views:** {views}"
  67.                                    + "\n" +
  68.                                    $"**Followers:** {followers}"
  69.                                    + "\n \n" +
  70.                                    $"**Status:** {live}"
  71.                                    + "\n" +
  72.                                    $"**Playing Game:** {playing_game}"
  73.                                    + "\n" +
  74.                                    $"**Viewers**: {viewers}"
  75.                                    + "\n" +
  76.                                    $"**Average FPS:** {avg_fps}"
  77.                                  )
  78.                         .WithThumbnailUrl($"{logo}")
  79.                         .WithColor(Color.Gold);
  80.                     }
  81.                     else
  82.                     {
  83.                         await Context.Channel.SendMessageAsync("User is offline");
  84.                         live = "Offline";
  85.                         embed.WithAuthor(author =>
  86.                         {
  87.                             author.WithName($"{name}'s Channel Info")
  88.                                    .WithUrl($"{url}")
  89.                                     .WithIconUrl($"https://seeklogo.com/images/T/twitch-tv-logo-51C922E0F0-seeklogo.com.png");
  90.                         })
  91.                         .WithDescription($"**Username:** {name}"
  92.                                     + "\n" +
  93.                                     $"**Last Played:** {game}"
  94.                                     + "\n" +
  95.                                     $"**Bio:** {bio}"
  96.                                     + "\n" +
  97.                                     $"**Created At:** {created_at}"
  98.                                     + "\n" +
  99.                                     $"**Last Updated At:** {updated_at}"
  100.                                     + "\n" +
  101.                                     $"**Total Views:** {views}"
  102.                                     + "\n" +
  103.                                     $"**Followers:** {followers}"
  104.                                   )
  105.                         .WithThumbnailUrl($"{logo}")
  106.                         .WithColor(Color.Gold);
  107.                     }
  108.  
  109.  
  110.  
  111.                     await ReplyAsync("", false, embed.Build());
  112.                 }
  113.             }
  114.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement