diff options
author | TrueDoctor <d-kobert@web.de> | 2018-04-09 17:41:52 +0200 |
---|---|---|
committer | TrueDoctor <d-kobert@web.de> | 2018-04-09 17:41:52 +0200 |
commit | bdd094926815196802c7d0bdad089fee9791abf4 (patch) | |
tree | abfcafa5bf1463f5c8a94542018ba7c76a29a1be /DiscoBot/Commands | |
parent | db846b1eebf4ee35ea7f72024c0db753b73d0177 (diff) |
Implemented Audio Memes small sound ques wich can be played from anywhere
Diffstat (limited to 'DiscoBot/Commands')
-rw-r--r-- | DiscoBot/Commands/Voice.cs | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/DiscoBot/Commands/Voice.cs b/DiscoBot/Commands/Voice.cs index 772d807..3391452 100644 --- a/DiscoBot/Commands/Voice.cs +++ b/DiscoBot/Commands/Voice.cs @@ -1,8 +1,14 @@ namespace DiscoBot.Commands { + using System; + using System.Collections.Generic; using System.Diagnostics; + using System.Linq; + using System.Media; using System.Threading.Tasks; + using DiscoBot.Auxiliary; + using Discord; using Discord.Audio; using Discord.Commands; @@ -10,6 +16,17 @@ public class Voice : ModuleBase { public static IAudioClient Client { get; set; } + + public static async Task SendAsync(string path, int volume = 256) + { + // Create FFmpeg using the previous example + var ffmpeg = CreateStream(path, volume); + var output = ffmpeg.StandardOutput.BaseStream; + var discord = Client.CreatePCMStream(AudioApplication.Music); + await output.CopyToAsync(discord); + await discord.FlushAsync(); + } + [Command("join", RunMode = RunMode.Async)] public async Task JoinChannelAsync(IVoiceChannel channel = null) { @@ -42,29 +59,40 @@ [Command("play")] public Task PlayAudioAsync(string path) { - return Client == null ? this.Context.Channel.SendMessageAsync("Erst Joinen!") : SendAsync(path); + if (Client == null) + { + return this.Context.Channel.SendMessageAsync("Erst Joinen!"); + } + + var sounds = Enum.GetValues(typeof(Sound)); + var soundList = new List<Sound>(); + foreach (var sound in sounds) + { + soundList.Add((Sound)sound); + } + + var sc = new SpellCorrect(); + + var tSound = soundList.OrderBy(x => sc.Compare(path, x.ToString())).First(); + + if (sc.Compare(path, tSound.ToString()) > SpellCorrect.ErrorThreshold) + { + return SendAsync(path); + } + + return SoundEffects.Play(tSound); } - private static Process CreateStream(string path) + 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 pipe:1", + Arguments = $"-i {path} -ac 2 -f s16le -ar 48000 -ab 620000 -vol {vol} pipe:1", UseShellExecute = false, RedirectStandardOutput = true, }; return Process.Start(ffmpeg); } - - private static async Task SendAsync(string path) - { - // Create FFmpeg using the previous example - var ffmpeg = CreateStream(path); - var output = ffmpeg.StandardOutput.BaseStream; - var discord = Client.CreatePCMStream(AudioApplication.Music); - await output.CopyToAsync(discord); - await discord.FlushAsync(); - } } } |