Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.59 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.                     if(jsun["stream"].ToString() == null)
  44.                     {
  45.                         live = "Offline";
  46.                     } else
  47.                     {
  48.                         live = "Online";
  49.                     }
  50.                     playing_game = jsun["game"].ToString();
  51.                     viewers = jsun["viewers"].ToString();
  52.                     avg_fps = jsun["average_fps"].ToString();
  53.                 }
  54.  
  55.                 var embed = new EmbedBuilder();
  56.                 if(live == "Offline")
  57.                 {
  58.                     embed.WithAuthor(author =>
  59.                     {
  60.                         author.WithName($"{name}'s Channel Info")
  61.                                .WithUrl($"{url}")
  62.                                 .WithIconUrl($"https://seeklogo.com/images/T/twitch-tv-logo-51C922E0F0-seeklogo.com.png");
  63.                     })
  64.                     .WithDescription($"**Username:** {name}"
  65.                                     + "\n" +
  66.                                     $"**Last Played:** {game}"
  67.                                     + "\n" +
  68.                                     $"**Bio:** {bio}"
  69.                                     + "\n" +
  70.                                     $"**Created At:** {created_at}"
  71.                                     + "\n" +
  72.                                     $"**Last Updated At:** {updated_at}"
  73.                                     + "\n" +
  74.                                     $"**Total Views:** {views}"
  75.                                     + "\n" +
  76.                                     $"**Followers:** {followers}"
  77.                                   )
  78.                     .WithThumbnailUrl($"{logo}")
  79.                     .WithColor(Color.Gold);
  80.                 } else
  81.                 {
  82.                     embed.WithAuthor(author =>
  83.                     {
  84.                         author.WithName($"{name}'s Channel Info")
  85.                                .WithUrl($"{url}")
  86.                                 .WithIconUrl($"https://seeklogo.com/images/T/twitch-tv-logo-51C922E0F0-seeklogo.com.png");
  87.                     })
  88.                     .WithDescription($"**Username:** {name}"
  89.                                     + "\n" +
  90.                                     $"**Bio:** {bio}"
  91.                                     + "\n" +
  92.                                     $"**Created At:** {created_at}"
  93.                                     + "\n" +
  94.                                     $"**Last Updated At:** {updated_at}"
  95.                                     + "\n" +
  96.                                     $"**Total Views:** {views}"
  97.                                     + "\n" +
  98.                                     $"**Followers:** {followers}"
  99.                                     + "\n \n" +
  100.                                     $"**Status:** {live}"
  101.                                     + "\n" +
  102.                                     $"**Playing Game:** {playing_game}"
  103.                                     + "\n" +
  104.                                     $"**Viewers**: {viewers}"
  105.                                     + "\n" +
  106.                                     $"**Average FPS:** {avg_fps}"
  107.                                   )
  108.                     .WithThumbnailUrl($"{logo}")
  109.                     .WithColor(Color.Gold);
  110.                 }
  111.                
  112.                 await ReplyAsync("", false, embed.Build());
  113.             }
  114.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement