Esempio n. 1
0
        /// <summary>
        ///     Move to a different voice channel.
        /// </summary>
        /// <param name="voiceChannel">The voice channel to connect to.</param>
        /// <exception cref="InvalidPlayerException">Thrown if not connected to a voice channel.</exception>
        /// <exception cref="InvalidAudioChannelException">Thrown if already connected to the specified voice channel.</exception>
        public async Task Move(IVoiceChannel voiceChannel)
        {
            if (_player == null)
            {
                throw new InvalidPlayerException("Not connected to a voice channel");
            }
            if (_player.VoiceChannel.Id.Equals(voiceChannel.Id))
            {
                throw new InvalidAudioChannelException("The argument is the same as the source.");
            }

            await _lavaNode.MoveChannelAsync(voiceChannel);
        }
Esempio n. 2
0
        public async Task <string> MoveAsync(IGuild guild, IVoiceChannel voiceChannel, ITextChannel textChannel)
        {
            if (!guildInfo.ContainsKey(guild))
            {
                return("Not currently in a voice channel.");
            }
            await lavaNode.MoveChannelAsync(voiceChannel);

            var player = lavaNode.GetPlayer(guild);

            if (guildInfo.TryGetValue(guild, out DJGuildInfo val))
            {
                val.voiceChannel = voiceChannel;
            }
            return($"Moved from {player.VoiceChannel} to {voiceChannel}.");
        }
Esempio n. 3
0
        public async Task Command([Remainder] string vcMatch = null)
        {
            LavaNode           node     = ConfigProperties.LavaNode;
            SocketVoiceChannel botCurVc = Context.Guild.CurrentUser.VoiceChannel;
            SocketVoiceChannel vc       = vcMatch == null
                ? (Context.User as SocketGuildUser).VoiceChannel
                : Context.Guild.VoiceChannels.First(x => x.Name.ToLower().Contains(vcMatch.ToLower()));

            if (node.HasPlayer(Context.Guild) && vc != null)
            {
                try
                {
                    await node.MoveChannelAsync(vc);
                }
                catch (Exception)
                {
                    await SendBasicErrorEmbedAsync($"It looks like I'm already connected to this voice channel " +
                                                   $"via the WebSocket. If I am not present in the voice channel, this " +
                                                   $"is due to an error. To fix this issue, join a new voice channel and " +
                                                   $"try the command again. This issue usually arises when I am manually " +
                                                   $"force-disconnected from the channel.");

                    return;
                }

                await SendBasicSuccessEmbedAsync(
                    $"{Context.User.Mention} Successfully moved to `{vc.Name}`.");
            }
            else
            {
                if (vc == botCurVc)
                {
                    await SendBasicErrorEmbedAsync($"I am already connected to this voice channel.");

                    return;
                }

                await node.JoinAsync(vc);
                await SendBasicSuccessEmbedAsync($"{Context.User.Mention} Successfully joined `{vc.Name}`.");
            }
        }
Esempio n. 4
0
        private async Task UserVoiceStateUpdated(SocketUser socketUser, SocketVoiceState oldSocketVoiceState, SocketVoiceState newSocketVoiceState)
        {
            if (socketUser.IsBot)
            {
                return;
            }

            var member = await _db.ServerMembers.FirstOrDefaultAsync(x => x.DiscordId == socketUser.Id.ToString());

            if (member?.IntroSong == null || socketUser.Id == _lastRequestBy)
            {
                return;
            }

            if (oldSocketVoiceState.VoiceChannel == null)
            {
                Console.WriteLine($"User {socketUser.Username} entered the server!");

                if (_lavaNode.HasPlayer(newSocketVoiceState.VoiceChannel.Guild))
                {
                    await _lavaNode.MoveChannelAsync(newSocketVoiceState.VoiceChannel);
                }
                else
                {
                    await _audioService.JoinChannel(socketUser as IVoiceState, newSocketVoiceState.VoiceChannel.Guild);
                }

                var player = _lavaNode.GetPlayer(newSocketVoiceState.VoiceChannel.Guild);
                await player.UpdateVolumeAsync(7);

                var searchResponse = await _lavaNode.SearchAsync(member.IntroSong.Url);

                var track    = searchResponse.Tracks[0];
                var timespan = member?.IntroSongSeek ?? TimeSpan.Zero;
                await player.PlayAsync(track);

                if (member?.IntroSongSeek.HasValue ?? false)
                {
                    await player.SeekAsync(member.IntroSongSeek);
                }

                _lastRequestBy = socketUser.Id;

                if (_cancelIntro != null && !_cancelIntro.IsCancellationRequested)
                {
                    _cancelIntro.Cancel();
                }

                _cancelIntro = new CancellationTokenSource();
                var cancellationToken = _cancelIntro.Token;

                Task.Run(async() =>
                {
                    await Task.Delay(TimeSpan.FromSeconds(30), cancellationToken);

                    if (cancellationToken.IsCancellationRequested)
                    {
                        return;
                    }

                    if (player.PlayerState != PlayerState.Disconnected && socketUser.Id == _lastRequestBy)
                    {
                        await _lavaNode.LeaveAsync(newSocketVoiceState.VoiceChannel);
                    }
                }, cancellationToken);
            }

            return;
        }