public async Task test(params string[] args) { List <TwitchHandler.TwitchData> userInfo = await TwitchHandler.GetTwitchInfo(args[1]); Color TwitchColour = new Color(100, 65, 165); EmbedBuilder eb = new EmbedBuilder(); eb.Title = userInfo[0].display_name; eb.Color = TwitchColour; eb.WithCurrentTimestamp(); switch (args[0].ToLower()) { case "channel": eb.Description = userInfo[0].description; eb.Footer = new EmbedFooterBuilder() { IconUrl = userInfo[0].profile_image_url, Text = $"created at: {userInfo[0].created_at}" }; eb.AddField("Twitch account information", $"Link to profile: https://www.twitch.tv/{args[1]} \nView count: {userInfo[0].view_count}\nUser id: {userInfo[0].id}"); break; case "av": case "avatar": case "pfp": eb.Description = $"Here's the profile picture for {userInfo[0].display_name}:"; eb.ImageUrl = userInfo[0].profile_image_url; break; case "livetest": List <TwitchHandler.UserStreams> userStreams = await TwitchHandler.GetStreams(args[1]); if (userStreams.Count == 0) { await Context.Message.ReplyAsync("", false, Global.EmbedMessage("Error", $"The user {args[1]} is not currently live on Twitch.", false, Color.Red).Build()); return; } eb.Title = $"{args[1]} is live on Twitch!"; eb.ImageUrl = $"https://static-cdn.jtvnw.net/previews-ttv/live_user_{args[1]}.jpg"; eb.Description = $"[Watch {args[1]} live on Twitch!](https://twitch.tv/{args[1]})"; eb.AddField("Stream information", $"title: {userStreams[0].title}\ngame name: {userStreams[0].game_name}\nviewer count: {userStreams[0].viewer_count}"); eb.Footer = new EmbedFooterBuilder() { IconUrl = userInfo[0].profile_image_url, Text = $"Live started at: {userStreams[0].started_at}" }; break; } await ReplyAsync("", false, eb.Build()); }
public async void CheckLiveUsers() { MongoClient mongoClient = new MongoClient(Global.Mongoconnstr); IMongoDatabase database = mongoClient.GetDatabase("finlay"); IMongoCollection <BsonDocument> collection = database.GetCollection <BsonDocument>("guilds"); ulong _id = 0; EmbedBuilder eb = new EmbedBuilder(); List <TwitchHandler.TwitchData> userInfo; Color TwitchColour = new Color(100, 65, 165); eb.Color = TwitchColour; string itemVal = ""; BsonDocument item = null; List <string> stringArray = new List <string>(); List <TwitchHandler.UserStreams> userStreams = new List <TwitchHandler.UserStreams>(); string modlogchannel = ""; SocketTextChannel logchannel; Dictionary <string, ulong> AlreadySent = new Dictionary <string, ulong>(); while (true) { foreach (SocketGuild guild in _client.Guilds) { _id = guild.Id; item = await collection.Find(Builders <BsonDocument> .Filter.Eq("_id", _id)).FirstOrDefaultAsync(); try { itemVal = item?.GetValue("TwitchUsers").ToJson(); } catch { continue; } if (itemVal != null) { stringArray = JsonConvert.DeserializeObject <string[]>(itemVal).ToList(); foreach (string user in stringArray) { userStreams = await TwitchHandler.GetStreams(user); if (userStreams.Count == 0) { if (AlreadySent.ContainsKey(user)) { List <string> IdenticalKeys = AlreadySent.Where(x => x.Key == user).Select(x => x.Key).ToList(); foreach (string key in IdenticalKeys) { AlreadySent.Remove(key); } } } if (AlreadySent.ContainsKey(user)) { continue; } modlogchannel = await TwitchHandler.GetTwitchChannel(guild); if (modlogchannel == "0") { continue; } logchannel = guild.GetTextChannel(Convert.ToUInt64(modlogchannel)); userInfo = await TwitchHandler.GetTwitchInfo(user); eb.Title = $"{user} is live on Twitch!"; eb.ImageUrl = $"https://static-cdn.jtvnw.net/previews-ttv/live_user_{user}.jpg"; eb.Description = $"[Watch {user} live on Twitch!](https://twitch.tv/{user})"; eb.AddField("Stream information", $"title: {userStreams[0].title}\ngame name: {userStreams[0].game_name}"); eb.Footer = new EmbedFooterBuilder() { IconUrl = userInfo[0].profile_image_url, Text = $"Live started at: {userStreams[0].started_at}" }; AlreadySent.Add(user, guild.Id); //AlreadySent.Append(user); await logchannel.SendMessageAsync("", false, eb.Build()); } } } } }