public async Task CheckTwitchStreams() { var allGroups = await _groupManager.GetAllGuildGroupsWithGroupChannels(); // TODO Refactor this logic var allChannels = GetCreatorChannelsIdsFromGuildGroupList(allGroups); var streamResponse = await _twitchManager.GetTwitchStreamsByUserIdsDelimitedList(allChannels.ToList()); if (streamResponse == null || streamResponse.Streams.Count == 0) { return; // No one live. Move along :) } var streamsToAnnounce = new List <StreamToAnnounce>(); foreach (var stream in streamResponse.Streams) { foreach (var group in GetGroupsToAnnounce(allGroups, stream.UserId)) { var streamToAnnounce = new StreamToAnnounce { GuildGroups = group, Platform = Platform.Twitch, CreatorChannelId = stream.Id, GameId = stream.GameId, TagIds = stream.Tags }; streamsToAnnounce.Add(streamToAnnounce); } } var gameIds = streamsToAnnounce.Select(x => x.GameId).Distinct(); var gameList = await _twitchManager.GetTwitchGamesByIdsDelimitedList(gameIds.ToList()); foreach (var game in gameList.Games) { streamsToAnnounce.FirstOrDefault(sta => sta.GameId.Equals(game.Id)).Game = game.Name; } var message = _messagingService.BuildMessage() //var guildId = Cryptography.Decrypt(group.GuildId); //var channelId = Cryptography.Decrypt(group.StreamChannelId); //var channel = _guildInteractionService.GetChannelById(ulong.Parse(channelId)); // TODO Get Users for the Avatar, Username, Followers, TotalViews // TODO Get Game endpoint //var message = await _messagingService.BuildMessage(group.LiveMessage, Platform.Twitch, guildId, channelId, // null, stream.Id, stream.Username, stream.GameId, stream.Title, // $"https://twitch.tv/{stream.Username}", 0, 0, stream.ThumbnailUrl); //await channel.SendMessageAsync($" ", false, message.Embed); }
public async Task <BroadcastMessage> BuildMessage(StreamToAnnounce streamToAnnounce, string baseMessage, string avatarUrl) { var embed = new EmbedBuilder(); var author = new EmbedAuthorBuilder(); var footer = new EmbedFooterBuilder(); switch (streamToAnnounce.Platform) { case Platform.Mixer: embed.Color = Constants.Blue; embed.ThumbnailUrl = avatarUrl != null ? avatarUrl + "?_=" + Guid.NewGuid().ToString().Replace("-", "") : "https://mixer.com/_latest/assets/images/main/avatars/default.jpg"; footer.IconUrl = "http://couchbot.io/img/mixer2.png"; break; case Platform.Twitch: embed.Color = Constants.Purple; embed.ThumbnailUrl = avatarUrl != null ? avatarUrl + "?_=" + Guid.NewGuid().ToString().Replace("-", "") : "https://static-cdn.jtvnw.net/jtv_user_pictures/xarth/404_user_70x70.png"; footer.IconUrl = "http://couchbot.io/img/twitch.jpg"; break; case Platform.YouTube: embed.Color = Constants.Red; embed.ThumbnailUrl = avatarUrl + "?_=" + Guid.NewGuid().ToString().Replace("-", ""); footer.IconUrl = "http://couchbot.io/img/ytg.jpg"; break; } embed.Description = baseMessage .Replace("%CHANNEL%", Format.Sanitize(streamToAnnounce.CreatorChannelName)) .Replace("%GAME%", streamToAnnounce.Game) .Replace("%TITLE%", streamToAnnounce.Title) .Replace("%URL%", streamToAnnounce.CreatorChannelUrl); if (!string.IsNullOrEmpty(streamToAnnounce.Game)) { embed.Fields.Add(new EmbedFieldBuilder() { IsInline = true, Name = "Game", Value = streamToAnnounce.Game }); } embed.Fields.Add(new EmbedFieldBuilder() { IsInline = true, Name = "Followers", Value = followers }); embed.Fields.Add(new EmbedFieldBuilder() { IsInline = true, Name = "Total Views", Value = totalViews }); embed.ImageUrl = thumbnailUrl.Replace("{height}", "648").Replace("{width}", "1152"); return(new BroadcastMessage { Platform = platform, ChannelId = channelId, DeleteOffline = true, Embed = embed.Build(), GuildId = guildId, Message = baseMessage, CreatorChannelID = creatorChannelId }); }