Beispiel #1
0
        public async Task Play(IVoiceChannel vc, Audio audio, CancellationToken cancellationToken)
        {
            using var s3object = await s3Client.GetObjectAsync("quotebot-audio-post", audio.Path, cancellationToken);

            using var ffmpeg = CreateStream();
            using var output = ffmpeg.StandardOutput.BaseStream;
            var inputTask = Task.Run(async() =>
            {
                using var input = ffmpeg.StandardInput.BaseStream;
                await s3object.ResponseStream.CopyToAsync(input, cancellationToken);
            }, cancellationToken);

            using var audioClient = await vc.ConnectAsync();

            using var discord = audioClient.CreatePCMStream(AudioApplication.Mixed, bufferMillis: 1);
            try
            {
                await output.CopyToAsync(discord, cancellationToken);

                await inputTask;
            }
            finally
            {
                await discord.FlushAsync(cancellationToken);
            }

            await vc.DisconnectAsync();
        }
Beispiel #2
0
        public async Task Wait()
        {
            _runningSignal.Wait();
            __log.Info("Stop received");

            __log.Info("Wait for playing sound to finish");
            _playingSoundSignal.Wait();

            if (_currentChannel != null)
            {
                __log.Info("Disconnect from current VoiceChannel");
                await _currentChannel.DisconnectAsync();
            }

            __log.Info("Done, bye bye");
        }
 internal async Task LeaveChannel()
 {
     if (_audioClient != null && _audioClient.ConnectionState == ConnectionState.Connected)
     {
         await _voiceChannel.DisconnectAsync();
     }
 }
Beispiel #4
0
        private async Task EndSnippet()
        {
            //Threads are hard
            if (!_endingItem)
            {
                _endingItem = true;
                _streamCanceller.Cancel();
                _streamProcess.Dispose();
                _outputStream.Dispose();
                _foundSinger = false;
                _foundTitle  = false;
                await ShowQuestionCard(_currentItem);

                if (_questions.Count > 0)
                {
                    _endingItem = false;
                    await PlaySnippet(_questions[0]);
                }
                else
                {
                    _discordStream.Dispose();
                    _endingItem = false;
                    await ShowFinalLeaderboard();

                    await _channel.DisconnectAsync();

                    OnFinishedQuestions?.Invoke(this);
                }
            }
        }
Beispiel #5
0
        private Task UserVoiceStateUpdated(SocketUser arg1, SocketVoiceState oldState, SocketVoiceState newState)
        {
            if (arg1.Id == client.CurrentUser.Id)
            {
                return(Task.CompletedTask);
            }


            _ = Task.Run(async() =>
            {
                IVoiceChannel channel = null;
                string audioClipPath  = null;

                //disconnect
                if (newState.VoiceChannel == null && oldState.VoiceChannel != null)
                {
                    channel       = oldState.VoiceChannel;
                    audioClipPath = ClipPaths[SoundClip.Disconnected];
                }
                //connect
                if (newState.VoiceChannel != null && oldState.VoiceChannel == null)
                {
                    channel       = newState.VoiceChannel;
                    audioClipPath = ClipPaths[SoundClip.Connected];
                }

                //server muted
                if (newState.IsMuted && !oldState.IsMuted)
                {
                    channel       = newState.VoiceChannel;
                    audioClipPath = ClipPaths[SoundClip.Muted];
                }

                //un server muted
                if (!newState.IsMuted && oldState.IsMuted)
                {
                    channel       = newState.VoiceChannel;
                    audioClipPath = ClipPaths[SoundClip.Unmuted];
                }

                //move
                if (newState.VoiceChannel != null && oldState.VoiceChannel != null && newState.VoiceChannel.Id != oldState.VoiceChannel.Id)
                {
                    channel       = newState.VoiceChannel;
                    audioClipPath = ClipPaths[SoundClip.Connected];
                }

                if (channel != null && audioClipPath != null)
                {
                    //if (channel.GuildId != 678781680638492672)
                    //	return;

                    var audioClient = await channel.ConnectAsync();
                    await SendAsync(audioClient, audioClipPath);
                    await channel.DisconnectAsync();
                }
            });

            return(Task.CompletedTask);
        }
Beispiel #6
0
        public async Task StopMusic(IVoiceChannel channel = null, bool canceltoken = true)
        {
            if (canceltoken == true)
            {
                CancellationTokenSource token = Program._data.RestoreObject <CancellationTokenSource>($"{Context.Guild.Id}.cts");
                token.Cancel();
            }

            channel = channel ?? (Context.User as IGuildUser)?.VoiceChannel;
            await channel.DisconnectAsync();
        }
 [Command("leave", RunMode = RunMode.Async), Alias("나가")] // message에 !leave이 들어오면 아래 있는 함수를 실행시켜라
 public async Task LeaveChannel()
 {
     if (_channel == null)
     {
         await Context.Channel.SendMessageAsync("봇이 길을 잃었습니다."); return;
     }
     else
     {
         await _channel.DisconnectAsync();
     }
 }
        /// <summary>
        /// Disconnects from the <paramref name="voiceChannel"/>.
        /// </summary>
        /// <param name="voiceChannel">Connected voice channel.</param>
        public async Task DisconnectAsync(IVoiceChannel voiceChannel)
        {
            if (!Players.TryRemove(voiceChannel.GuildId, out _))
            {
                return;
            }

            await voiceChannel.DisconnectAsync().ConfigureAwait(false);

            var destroyPayload = new DestroyPayload(voiceChannel.GuildId);
            await _socketHelper.SendPayloadAsync(destroyPayload);
        }
Beispiel #9
0
        public async Task LeaveCmd(IVoiceChannel channel = null)
        {
            // Get the audio channel
            channel = channel ?? (Context.User as IGuildUser)?.VoiceChannel;
            if (channel == null)
            {
                await Context.Channel.SendMessageAsync("User must be in a voice channel, or a voice channel must be passed as an argument."); return;
            }

            // For the next step with transmitting audio, you would want to pass this Audio Client in to a service.
            await channel.DisconnectAsync();
        }
Beispiel #10
0
        public async Task <AudioPlayer> JoinAsync(IVoiceChannel voiceChannel, ISocketMessageChannel textChannel)
        {
            await voiceChannel.ConnectAsync(true);

            await voiceChannel.DisconnectAsync();

            var client = await voiceChannel.ConnectAsync(true);

            var player = new AudioPlayer(voiceChannel.GuildId, textChannel, voiceChannel, client, this, _client);

            players.Add(player);
            return(player);
        }
Beispiel #11
0
        public async Task LeaveChannel(IVoiceChannel Channel = null)
        {
            Channel = Channel ?? (Context.User as IGuildUser)?.VoiceChannel;
            if (Channel == null)
            {
                await Context.Channel.SendMessageAsync(NoChannelError);

                return;
            }
            await Channel.DisconnectAsync();

            Connections.Remove(Channel.Guild.Id);
        }
Beispiel #12
0
 public void Dispose()
 {
     try
     {
         _shouldLoop = false;
         _currentProcess?.Kill(true);
         _audioClient.StopAsync();
         _channel.DisconnectAsync();
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
     }
 }
Beispiel #13
0
        /// <summary>
        /// Disconnects from the <paramref name="voiceChannel"/>.
        /// </summary>
        /// <param name="voiceChannel">Connected voice channel.</param>
        public async Task DisconnectAsync(IVoiceChannel voiceChannel)
        {
            if (!Players.TryRemove(voiceChannel.GuildId, out LavaPlayer player))
            {
                return;
            }

            await player.DisposeAsync();

            await voiceChannel.DisconnectAsync();

            var destroyPayload = new DestroyPayload(voiceChannel.GuildId);
            await _socketHelper.SendPayloadAsync(destroyPayload);
        }
        public async Task JoinChannel(IVoiceChannel channel = null)
        {
            // Get the audio channel
            channel ??= (Context.User as IGuildUser)?.VoiceChannel;
            if (channel == null)
            {
                await ReplyAsync("User must be in a voice channel, or a voice channel must be passed as an argument.");

                return;
            }

            await channel.DisconnectAsync();

            // For the next step with transmitting audio, you would want to pass this Audio Client in to a service.
            _audioClient = await channel.ConnectAsync();
        }
Beispiel #15
0
        public async Task JoinChannel(string command = null, IVoiceChannel channel = null)
        {
            if (Program.playingSound)
            {
                await Context.User.SendMessageAsync("I am currently busy. Try again shortly");

                return;
            }
            // Get the audio channel
            channel = channel ?? (Context.User as IGuildUser)?.VoiceChannel;
            if (channel == null)
            {
                await Context.Channel.SendMessageAsync("User must be in a voice channel, or a voice channel must be passed as an argument."); return;
            }
            if (command == null)
            {
                await Context.User.SendMessageAsync("Please provide a sound name. Example: !play name. !sounds for a full list of available sounds."); return;
            }

            var sound = SoundManager.SoundManager.GetSound(command);

            if (sound == null)
            {
                await Context.User.SendMessageAsync("The sound you have requested does not exist. Please try again");

                return;
            }

            if (!sound.enabled)
            {
                await Context.User.SendMessageAsync("The sound you have requested is not enabled. Please tell TPU to activate it before trying again");

                return;
            }
            Program.playingSound = true;
            var audioClient = await channel.ConnectAsync(); // Connect to channel

            Program.audioClient = audioClient;
            await Say(audioClient, sound);                  // Play sound

            await channel.DisconnectAsync();                // Disconnect from channel

            Program.playingSound = false;
        }
Beispiel #16
0
        /// <summary>
        /// Joins a voice channel and returns a new instance of <see cref="LavalinkPlayer"/>
        /// </summary>
        /// <param name="voiceChannel"></param>
        /// <returns></returns>
        public async Task <LavalinkPlayer> JoinAsync(IVoiceChannel voiceChannel)
        {
            if (players.ContainsKey(voiceChannel.GuildId))
            {
                throw new InvalidOperationException("This guild is already actively connected");
            }

            // Disconnect from the channel first for a fresh session id
            await voiceChannel.DisconnectAsync();

            LavalinkPlayer player = new LavalinkPlayer(this, voiceChannel);

            players.Add(voiceChannel.GuildId, player);

            // Initiates the voice connection
            await player.ConnectAsync();

            return(player);
        }
Beispiel #17
0
        public async Task JoinChannel([Remainder] IVoiceChannel channel = null)
        {
            // Get the audio channel
            channel = channel ?? (Context.User as IGuildUser)?.VoiceChannel;
            if (channel == null)
            {
                await Context.Channel.SendMessageAsync("User must be in a voice channel, or a voice channel must be passed as an argument."); return;
            }

            // For the next step with transmitting audio, you would want to pass this Audio Client in to a service.
            var audioClient = await channel.ConnectAsync();

            string[] files = Directory.GetFiles(voiceLinesPath, "*.mp3");

            await SendAsync(audioClient, files[rand.Next(files.Length)]);

            //await Context.Channel.SendMessageAsync(files[rand.Next(files.Length)]);

            await channel.DisconnectAsync();
        }
Beispiel #18
0
        // TODO: Implement MoveAsync()/MoveNodeAsync() where we explicitly define that we're moving Lavalink servers

        /// <summary>
        /// Tells lavalink to destroy the voice connection and disconnects from the channel
        /// </summary>
        /// <returns></returns>
        public async Task DisconnectAsync()
        {
            await initialVoiceChannel.DisconnectAsync();
        }
Beispiel #19
0
        public async Task LeaveAsync(IVoiceChannel voiceChannel)
        {
            await voiceChannel.DisconnectAsync();

            players.RemoveAll(x => x.GuildId == voiceChannel.GuildId);
        }