diff options
author | Dennis Kobert <d-kobert@web.de> | 2019-06-11 23:38:13 +0200 |
---|---|---|
committer | Dennis Kobert <d-kobert@web.de> | 2019-06-11 23:38:13 +0200 |
commit | 2fa4a0e50ebfc97059c8b84dbd17e79f9afc8a8d (patch) | |
tree | c3b34ccb2737e347a73768536895cbbaab13cc01 /DiscoBot/Audio/Voice.cs | |
parent | ec991104f56e90d7bb2878da2fe6ed4e585dfc46 (diff) | |
parent | af74efccf8d21e6151022b71f3cacd3fa83024ee (diff) |
Merge branch 'rework-backend'
Diffstat (limited to 'DiscoBot/Audio/Voice.cs')
-rw-r--r-- | DiscoBot/Audio/Voice.cs | 117 |
1 files changed, 0 insertions, 117 deletions
diff --git a/DiscoBot/Audio/Voice.cs b/DiscoBot/Audio/Voice.cs deleted file mode 100644 index 379f65b..0000000 --- a/DiscoBot/Audio/Voice.cs +++ /dev/null @@ -1,117 +0,0 @@ -namespace DiscoBot.Audio -{ - using System; - using System.Collections.Generic; - using System.ComponentModel; - using System.Diagnostics; - using System.Linq; - using System.Threading.Tasks; - - using DiscoBot.Auxiliary; - using DiscoBot.DSA_Game; - - using Discord; - using Discord.Audio; - using Discord.Commands; - using Discord.WebSocket; - - public class Voice : ModuleBase - { - public static IAudioClient Client { get; set; } - - public static void Send(string path, int volume = 256) - { - if (Client == null) - { - throw new NullReferenceException("Bot befindet sich nicht in einem Sprachchannel"); - } - - // Create FFmpeg using the previous example - var ffmpeg = CreateStream(path, volume); - var output = ffmpeg.StandardOutput.BaseStream; - var barInvoker = new BackgroundWorker(); - barInvoker.DoWork += delegate - { - var discord = Client.CreatePCMStream(AudioApplication.Music); - output.CopyToAsync(discord); - - discord.FlushAsync(); - }; - - barInvoker.RunWorkerAsync(); - } - - [Command("join", RunMode = RunMode.Async)] - public async Task JoinChannelAsync(IVoiceChannel channel = null) - { - var msg = this.Context.Message; - - // Get the audio channel - channel = channel ?? (msg.Author as IGuildUser)?.VoiceChannel; - if (channel == null) - { - await msg.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(); - Client = audioClient; - } - - [Command("leave", RunMode = RunMode.Async)] - public async Task LeaveChannelAsync(IVoiceChannel channel = null) - { -// Permissions.Test(this.Context, "Meister"); - - if (Client != null) - { - SoundEffects.Play("Nooo"); - await Client.StopAsync(); - Client = null; - } - } - - [Command("volume")] - public void SetVolume(int volume) - { - if (volume <= 100 && volume >= 0) - { - SoundEffects.MaxVolume = volume; - } - } - - [Command("play", RunMode = RunMode.Async)] - public async Task PlayAudioAsync(string path) - { - if (Client == null) - { - await this.Context.Channel.SendMessageAsync("Erst Joinen!"); - } - - SoundEffects.Play(path); - - var sounds = Enum.GetValues(typeof(Sound)); - var soundList = new List<Sound>(); - foreach (var sound in sounds) - { - soundList.Add((Sound)sound); - } - - var sc = new SpellCorrect(); - } - - private static Process CreateStream(string path, int vol = 256) - { - var ffmpeg = new ProcessStartInfo - { - FileName = "ffmpeg", - Arguments = $"-i {path} -ac 2 -f s16le -ar 48000 -ab 620000 -vol {vol} pipe:1", - UseShellExecute = false, - RedirectStandardOutput = true, - }; - return Process.Start(ffmpeg); - } - } -} |