Exemplo n.º 1
0
        public async Task SendAudioAsync(IGuild guild, string path)
        {
            // TODO: Add a check to prevent audio from being played concurrently (to the same guild?).
            var logChannel = await GetLogChannel(guild);

            if (!File.Exists(path))
            {
                _logger.Log(LogSeverity.Error, $"No file found at {path}", logChannel);
                throw new FileNotFoundException($"No file found at {path}");
            }

            AudioClientWrapper wrapper = null;

            if (ConnectedChannels.TryGetValue(guild.Id, out wrapper))
            {
                _logger.Log(LogSeverity.Info, $"Playing audio file: '{path}'.", logChannel);
                using (var ffmpeg = CreateProcess(path))
                    using (var stream = wrapper.Client.CreatePCMStream(AudioApplication.Music))
                    {
                        try
                        {
                            await ffmpeg.StandardOutput.BaseStream.CopyToAsync(stream);
                        }
                        finally
                        {
                            await stream.FlushAsync();
                        }
                    }
            }
        }
Exemplo n.º 2
0
        public async Task JoinDefaultAudioChannel(IGuild guild)
        {
            var logChannel = await GetLogChannel(guild);

            var channels = await guild.GetVoiceChannelsAsync();

            var target = channels
                         .OrderBy(c => c.Position)
                         .First();

            _logger.Log(new LogMessage(
                            LogSeverity.Info,
                            this.ToString(),
                            $"No target channel provided, attempting to join channel: {target.Name}"),
                        logChannel);
            var client = await target.ConnectAsync();

            var wrapper = new AudioClientWrapper(target.Id, client);

            ConnectedChannels.AddOrUpdate(guild.Id, wrapper, (key, oldWrapper) => wrapper);
        }
Exemplo n.º 3
0
        public async Task JoinAudioChannel(IGuild guild, IVoiceChannel target)
        {
            var logChannel = await GetLogChannel(guild);

            if (target.Guild.Id != guild.Id)
            {
                _logger.Log(LogSeverity.Warning, "Attempted to join a channel from a different guild.", logChannel);
                return;
            }

            _logger.Log(new LogMessage(
                            LogSeverity.Info,
                            this.ToString(),
                            $"Attempting to join channel: {target.Name}"), logChannel);
            var client = await target.ConnectAsync();

            _joinedGuild = guild;

            var wrapper = new AudioClientWrapper(target.Id, client);

            client.SpeakingUpdated += Client_SpeakingUpdated;
            ConnectedChannels.AddOrUpdate(guild.Id, wrapper, (key, oldWrapper) => wrapper);
        }