Ejemplo n.º 1
0
        public static async Task StreamOffline(string beamId)
        {
            IMixerManager mixerManager = new MixerManager();
            var           stream       = await mixerManager.GetChannelByName(beamId);

            var live = BotFiles.GetCurrentlyLiveBeamChannels().FirstOrDefault(x => x.Name == beamId);

            if (live == null)
            {
                return;
            }

            foreach (var message in live.ChannelMessages)
            {
                var serverFile = BotFiles.GetConfiguredServers().FirstOrDefault(x => x.Id == message.GuildId);

                if (serverFile == null)
                {
                    continue;
                }

                if (serverFile.DeleteWhenOffline)
                {
                    await DiscordHelper.DeleteMessage(message.GuildId, message.ChannelId, message.MessageId);
                }
                else
                {
                    await DiscordHelper.SetOfflineStream(message.GuildId, serverFile.StreamOfflineMessage, message.ChannelId, message.MessageId);
                }

                BotFiles.DeleteLiveBeamChannel(beamId);
            }
        }
Ejemplo n.º 2
0
        public static async Task AnnounceLiveChannel(string beamId)
        {
            IMixerManager mixerManager = new MixerManager();
            var           servers      = BotFiles.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 MessagingHelper.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 MessagingHelper.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 MessagingHelper.SendMessages(Constants.Mixer, messages)
                };

                File.WriteAllText(
                    Constants.ConfigRootDirectory +
                    Constants.LiveDirectory +
                    Constants.MixerDirectory +
                    beamId + ".json",
                    JsonConvert.SerializeObject(channel));
            }
        }
Ejemplo n.º 3
0
        public static async Task <BroadcastMessage> BuildTestPublishedMessage(SocketUser user, ulong guildId, ulong channelId)
        {
            var servers = BotFiles.GetConfiguredServers();
            var server  = servers.FirstOrDefault(x => x.Id == guildId);

            if (server == null)
            {
                return(null);
            }

            string url = "http://" + (server.UseYouTubeGamingPublished ? "gaming" : "www") + ".youtube.com/watch?v=B7wkzmZ4GBw";

            EmbedBuilder       embed  = new EmbedBuilder();
            EmbedAuthorBuilder author = new EmbedAuthorBuilder();
            EmbedFooterBuilder footer = new EmbedFooterBuilder();


            if (server.PublishedMessage == null)
            {
                server.PublishedMessage = "%CHANNEL% just published a new video.";
            }

            Color red = new Color(179, 18, 23);

            author.IconUrl    = user.GetAvatarUrl() + "?_=" + Guid.NewGuid().ToString().Replace("-", "");
            author.Name       = Program.client.CurrentUser.Username;
            author.Url        = url;
            footer.Text       = "[" + Constants.YouTube + "] - " + DateTime.UtcNow.AddHours(server.TimeZoneOffset);
            footer.IconUrl    = "http://couchbot.io/img/ytg.jpg";
            embed.Author      = author;
            embed.Color       = red;
            embed.Description = server.PublishedMessage.Replace("%CHANNEL%", "Test Channel").Replace("%TITLE%", "Test Title").Replace("%URL%", url);

            embed.Title        = "Test Channel published a new video!";
            embed.ThumbnailUrl = "http://couchbot.io/img/bot/vader.jpg" + "?_=" + Guid.NewGuid().ToString().Replace("-", "");
            embed.ImageUrl     = server.AllowThumbnails ? "http://couchbot.io/img/bot/test_thumbnail.jpg" + "?_=" + Guid.NewGuid().ToString().Replace("-", "") : "";
            embed.Footer       = footer;

            var role = await DiscordHelper.GetRoleByGuildAndId(server.Id, server.MentionRole);

            var roleName = "";

            if (role == null)
            {
                server.MentionRole = 0;
            }

            if (server.MentionRole == 0)
            {
                roleName = "@everyone";
            }
            else if (server.MentionRole == 1)
            {
                roleName = "@here";
            }
            else
            {
                roleName = role.Mention;
            }

            var message = (server.AllowEveryone ? roleName + " " : "");

            if (server.UseTextAnnouncements)
            {
                if (!server.AllowThumbnails)
                {
                    url = "<" + url + ">";
                }

                message += "**[Test]** " + server.PublishedMessage.Replace("%CHANNEL%", "Test Channel").Replace("%TITLE%", "Test Title").Replace("%URL%", url);
            }

            var broadcastMessage = new BroadcastMessage()
            {
                GuildId   = server.Id,
                ChannelId = channelId,
                UserId    = "0",
                Message   = message,
                Platform  = "Test",
                Embed     = (!server.UseTextAnnouncements ? embed.Build() : null)
            };

            return(broadcastMessage);
        }
Ejemplo n.º 4
0
        public static async Task <BroadcastMessage> BuildTestMessage(SocketUser user, ulong guildId, ulong channelId, string platform)
        {
            var servers = BotFiles.GetConfiguredServers();
            var server  = servers.FirstOrDefault(x => x.Id == guildId);

            if (server == null)
            {
                return(null);
            }

            string gameName = "a game";;
            string url      = "http://couchbot.io";

            EmbedBuilder       embed  = new EmbedBuilder();
            EmbedAuthorBuilder author = new EmbedAuthorBuilder();
            EmbedFooterBuilder footer = new EmbedFooterBuilder();

            if (server.LiveMessage == null)
            {
                server.LiveMessage = "%CHANNEL% just went live with %GAME% - %TITLE% - %URL%";
            }

            Color color = new Color(76, 144, 243);

            if (platform.Equals(Constants.Twitch))
            {
                color          = new Color(100, 65, 164);
                footer.Text    = "[" + Constants.Twitch + "] - " + DateTime.UtcNow.AddHours(server.TimeZoneOffset);
                footer.IconUrl = "http://couchbot.io/img/twitch.jpg";
            }
            else if (platform.Equals(Constants.YouTube) || platform.Equals(Constants.YouTubeGaming))
            {
                color          = new Color(179, 18, 23);
                footer.Text    = "[" + Constants.YouTubeGaming + "] - " + DateTime.UtcNow.AddHours(server.TimeZoneOffset);
                footer.IconUrl = "http://couchbot.io/img/ytg.jpg";
            }
            else if (platform.Equals(Constants.Smashcast))
            {
                color          = new Color(153, 204, 0);
                footer.Text    = "[" + Constants.Smashcast + "] - " + DateTime.UtcNow.AddHours(server.TimeZoneOffset);
                footer.IconUrl = "http://couchbot.io/img/smashcast.png";
            }
            else if (platform.Equals(Constants.Mixer))
            {
                color          = new Color(76, 144, 243);
                footer.Text    = "[" + Constants.Mixer + "] - " + DateTime.UtcNow.AddHours(server.TimeZoneOffset);
                footer.IconUrl = "http://couchbot.io/img/beam.jpg";
            }

            author.IconUrl     = (user.GetAvatarUrl() != null ? user.GetAvatarUrl() : "http://couchbot.io/img/bot/discord.png") + "?_=" + Guid.NewGuid().ToString().Replace("-", "");
            author.Name        = Program.client.CurrentUser.Username;
            author.Url         = url;
            embed.Author       = author;
            embed.Color        = color;
            embed.Description  = server.LiveMessage.Replace("%CHANNEL%", "Test Channel").Replace("%GAME%", gameName).Replace("%TITLE%", "Test Title").Replace("%URL%", url);
            embed.Title        = "Test Channel has gone live!";
            embed.ThumbnailUrl = "http://couchbot.io/img/bot/vader.jpg" + "?_=" + Guid.NewGuid().ToString().Replace("-", "");
            embed.ImageUrl     = server.AllowThumbnails ? "http://couchbot.io/img/bot/test_thumbnail.jpg" + "?_=" + Guid.NewGuid().ToString().Replace("-", "") : "";
            embed.Footer       = footer;

            var role = await DiscordHelper.GetRoleByGuildAndId(server.Id, server.MentionRole);

            var roleName = "";

            if (role == null && server.MentionRole != 1)
            {
                server.MentionRole = 0;
            }

            if (server.MentionRole == 0)
            {
                roleName = "@everyone";
            }
            else if (server.MentionRole == 1)
            {
                roleName = "@here";
            }
            else
            {
                roleName = role.Mention;
            }

            var message = (server.AllowEveryone ? roleName + " " : "");

            if (server.UseTextAnnouncements)
            {
                if (!server.AllowThumbnails)
                {
                    url = "<" + url + ">";
                }

                message += "**[Test]** " + server.LiveMessage.Replace("%CHANNEL%", "Test Channel").Replace("%GAME%", gameName).Replace("%TITLE%", "Test Title").Replace("%URL%", url);
            }

            var broadcastMessage = new BroadcastMessage()
            {
                GuildId   = server.Id,
                ChannelId = channelId,
                UserId    = "0",
                Message   = message,
                Platform  = "Test",
                Embed     = (!server.UseTextAnnouncements ? embed.Build() : null)
            };

            return(broadcastMessage);
        }