Exemplo n.º 1
0
        public async Task Add(string channelName)
        {
            if (!IsApprovedAdmin)
            {
                return;
            }

            var channel = await _mixerManager.GetChannelByName(channelName);

            if (channel == null)
            {
                await Context.Channel.SendMessageAsync("The Mixer channel, " + channelName + ", does not exist.");

                return;
            }

            var           file   = Constants.ConfigRootDirectory + Constants.GuildDirectory + Context.Guild.Id + ".json";
            DiscordServer server = null;

            if (File.Exists(file))
            {
                server = JsonConvert.DeserializeObject <DiscordServer>(File.ReadAllText(file));
            }

            if (server == null)
            {
                return;
            }

            if (server.ServerBeamChannels == null)
            {
                server.ServerBeamChannels = new List <string>();
            }

            if (server.ServerBeamChannelIds == null)
            {
                server.ServerBeamChannelIds = new List <string>();
            }

            if (!string.IsNullOrEmpty(server.OwnerBeamChannel) && server.OwnerBeamChannel.ToLower().Equals(channelName.ToLower()))
            {
                await Context.Channel.SendMessageAsync("The channel " + channelName + " is configured as the Owner Mixer channel. " +
                                                       "Please remove it with the '!cb mixer resetowner' command and then try re-adding it.");

                return;
            }

            if (!server.ServerBeamChannels.Contains(channelName.ToLower()))
            {
                server.ServerBeamChannels.Add(channelName.ToLower());
                server.ServerBeamChannelIds.Add(channel.id.Value.ToString());

                if (Constants.EnableMixer)
                {
                    await Program.beamClient.SubscribeToLiveAnnouncements(channel.id.Value.ToString());
                }

                File.WriteAllText(file, JsonConvert.SerializeObject(server));
                await Context.Channel.SendMessageAsync("Added " + channelName + " to the server Mixer streamer list.");
            }
            else
            {
                await Context.Channel.SendMessageAsync(channelName + " is already on the server Mixer streamer list.");
            }
        }
Exemplo n.º 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));
            }
        }