Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Command("twitchuser")]
- public async Task twitchAsync(string username = "")
- {
- if(username == "")
- {
- await Context.Channel.SendMessageAsync("You need to give me an Channel Name to search for.");
- }
- using (var client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }))
- {
- string websiteurl = $"https://api.twitch.tv/kraken/channels/{username}?client_id=g8vz0dctlo417o6dz3gvol1ssws1ih";
- client.BaseAddress = new Uri(websiteurl);
- HttpResponseMessage response = client.GetAsync("").Result;
- response.EnsureSuccessStatusCode();
- string result = await response.Content.ReadAsStringAsync();
- var json = JObject.Parse(result);
- string name = json["display_name"].ToString();
- string bio = json["status"].ToString();
- string created_at = json["created_at"].ToString();
- string logo = json["logo"].ToString();
- string updated_at = json["updated_at"].ToString();
- string views = json["views"].ToString();
- string followers = json["followers"].ToString();
- string game = json["game"].ToString();
- string url = json["url"].ToString();
- string live = "";
- string playing_game = "";
- string viewers = "";
- string avg_fps = "";
- using (var clientel = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }))
- {
- string weburl = $"https://api.twitch.tv/kraken/streams/{username}?client_id=g8vz0dctlo417o6dz3gvol1ssws1ih";
- clientel.BaseAddress = new Uri(weburl);
- HttpResponseMessage responds = clientel.GetAsync("").Result;
- responds.EnsureSuccessStatusCode();
- string results = await responds.Content.ReadAsStringAsync();
- var jsun = JObject.Parse(results);
- var embed = new EmbedBuilder();
- if (jsun["stream"] != null)
- {
- live = "Online";
- playing_game = jsun["stream"]["game"].ToString();
- viewers = jsun["stream"]["viewers"].ToString();
- avg_fps = jsun["stream"]["average_fps"].ToString();
- embed.WithAuthor(author =>
- {
- author.WithName($"{name}'s Channel Info")
- .WithUrl($"{url}")
- .WithIconUrl($"https://seeklogo.com/images/T/twitch-tv-logo-51C922E0F0-seeklogo.com.png");
- })
- .WithDescription($"**Username:** {name}"
- + "\n" +
- $"**Bio:** {bio}"
- + "\n" +
- $"**Created At:** {created_at}"
- + "\n" +
- $"**Last Updated At:** {updated_at}"
- + "\n" +
- $"**Total Views:** {views}"
- + "\n" +
- $"**Followers:** {followers}"
- + "\n \n" +
- $"**Status:** {live}"
- + "\n" +
- $"**Playing Game:** {playing_game}"
- + "\n" +
- $"**Viewers**: {viewers}"
- + "\n" +
- $"**Average FPS:** {avg_fps}"
- )
- .WithThumbnailUrl($"{logo}")
- .WithColor(Color.Gold);
- }
- else
- {
- await Context.Channel.SendMessageAsync("User is offline");
- live = "Offline";
- embed.WithAuthor(author =>
- {
- author.WithName($"{name}'s Channel Info")
- .WithUrl($"{url}")
- .WithIconUrl($"https://seeklogo.com/images/T/twitch-tv-logo-51C922E0F0-seeklogo.com.png");
- })
- .WithDescription($"**Username:** {name}"
- + "\n" +
- $"**Last Played:** {game}"
- + "\n" +
- $"**Bio:** {bio}"
- + "\n" +
- $"**Created At:** {created_at}"
- + "\n" +
- $"**Last Updated At:** {updated_at}"
- + "\n" +
- $"**Total Views:** {views}"
- + "\n" +
- $"**Followers:** {followers}"
- )
- .WithThumbnailUrl($"{logo}")
- .WithColor(Color.Gold);
- }
- await ReplyAsync("", false, embed.Build());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement