Пример #1
0
        public async Task VoicePlay(string url)
        {
            if ((Context.User as IGuildUser).VoiceChannel == null)
            {
                await ReplyAsync("Enter a voice channel to use voice commands!");

                return;
            }

            var client = new YoutubeClient();
            var info   = await client.Videos.GetAsync(url);

            if (info.Duration.Hours >= 1)
            {
                await ReplyAsync("Video is too long! Keep it under 1 hour.");

                return;
            }

            await ReplyAsync("", false, GetVideoEmbed(info).Build());

            if (_voiceManager.HasActiveService(Context.Guild.Id))
            {
                _voiceManager.AddVideoToServiceQueue(Context.Guild.Id, info);
            }
            else
            {
                await _voiceManager.CreateVoiceService((Context.User as IGuildUser).VoiceChannel, info);
            }
        }
Пример #2
0
        private async Task OnVoiceStateUpdated(SocketUser user, SocketVoiceState oldState, SocketVoiceState newState)
        {
            XDocument doc   = XDocument.Load(Globals.path + "Servers.xml");
            var       oldVC = oldState.VoiceChannel;
            var       newVC = newState.VoiceChannel;

            if (oldVC == null && newVC != null) //joined voice channel
            {
                ulong    guild = newVC.Guild.Id;
                XElement inVoiceChannelElem = doc.Root.XPathSelectElement($"./server[@id='{guild}']/InVoiceChannel");
                if (inVoiceChannelElem.Value == "")
                {
                    return;
                }

                OverwritePermissions permissions = new OverwritePermissions(viewChannel: PermValue.Allow, sendMessages: PermValue.Allow);

                var textChannel = newVC.Guild.GetTextChannel(ulong.Parse(inVoiceChannelElem.Value));
                await textChannel.AddPermissionOverwriteAsync(user, permissions); //give them invoice channel perms
            }
            else if (oldVC != null && newVC == null)                              //left voice channel
            {
                ulong guild = oldVC.Guild.Id;
                if (_voiceManager.HasActiveService(guild))
                {
                    if (oldVC.Id == _voiceManager.GetServiceVoiceChannelId(guild))
                    {
                        if (oldVC.Users.Count == 1)                //only the bot left in there
                        {
                            _voiceManager.ForceStopService(guild); //kill the service
                        }
                    }
                }
                XElement inVoiceChannelElem = doc.Root.XPathSelectElement($"./server[@id='{guild}']/InVoiceChannel");
                if (inVoiceChannelElem.Value == "")
                {
                    return;
                }

                var textChannel = oldVC.Guild.GetTextChannel(ulong.Parse(inVoiceChannelElem.Value));
                await textChannel.RemovePermissionOverwriteAsync(user); //remove their invoice channel perms
            }
            else if (oldVC != null && newVC != null && oldVC != newVC)  //moved channel
            {
                ulong guild = oldVC.Guild.Id;
                if (_voiceManager.HasActiveService(guild))
                {
                    if (oldVC.Id == _voiceManager.GetServiceVoiceChannelId(guild))
                    {
                        if (oldVC.Users.Count == 1)                //only the bot left in there
                        {
                            _voiceManager.ForceStopService(guild); //kill the service
                        }
                    }
                }
            }
        }