예제 #1
0
        public Embed createEmbed(bool largeThumbnail = false, bool showChat = false, bool showVod = false, bool showGraph = false)
        {
            Channel streamer = StreamerStatus.Stream.Channel;

            if (showGraph)
            {
                ViewerGraph.SetMaximumLine();
            }

            EmbedBuilder e = new EmbedBuilder();

            e.Color = new Color(0x6441A4);
            e.Title = streamer.Status;
            e.Url   = streamer.Url.ToString();
            e.WithCurrentTimestamp();

            if (VodUrl != null)
            {
                if (showVod)
                {
                    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}]({VodUrl}?t={(int)timestamp.TotalMinutes}m) ({duration.ToString("hh")}h {duration.ToString("mm")}m)";
                    }
                    e.AddField("VOD Segments", String.IsNullOrEmpty(vods) ? "/" : vods);
                }

                if (showChat)
                {
                    var streamDuration = DateTime.UtcNow - OxyPlot.Axes.DateTimeAxis.ToDateTime(ViewerGraph.PlotDataPoints[0].Value.Key);
                    var chat           = GetVodChat(ulong.Parse(VodUrl.Split("/").Last()), (uint)streamDuration.TotalSeconds - 10).Result;

                    if (chat.comments.Count >= 5)
                    {
                        comments = chat.comments.Take(5).ToList();
                    }
                    else
                    {
                        comments = chat.comments.Concat(comments.Take(Math.Min(comments.Count, 5 - chat.comments.Count))).ToList();
                    }

                    string chatPreview = "```asciidoc\n";
                    for (int i = comments.Count - 1; i >= 0; i--)
                    {
                        if (comments[i].message.body.Length > 100)
                        {
                            chatPreview += comments[i].commenter.display_name + ":: " + string.Join("", comments[i].message.body.Take(100)) + " [...]\n";
                        }
                        else
                        {
                            chatPreview += comments[i].commenter.display_name + ":: " + comments[i].message.body + "\n";
                        }
                    }
                    if (chatPreview.Equals("```asciidoc\n"))
                    {
                        chatPreview += "Could not fetch chat messages.\nFollowers/Subs only, or empty?";
                    }
                    chatPreview += "```";

                    e.AddField("Chat Preview", chatPreview);
                }
            }

            EmbedAuthorBuilder author = new EmbedAuthorBuilder();

            author.Name    = Name;
            author.Url     = streamer.Url.ToString();
            author.IconUrl = streamer.Logo.ToString();
            e.Author       = author;

            EmbedFooterBuilder footer = new EmbedFooterBuilder();

            footer.IconUrl = "https://media-elerium.cursecdn.com/attachments/214/576/twitch.png";
            footer.Text    = "Twitch";
            e.Footer       = footer;

            if (largeThumbnail)
            {
                e.ImageUrl = $"{StreamerStatus.Stream.Preview.Medium}?rand={StaticBase.ran.Next(0, 99999999)}";
                if (showGraph)
                {
                    e.ThumbnailUrl = ViewerGraph.DrawPlot();
                }
            }
            else
            {
                e.ThumbnailUrl = $"{StreamerStatus.Stream.Preview.Medium}?rand={StaticBase.ran.Next(0, 99999999)}";
                if (showGraph)
                {
                    e.ImageUrl = ViewerGraph.DrawPlot();
                }
            }
            if (!showGraph)
            {
                e.AddField("Viewers", StreamerStatus.Stream.Viewers, true);
                e.AddField("Game", StreamerStatus.Stream.Game, true);
            }

            return(e.Build());
        }
예제 #2
0
        public Embed createEmbed(bool largeThumbnail = false, bool showChat = false, bool showVod = false)
        {
            Channel streamer = StreamerStatus.stream.channel;

            ViewerGraph.SetMaximumLine();

            EmbedBuilder e = new EmbedBuilder();

            e.Color = new Color(0x6441A4);
            e.Title = streamer.status;
            e.Url   = streamer.url;
            e.WithCurrentTimestamp();

            if (VodUrl != null)
            {
                if (showVod)
                {
                    List <KeyValuePair <string, double> > games = new List <KeyValuePair <string, double> >();
                    for (int i = 0; i < ViewerGraph.PlotDataPoints.Count; i++)
                    {
                        string current = ViewerGraph.PlotDataPoints[i].Key;
                        games.Add(new KeyValuePair <string, double>(current, ViewerGraph.PlotDataPoints[i].Value.Key));

                        while (i < ViewerGraph.PlotDataPoints.Count && ViewerGraph.PlotDataPoints[i].Key.Equals(current))
                        {
                            i++;
                        }
                        i--;
                    }

                    string vods = "";
                    for (int i = Math.Max(0, games.Count - 6); i < games.Count; i++)
                    {
                        TimeSpan duration = i != games.Count - 1 ? OxyPlot.Axes.DateTimeAxis.ToDateTime(games[i + 1].Value) - OxyPlot.Axes.DateTimeAxis.ToDateTime(games[i].Value)
                                                                 : DateTime.UtcNow - OxyPlot.Axes.DateTimeAxis.ToDateTime(games[i].Value);
                        TimeSpan timestamp = OxyPlot.Axes.DateTimeAxis.ToDateTime(games[i].Value) - OxyPlot.Axes.DateTimeAxis.ToDateTime(games[0].Value);
                        vods += $"\n[{games[i].Key}]({VodUrl}?t={(int)timestamp.TotalMinutes}m) ({duration.ToString("hh")}h {duration.ToString("mm")}m)";
                    }
                    e.AddField("VOD Segments", vods);
                }

                if (showChat)
                {
                    var streamDuration = DateTime.UtcNow - OxyPlot.Axes.DateTimeAxis.ToDateTime(ViewerGraph.PlotDataPoints[0].Value.Key);
                    var chat           = GetVodChat(ulong.Parse(VodUrl.Split("/").Last()), (uint)streamDuration.TotalSeconds - 10).Result;

                    if (chat.comments.Count >= 5)
                    {
                        comments = chat.comments.Take(5).ToList();
                    }
                    else
                    {
                        comments = chat.comments.Concat(comments.Take(Math.Min(comments.Count, 5 - chat.comments.Count))).ToList();
                    }

                    string chatPreview = "```asciidoc\n";
                    for (int i = comments.Count - 1; i >= 0; i--)
                    {
                        if (comments[i].message.body.Length > 100)
                        {
                            chatPreview += comments[i].commenter.display_name + ":: " + string.Join("", comments[i].message.body.Take(100)) + " [...]\n";
                        }
                        else
                        {
                            chatPreview += comments[i].commenter.display_name + ":: " + comments[i].message.body + "\n";
                        }
                    }
                    if (chatPreview.Equals("```asciidoc\n"))
                    {
                        chatPreview += "Could not fetch chat messages.\nFollowers/Subs only, or empty?";
                    }
                    chatPreview += "```";

                    e.AddField("Chat Preview", chatPreview);
                }
            }

            EmbedAuthorBuilder author = new EmbedAuthorBuilder();

            author.Name    = Name;
            author.Url     = streamer.url;
            author.IconUrl = streamer.logo;
            e.Author       = author;

            EmbedFooterBuilder footer = new EmbedFooterBuilder();

            footer.IconUrl = "https://media-elerium.cursecdn.com/attachments/214/576/twitch.png";
            footer.Text    = "Twitch";
            e.Footer       = footer;

            e.ThumbnailUrl = largeThumbnail ? ViewerGraph.DrawPlot() : $"{StreamerStatus.stream.preview.medium}?rand={StaticBase.ran.Next(0, 99999999)}";
            e.ImageUrl     = largeThumbnail ? $"{StreamerStatus.stream.preview.large}?rand={StaticBase.ran.Next(0, 99999999)}" : ViewerGraph.DrawPlot();

            //e.AddField("Game", CurGame, true);
            //e.AddField("Viewers", StreamerStatus.stream.viewers, true);

            return(e.Build());
        }