Exemplo n.º 1
0
        private static EmbedBuilder GetTwitchEmbedMessage(TwitchLib.Api.Helix.Models.Streams.Stream stream, TwitchLib.Api.V5.Models.Streams.Stream streamV5, Link link)
        {
            var channelName    = (streamV5?.Channel?.DisplayName ?? streamV5?.Channel?.Name ?? stream?.UserName ?? "Unknown");
            var streamImageUrl = stream.ThumbnailUrl.Replace("{width}", "800").Replace("{height}", "600");
            var game           = streamV5?.Game;

            if (string.IsNullOrEmpty(game))
            {
                game = $"Unknown ({stream?.GameId}";
            }

            var embedBuilder = new EmbedBuilder()
                               //.WithTitle($"[Twitch] {args.Channel}")
                               //.WithDescription(args.Stream.Title)
                               .WithTitle(stream.Title)
                               .WithFields(
                //new EmbedFieldBuilder().WithName("Description").WithValue(args.Stream.Title).WithIsInline(false),
                new EmbedFieldBuilder().WithName("Playing").WithValue(game).WithIsInline(true),
                new EmbedFieldBuilder().WithName("Viewers").WithValue(stream.ViewerCount).WithIsInline(true)
                )
                               .WithFooter(efb => efb.WithText($"started at {stream.StartedAt:dd-MM-yyyy HH:mm:ss}"))
                               .WithUrl($"https://twitch.tv/{channelName}")
                               .WithThumbnailUrl(streamImageUrl)
                               .WithAuthor(new EmbedAuthorBuilder()
                                           .WithIconUrl(streamV5?.Channel?.Logo ?? "")
                                           .WithName($"[Twitch] {channelName}")
                                           .WithUrl($"https://twitch.tv/{channelName}")
                                           )
                               .WithTwitchColour(link.Guild)
            ;


            return(embedBuilder);
        }
        private void UpdateLiveStreamModelsAsync(TwitchLib.Api.Helix.Models.Streams.Stream twitchStream,
                                                 GetGamesResponse game)
        {
            string gameName = game.Games.Length != 0 ? game.Games[0].Name : "Unknown";

            StreamModel streamModel = new StreamModel()
            {
                Stream  = twitchStream.UserName,
                Id      = twitchStream.UserId,
                Avatar  = StreamProfileImages[twitchStream.UserId],
                Title   = twitchStream.Title,
                Game    = gameName,
                Viewers = twitchStream.ViewerCount,
                Link    = $"https://www.twitch.tv/{twitchStream.UserName}"
            };

            if (StreamModels.ContainsKey(twitchStream.UserId))
            {
                StreamModels.Remove(twitchStream.UserId);
            }

            StreamModels.Add(twitchStream.UserId, streamModel);
        }