Пример #1
0
        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);
        }
Пример #2
0
        public async Task AnnounceLiveChannel(string beamId)
        {
            var servers = _fileService.GetConfiguredServers();

            var beamServers       = new List <DiscordServer>();
            var ownerBeamServers  = new List <DiscordServer>();
            var userSharedServers = new List <DiscordServer>();

            foreach (var server in servers)
            {
                if (server.ServerBeamChannels != null && server.ServerBeamChannelIds != null)
                {
                    if (server.ServerBeamChannels.Count > 0 && server.ServerBeamChannelIds.Count > 0)
                    {
                        if (server.ServerBeamChannelIds.Contains(beamId))
                        {
                            if (server.GoLiveChannel != 0)
                            {
                                beamServers.Add(server);
                            }
                        }
                    }
                }

                if (!string.IsNullOrEmpty(server.OwnerBeamChannelId) && server.OwnerBeamChannelId.Equals(beamId))
                {
                    if (server.OwnerLiveChannel != 0)
                    {
                        ownerBeamServers.Add(server);
                    }
                }
            }

            List <BroadcastMessage> messages = new List <BroadcastMessage>();

            foreach (var server in beamServers)
            {
                // Check to see if we have a message already queued up. If so, jump to the next server.

                if (server.GoLiveChannel != 0 && server.Id != 0)
                {
                    if (messages.FirstOrDefault(x => x.GuildId == server.Id && x.UserId == beamId) == null)
                    {
                        var stream = await _mixerManager.GetChannelByName(beamId);

                        string gameName     = stream.type == null ? "a game" : stream.type.name;
                        string url          = "http://mixer.com/" + stream.token;
                        string avatarUrl    = stream.user.avatarUrl != null ? stream.user.avatarUrl : "https://mixer.com/_latest/assets/images/main/avatars/default.jpg";
                        string thumbnailUrl = "https://thumbs.mixer.com/channel/" + stream.id + ".small.jpg";
                        string channelId    = stream.id.Value.ToString();

                        messages.Add(await _messagingService.BuildMessage(stream.token, gameName, stream.name, url, avatarUrl, thumbnailUrl,
                                                                          Constants.Mixer, channelId, server, server.GoLiveChannel, null));
                    }
                }
            }

            foreach (var server in ownerBeamServers)
            {
                if (server.OwnerLiveChannel != 0 && server.Id != 0)
                {
                    if (messages.FirstOrDefault(x => x.GuildId == server.Id && x.UserId == beamId) == null)
                    {
                        var stream = await _mixerManager.GetChannelByName(beamId);

                        string gameName     = stream.type == null ? "a game" : stream.type.name;
                        string url          = "http://mixer.com/" + stream.token;
                        string avatarUrl    = stream.user.avatarUrl != null ? stream.user.avatarUrl : "https://mixer.com/_latest/assets/images/main/avatars/default.jpg";
                        string thumbnailUrl = "https://thumbs.mixer.com/channel/" + stream.id + ".small.jpg";
                        string channelId    = stream.id.Value.ToString();

                        messages.Add(await _messagingService.BuildMessage(stream.token, gameName, stream.name, url, avatarUrl, thumbnailUrl,
                                                                          Constants.Mixer, channelId, server, server.OwnerLiveChannel, null));
                    }
                }
            }

            if (messages.Count > 0)
            {
                var channel = new LiveChannel()
                {
                    Name            = beamId,
                    Servers         = new List <ulong>(),
                    ChannelMessages = await _messagingService.SendMessages(Constants.Mixer, messages)
                };

                File.WriteAllText(
                    _botSettings.DirectorySettings.ConfigRootDirectory +
                    _botSettings.DirectorySettings.LiveDirectory +
                    _botSettings.DirectorySettings.MixerDirectory +
                    beamId + ".json",
                    JsonConvert.SerializeObject(channel));
            }
        }