public Embed createEmbed(MixerResult StreamerStatus, bool largeThumbnail = false, bool showTimestamps = false, bool showGraph = false) { if (showGraph) { ViewerGraph.SetMaximumLine(); } EmbedBuilder e = new EmbedBuilder(); e.Color = new Color(0, 163, 243); e.Title = StreamerStatus.name; e.Url = TrackerUrl(); e.WithCurrentTimestamp(); if (showTimestamps) { string vods = ""; for (int i = Math.Max(0, GameChanges.Count - 6); i < GameChanges.Count; i++) { TimeSpan duration = i != GameChanges.Count - 1 ? GameChanges[i + 1].Item2 - GameChanges[i].Item2 : DateTime.UtcNow - GameChanges[i].Item2; TimeSpan timestamp = GameChanges[i].Item2 - GameChanges[0].Item2; vods += $"\n{GameChanges[i].Item1} ({duration.ToString("hh")}h {duration.ToString("mm")}m)"; } e.AddField("VOD Segments", String.IsNullOrEmpty(vods) ? "/" : vods); } EmbedAuthorBuilder author = new EmbedAuthorBuilder(); author.Name = Name; author.Url = TrackerUrl(); author.IconUrl = StreamerStatus.user.avatarUrl; e.Author = author; EmbedFooterBuilder footer = new EmbedFooterBuilder(); footer.IconUrl = "https://img.pngio.com/mixer-logo-png-images-png-cliparts-free-download-on-seekpng-mixer-logo-png-300_265.png"; footer.Text = "Mixer"; e.Footer = footer; if (largeThumbnail) { e.ImageUrl = $"https://thumbs.mixer.com/channel/{MixerId}.small.jpg?rand={StaticBase.ran.Next(0, 99999999)}"; if (showGraph) { e.ThumbnailUrl = ViewerGraph.DrawPlot(); } } else { e.ThumbnailUrl = $"https://thumbs.mixer.com/channel/{MixerId}.small.jpg?rand={StaticBase.ran.Next(0, 99999999)}"; if (showGraph) { e.ImageUrl = ViewerGraph.DrawPlot(); } } if (!showGraph) { e.AddField("Viewers", StreamerStatus.viewersCurrent, true); e.AddField("Game", StreamerStatus.type?.name ?? "Nothing", true); } return(e.Build()); }
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)); } }