public async override void CheckForChange_Elapsed(object stateinfo) { try { var match = await fetchData(); if (!string.IsNullOrEmpty(match) || ChannelConfig.Any(x => (bool)x.Value[TRACKEMPTYSTRINGS])) { bool isNumeric; if (oldMatch == null) { oldMatch = match; await UpdateTracker(); } if ((isNumeric = Double.TryParse(oldMatch, out double value)) && DataGraph == null) { DataGraph = new DatePlot("HTML" + Name.GetHashCode(), "Date", "Value", "dd-MMM", false); DataGraph.AddValue("Value", value); } if (!match.Equals(oldMatch)) { if (isNumeric) { DataGraph.AddValue("Value", value); var success = Double.TryParse(match, out value); if (success) { DataGraph.AddValue("Value", value); } } foreach (var channel in ChannelConfig.Keys.ToList()) { await OnMajorChangeTracked(channel, CreateChangeEmbed($"{oldMatch} -> {match}", isNumeric), (string)ChannelConfig[channel]["Notification"]); } oldMatch = match; await UpdateTracker(); } } } catch (Exception e) { await Program.MopsLog(new LogMessage(LogSeverity.Error, "", $" error by {Name}", e)); } }
public async Task CheckStreamerInfoAsync() { try { StreamerStatus = await streamerInformation(); bool isStreaming = StreamerStatus.Stream.Channel != null && (StreamerStatus.Stream.BroadcastPlatform.Contains("other") ? ChannelConfig.Any(x => (bool)x.Value[TRACKRERUN]) : true); bool isRerun = StreamerStatus.Stream?.BroadcastPlatform?.Contains("other") ?? false; if (!timerChanged && !IsOnline && (WebhookExpire - DateTime.Now).TotalMinutes >= 60) { //SetTimer(3600000, StaticBase.ran.Next(5000, 3600000)); timerChanged = true; } if (IsOnline != isStreaming) { if (IsOnline) { if (++TimeoutCount >= 3) { TimeoutCount = 0; IsOnline = false; try { var pdf = ViewerGraph.DrawPlot(true, $"{Name}-{DateTime.UtcNow.ToString("MM-dd-yy_hh-mm")}"); foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][SENDPDF]).ToList()) { await(Program.Client.GetChannel(channel) as SocketTextChannel)?.SendFileAsync(pdf, "Graph PDF for personal use:"); } File.Delete(pdf); } catch (Exception e) { await Program.MopsLog(new LogMessage(LogSeverity.Error, "", $" error sending graph by {Name}", e)); } ViewerGraph?.Dispose(); ViewerGraph = null; VodUrl = null; foreach (var channelMessage in ToUpdate) { await Program.ReactionHandler.ClearHandler((IUserMessage)await ((ITextChannel)Program.Client.GetChannel(channelMessage.Key)).GetMessageAsync(channelMessage.Value)); } ToUpdate = new Dictionary <ulong, ulong>(); GameChanges = new List <Tuple <string, DateTime> >(); if (OnOffline != null) { await OnOffline.Invoke(this); } foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][OFFLINE] && (isRerun ? (bool)ChannelConfig[x][TRACKRERUN] : true)).ToList()) { await OnMinorChangeTracked(channel, $"{Name} went Offline!"); } //SetTimer(3600000, 3600000); } else if (!IsHosting) { var host = (await hostInformation()).hosts.First(); if (host.IsHosting()) { if (OnHosting != null) { await OnHosting.Invoke(host.host_display_name, host.target_display_name, (int)ViewerGraph.PlotDataPoints.LastOrDefault().Value.Value); } foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][HOST] && (isRerun ? (bool)ChannelConfig[x][TRACKRERUN] : true)).ToList()) { await OnMinorChangeTracked(channel, $"{Name} is now hosting {host.target_display_name} for {(int)ViewerGraph.PlotDataPoints.LastOrDefault().Value.Value} viewers!"); } IsHosting = true; } } } else { ViewerGraph = new DatePlot(Name, "Time since start", "Viewers"); IsOnline = true; IsHosting = false; CurGame = StreamerStatus.Stream.Game; ViewerGraph.AddValue(CurGame, 0, StreamerStatus.Stream.CreatedAt.UtcDateTime); GameChanges.Add(Tuple.Create(StreamerStatus.Stream.Game, StreamerStatus.Stream.CreatedAt.UtcDateTime)); if (OnLive != null) { await OnLive.Invoke(this); } foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][ONLINE] && (isRerun ? (bool)ChannelConfig[x][TRACKRERUN] : true)).ToList()) { await OnMinorChangeTracked(channel, (string)ChannelConfig[channel]["Notification"]); } //SetTimer(120000, 120000); } await UpdateTracker(); } else { TimeoutCount = 0; } if (isStreaming) { if (VodUrl == null) { VodUrl = await GetVodAsync(); } if (CurGame.ToLower().CompareTo(StreamerStatus.Stream.Game.ToLower()) != 0) { CurGame = StreamerStatus.Stream.Game; GameChanges.Add(Tuple.Create(StreamerStatus.Stream.Game, DateTime.UtcNow)); await UpdateTracker(); foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][GAMECHANGE] && (isRerun ? (bool)ChannelConfig[x][TRACKRERUN] : true)).ToList()) { await OnMinorChangeTracked(channel, $"{Name} switched games to **{CurGame}**"); } } if (ChannelConfig.Any(x => (bool)x.Value[SHOWGRAPH])) { await ModifyAsync(x => x.ViewerGraph.AddValue(CurGame, StreamerStatus.Stream.Viewers)); } foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][SHOWEMBED] && (isRerun ? (bool)ChannelConfig[x][TRACKRERUN] : true)).ToList()) { await OnMajorChangeTracked(channel, createEmbed((bool)ChannelConfig[channel][THUMBNAIL], (bool)ChannelConfig[channel][SHOWCHAT], (bool)ChannelConfig[channel][SHOWVOD], (bool)ChannelConfig[channel][SHOWGRAPH])); } } } catch (Exception e) { await Program.MopsLog(new LogMessage(LogSeverity.Error, "", $" error by {Name}", e)); } }
protected async override void CheckForChange_Elapsed(object stateinfo) { try { if (ChannelConfig.Any(x => (bool)x.Value[TRACKLEVEL])) { if (PastInformation.character == null) { PastInformation.character = await GetCharacterEndpoint(CharacterName, APIKey); LevelGraph = new DatePlot($"{CharacterName.Replace(" ", "")}Level", "Date", "Level", "dd-MMM", false, true); LevelGraph.AddValueSeperate("Level", PastInformation.character.level, relative: false); LevelGraph.AddValueSeperate("M-Level", PastInformation.character.masteryLevel, relative: false); await UpdateTracker(); } else { Character pastInfo = PastInformation.character; Character currentInfo = await GetCharacterEndpoint(CharacterName, APIKey); if (currentInfo.level != pastInfo.level || currentInfo.masteryLevel != pastInfo.masteryLevel) { LevelGraph.AddValueSeperate("Level", pastInfo.level, relative: false); LevelGraph.AddValueSeperate("M-Level", pastInfo.masteryLevel, relative: false); LevelGraph.AddValueSeperate("Level", currentInfo.level, relative: false); LevelGraph.AddValueSeperate("M-Level", currentInfo.masteryLevel, relative: false); foreach (var channel in ChannelConfig.Where(x => (bool)x.Value[TRACKLEVEL])) { await OnMajorChangeTracked(channel.Key, createLevelEmbed(pastInfo, currentInfo)); } PastInformation.character = currentInfo; await UpdateTracker(); } } } if (ChannelConfig.Any(x => (bool)x.Value[TRACKACHIEVEMENTS])) { //ToDo } if (ChannelConfig.Any(x => (bool)x.Value[TRACKWEALTH])) { if (PastInformation.wallet == null) { PastInformation.wallet = (await GetWealth(APIKey)).FirstOrDefault(); MoneyGraph = new DatePlot($"{CharacterName.Replace(" ", "")}Gold", "Date", "Gold", "dd-MMM", false); MoneyGraph.AddValue("Gold", PastInformation.wallet.value, relative: false); await UpdateTracker(); } else { Wallet pastInfo = PastInformation.wallet; Wallet currentInfo = (await GetWealth(APIKey)).FirstOrDefault(); if (currentInfo.value != pastInfo.value) { MoneyGraph.AddValue("Gold", pastInfo.value, relative: false); MoneyGraph.AddValue("Gold", currentInfo.value, relative: false); foreach (var channel in ChannelConfig.Where(x => (bool)x.Value[TRACKWEALTH])) { await OnMajorChangeTracked(channel.Key, createWealthEmbed(pastInfo, currentInfo)); } PastInformation.wallet = currentInfo; await UpdateTracker(); } } } if (ChannelConfig.Any(x => (bool)x.Value[TRACKTPBUYS])) { if (PastInformation.buy == null) { PastInformation.buy = (await GetTPBuys(APIKey)).FirstOrDefault(); await UpdateTracker(); } else { TPTransaction pastInfo = PastInformation.buy; List <TPTransaction> currentInfo = (await GetTPBuys(APIKey)).TakeWhile(x => x.purchased > pastInfo.purchased).ToList(); currentInfo.Reverse(); foreach (var transaction in currentInfo) { foreach (var channel in ChannelConfig.Where(x => (bool)x.Value[TRACKTPBUYS])) { await OnMajorChangeTracked(channel.Key, await CreateTPBuyEmbed(transaction)); } } if (currentInfo.Count > 0) { PastInformation.buy = currentInfo.LastOrDefault(); await UpdateTracker(); } } } if (ChannelConfig.Any(x => (bool)x.Value[TRACKTPSELLS])) { if (PastInformation.sell == null) { PastInformation.sell = (await GetTPSells(APIKey)).FirstOrDefault(); await UpdateTracker(); } else { TPTransaction pastInfo = PastInformation.sell; List <TPTransaction> currentInfo = (await GetTPSells(APIKey)).TakeWhile(x => x.purchased > pastInfo.purchased).ToList(); currentInfo.Reverse(); foreach (var transaction in currentInfo) { foreach (var channel in ChannelConfig.Where(x => (bool)x.Value[TRACKTPSELLS])) { await OnMajorChangeTracked(channel.Key, await CreateTPSellEmbed(transaction)); } } if (currentInfo.Count > 0) { PastInformation.sell = currentInfo.LastOrDefault(); await UpdateTracker(); } } } if (ChannelConfig.Any(x => (bool)x.Value[TRACKTPDELIVERY])) { if (PastInformation.delivery == null) { PastInformation.delivery = await GetTPInbox(APIKey); await UpdateTracker(); } else { TPInbox pastInfo = PastInformation.delivery; TPInbox currentInfo = await GetTPInbox(APIKey); if (currentInfo.items.Count != pastInfo.items.Count || currentInfo.coins != pastInfo.coins) { foreach (var channel in ChannelConfig.Where(x => (bool)x.Value[TRACKTPDELIVERY])) { await OnMajorChangeTracked(channel.Key, CreateTPInboxEmbed(pastInfo, currentInfo)); } PastInformation.delivery = currentInfo; await UpdateTracker(); } } } if (ChannelConfig.Any(x => (bool)x.Value[TRACKEQUIPMENT])) { } } catch (Exception e) { await Program.MopsLog(new LogMessage(LogSeverity.Error, "", $" error by {Name}", e)); } }
public async Task CheckStreamerInfoAsync() { try { StreamerStatus = await streamerInformation(); bool isStreaming = StreamerStatus.online; if (IsOnline != isStreaming) { if (IsOnline) { if (++TimeoutCount >= 3) { TimeoutCount = 0; IsOnline = false; ViewerGraph?.Dispose(); ViewerGraph = null; ToUpdate = new Dictionary <ulong, ulong>(); GameChanges = new List <Tuple <string, DateTime> >(); if (OnOffline != null) { await OnOffline.Invoke(this); } foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][OFFLINE]).ToList()) { await OnMinorChangeTracked(channel, $"{Name} went Offline!"); } //SetTimer(600000, 600000); } } else { ViewerGraph = new DatePlot(Name + "Mixer", "Time since start", "Viewers"); IsOnline = true; CurGame = StreamerStatus.type?.name ?? "Nothing"; GameChanges.Add(Tuple.Create(CurGame, DateTime.UtcNow)); ViewerGraph.AddValue(CurGame, 0, (await GetBroadcastStartTime()).AddHours(-2)); if (OnLive != null) { await OnLive.Invoke(this); } foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][ONLINE]).ToList()) { await OnMinorChangeTracked(channel, (string)ChannelConfig[channel]["Notification"]); } //SetTimer(60000, 60000); } await UpdateTracker(); } else { TimeoutCount = 0; } if (isStreaming) { if (CurGame.CompareTo(StreamerStatus.type?.name ?? "Nothing") != 0) { CurGame = StreamerStatus.type?.name ?? "Nothing"; GameChanges.Add(Tuple.Create(CurGame, DateTime.UtcNow)); await UpdateTracker(); foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][GAMECHANGE]).ToList()) { await OnMinorChangeTracked(channel, $"{Name} switched games to **{CurGame}**"); } } if (ChannelConfig.Any(x => (bool)x.Value[SHOWGRAPH])) { await ModifyAsync(x => x.ViewerGraph.AddValue(CurGame, StreamerStatus.viewersCurrent)); } foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][SHOWEMBED]).ToList()) { await OnMajorChangeTracked(channel, createEmbed(StreamerStatus, (bool)ChannelConfig[channel][THUMBNAIL], (bool)ChannelConfig[channel][SHOWTIMESTAMPS], (bool)ChannelConfig[channel][SHOWGRAPH])); } } } catch (Exception e) { await Program.MopsLog(new LogMessage(LogSeverity.Error, "", $" error by {Name}", e)); } }
public async override void CheckForChange_Elapsed(object stateinfo) { try { var newInformation = await getResults(); if (PastInformation == null) { PastInformation = newInformation; } var embed = createEmbed(newInformation, PastInformation, out bool changed); if (changed) { var graphMembers = newInformation.Where(x => x.Key.Contains("graph:")); foreach (var graphValue in graphMembers) { if (DataGraph == null) { foreach (var graphTest in graphMembers) { if (!graphTest.Equals(default(KeyValuePair <string, string>))) { bool succeeded = double.TryParse(graphTest.Value, out double test); var format = graphTest.Key.Split("->").First().Split(":").First(); if (format.Contains("graph")) { format = "dd-MMM|false"; } var relative = Boolean.Parse(format.Split("|").Last()); if (succeeded) { var chosenName = graphTest.Key.Contains("as:") ? graphTest.Key.Split(":").Last() : graphTest.Key; if (DataGraph == null) { DataGraph = new DatePlot("JSON" + Name.GetHashCode(), "Date", "Value", format: format.Split("|").First(), relativeTime: relative, multipleLines: true); } } else { throw new Exception("Graph value is not a number!"); } } } } var name = graphValue.Key.Contains("as:") ? graphValue.Key.Split(":").Last() : graphValue.Key; if (!graphValue.Equals(default(KeyValuePair <string, string>))) { DataGraph.AddValueSeperate(name, double.Parse(PastInformation[graphValue.Key])); DataGraph.AddValueSeperate(name, double.Parse(graphValue.Value)); } } foreach (var channel in ChannelConfig.Keys.ToList()) { await OnMajorChangeTracked(channel, DataGraph == null?embed : createEmbed(newInformation, PastInformation, out changed), (string)ChannelConfig[channel]["Notification"]); } if (!ChannelConfig.Any(x => (bool)x.Value[UPDATEUNTILNULL])) { ToUpdate = new Dictionary <ulong, ulong>(); } PastInformation = newInformation; await UpdateTracker(); } } catch (Exception e) { if (ChannelConfig.Any(x => (bool)x.Value[UPDATEUNTILNULL]) && e.Message.Contains("access child value")) { ToUpdate = new Dictionary <ulong, ulong>(); DataGraph = null; await UpdateTracker(); } await Program.MopsLog(new LogMessage(LogSeverity.Error, "", $" error by {Name}", e)); } }
public async override void CheckForChange_Elapsed(object stateinfo) { try { if (VideoId == null) { VideoId = await scrapeLivestreamId(Name); //Not live if (VideoId == null) { return; } //New livestream else { while (StreamInfo == null) { await Task.Delay(60000); } ViewerGraph = new DatePlot(Name, "Time since start", "Viewers"); ViewerGraph.AddValue("Viewers", 0, StreamInfo.liveStreamingDetails.actualStartTime); foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][ONLINE]).ToList()) { await OnMinorChangeTracked(channel, (string)ChannelConfig[channel]["Notification"]); } //SetTimer(120000, 120000); IconUrl = (await fetchChannel()).snippet.thumbnails.medium.url; await UpdateTracker(); } } if (StreamInfo == null) { await Task.Delay(120000); } bool isStreaming = StreamInfo?.snippet?.liveBroadcastContent?.Equals("live") ?? false; if (!isStreaming) { await Program.MopsLog(new LogMessage(LogSeverity.Verbose, "", $"Stream went offline for {Name}, investigate please:\n{(StreamInfo != null ? JsonConvert.SerializeObject(StreamInfo) : "Was null")}")); VideoId = null; //SetTimer(900000); try{ if (ChannelConfig.Any(x => (bool)x.Value[SENDGRAPH])) { var png = ViewerGraph.DrawPlot(false, $"{Name}-{DateTime.UtcNow.ToString("MM-dd-yy_hh-mm")}", true); foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][SENDGRAPH]).ToList()) { await(Program.Client.GetChannel(channel) as SocketTextChannel)?.SendFileAsync(png, "Graph for personal use:"); } File.Delete(png); } } catch (Exception e) { await Program.MopsLog(new LogMessage(LogSeverity.Error, "", $" error sending graph by {Name}", e)); } ViewerGraph?.Dispose(); ViewerGraph = null; ToUpdate = new Dictionary <ulong, ulong>(); foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][OFFLINE]).ToList()) { await OnMinorChangeTracked(channel, $"{StreamInfo?.snippet?.channelTitle ?? "Streamer"} went Offline!"); } StreamInfo = null; await UpdateTracker(); } else { if (ChannelConfig.Any(x => (bool)x.Value[SHOWGRAPH])) { if (StreamInfo.liveStreamingDetails?.concurrentViewers != null) { ViewerGraph.AddValue("Viewers", double.Parse(StreamInfo.liveStreamingDetails.concurrentViewers)); } else { ViewerGraph.AddValue("Viewers", 0); } await UpdateTracker(); } foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][SHOWEMBED]).ToList()) { await OnMajorChangeTracked(channel, await createEmbed((bool)ChannelConfig[channel][THUMBNAIL], (bool)ChannelConfig[channel][SHOWCHAT], (bool)ChannelConfig[channel][SHOWGRAPH])); } } } catch (Exception e) { await Program.MopsLog(new LogMessage(LogSeverity.Error, "", $" error by {Name}", e)); } }