From 97450e451fe535bccec1651b9960dd0f446736f3 Mon Sep 17 00:00:00 2001 From: TrueDoctor Date: Wed, 6 Jun 2018 17:10:58 +0200 Subject: fixed some async stuff --- DiscoBot/Audio/AudioModule.cs | 2 +- DiscoBot/Audio/AudioService.cs | 10 ++++------ DiscoBot/Audio/Soundeffects.cs | 10 +++++----- DiscoBot/Audio/Voice.cs | 11 +++++------ DiscoBot/Auxiliary/TalentEnumerableExtension.cs | 2 +- DiscoBot/Commands/List.cs | 2 ++ DiscoBot/Commands/MiscCommands.cs | 5 +---- DiscoBot/DSA_Game/Characters/Character.cs | 6 +++--- DiscoBot/Program.cs | 1 - 9 files changed, 22 insertions(+), 27 deletions(-) (limited to 'DiscoBot') diff --git a/DiscoBot/Audio/AudioModule.cs b/DiscoBot/Audio/AudioModule.cs index 9cc4823..f2097b7 100644 --- a/DiscoBot/Audio/AudioModule.cs +++ b/DiscoBot/Audio/AudioModule.cs @@ -71,7 +71,7 @@ namespace DiscoBot.Audio await _service.SendAudioAsync(Context.Guild, Context.Channel, song); } - await SoundEffects.Play(tSound); + SoundEffects.Play(tSound); } } } \ No newline at end of file diff --git a/DiscoBot/Audio/AudioService.cs b/DiscoBot/Audio/AudioService.cs index 52caf23..6e01980 100644 --- a/DiscoBot/Audio/AudioService.cs +++ b/DiscoBot/Audio/AudioService.cs @@ -16,8 +16,7 @@ public async Task JoinAudio(IGuild guild, IVoiceChannel target) { - IAudioClient client; - if (this.connectedChannels.TryGetValue(guild.Id, out client)) + if (this.connectedChannels.TryGetValue(guild.Id, out var client)) { return; } @@ -39,8 +38,7 @@ public async Task LeaveAudio(IGuild guild) { - IAudioClient client; - if (this.connectedChannels.TryRemove(guild.Id, out client)) + if (this.connectedChannels.TryRemove(guild.Id, out var client)) { await client.StopAsync(); //await Log(LogSeverity.Info, $"Disconnected from voice on {guild.Name}."); @@ -55,8 +53,8 @@ await channel.SendMessageAsync("File does not exist."); return; } - IAudioClient client; - if (this.connectedChannels.TryGetValue(guild.Id, out client)) + + if (this.connectedChannels.TryGetValue(guild.Id, out var client)) { //await Log(LogSeverity.Debug, $"Starting playback of {path} in {guild.Name}"); using (var ffmpeg = this.CreateStream(path)) diff --git a/DiscoBot/Audio/Soundeffects.cs b/DiscoBot/Audio/Soundeffects.cs index 7e5e918..1e6dda1 100644 --- a/DiscoBot/Audio/Soundeffects.cs +++ b/DiscoBot/Audio/Soundeffects.cs @@ -23,10 +23,10 @@ { public static int Volume { get; set; } = 50; - public static async Task Play(Sound s) + public static void Play(Sound s) { string url = string.Empty; - int volume = 256; + int volume = 255; switch (s) { case Sound.Bell: @@ -35,7 +35,7 @@ break; case Sound.Finish: url = "https://www.myinstants.com/media/sounds/finishhim.swf.mp3"; - break; + break; case Sound.Magic: url = "https://www.myinstants.com/media/sounds/dream-harp-sound-effect.mp3"; break; @@ -58,7 +58,7 @@ case Sound.Wrong: url = "https://www.myinstants.com/media/sounds/wrong-answer-sound-effect.mp3"; volume = 50; - break; + break; } volume = (int)(volume * (Volume / 100.0)); @@ -67,7 +67,7 @@ if (url != string.Empty) { // await Dsa.Service.SendAudioAsync(url, vol); - Voice.SendAsync(url, volume); + Voice.Send(url, volume); return; } diff --git a/DiscoBot/Audio/Voice.cs b/DiscoBot/Audio/Voice.cs index 84a221c..2c8f75e 100644 --- a/DiscoBot/Audio/Voice.cs +++ b/DiscoBot/Audio/Voice.cs @@ -18,7 +18,7 @@ { public static IAudioClient Client { get; set; } - public static void SendAsync(string path, int volume = 256) + public static void Send(string path, int volume = 256) { if (Client == null) { @@ -26,7 +26,7 @@ } // Create FFmpeg using the previous example - var ffmpeg = CreateStream(path, volume); + var ffmpeg = CreateStream(path, volume); var output = ffmpeg.StandardOutput.BaseStream; var barInvoker = new BackgroundWorker(); barInvoker.DoWork += delegate @@ -36,7 +36,7 @@ discord.FlushAsync(); }; - + barInvoker.RunWorkerAsync(); } @@ -66,10 +66,9 @@ if (Client != null) { - var wait = SoundEffects.Play(Sound.Nooo); + SoundEffects.Play(Sound.Nooo); await Client.StopAsync(); Client = null; - wait.Wait(); } } @@ -103,7 +102,7 @@ if (sc.Compare(path, tSound.ToString()) > SpellCorrect.ErrorThreshold) { - await Task.Run(() => Voice.SendAsync(path)); + await Task.Run(() => Voice.Send(path)); } await Task.Run(() => SoundEffects.Play(tSound)); diff --git a/DiscoBot/Auxiliary/TalentEnumerableExtension.cs b/DiscoBot/Auxiliary/TalentEnumerableExtension.cs index 3c5330b..83975e7 100644 --- a/DiscoBot/Auxiliary/TalentEnumerableExtension.cs +++ b/DiscoBot/Auxiliary/TalentEnumerableExtension.cs @@ -21,7 +21,7 @@ namespace DiscoBot.Auxiliary if (sc.Compare(talent, tTalent.Name) > SpellCorrect.ErrorThreshold) { - SoundEffects.Play(Sound.Wrong).Wait(); + SoundEffects.Play(Sound.Wrong); return $"{c.Name} kann nicht {talent}..."; } diff --git a/DiscoBot/Commands/List.cs b/DiscoBot/Commands/List.cs index 3cd66b9..601178c 100644 --- a/DiscoBot/Commands/List.cs +++ b/DiscoBot/Commands/List.cs @@ -21,6 +21,8 @@ var res = new List(); var character = ((Character)Dsa.Chars.Find(x => x.Name.Equals(Dsa.Relation[this.Context.User.Username]))); + + switch (prop.ToLower()) { case "chars": diff --git a/DiscoBot/Commands/MiscCommands.cs b/DiscoBot/Commands/MiscCommands.cs index 158882c..daf34e2 100644 --- a/DiscoBot/Commands/MiscCommands.cs +++ b/DiscoBot/Commands/MiscCommands.cs @@ -180,10 +180,7 @@ namespace DiscoBot.Commands [Alias("Check")] public async Task CheckAsync(string quarry) { - var perm = new List(); - perm.Add("Admin"); - perm.Add("Mod"); - perm.Add("Privatpolizei"); + var perm = new List { "Admin", "Mod", "Privatpolizei" }; Permissions.Test(this.Context, perm.ToArray()); diff --git a/DiscoBot/DSA_Game/Characters/Character.cs b/DiscoBot/DSA_Game/Characters/Character.cs index 2f994f0..86e9831 100644 --- a/DiscoBot/DSA_Game/Characters/Character.cs +++ b/DiscoBot/DSA_Game/Characters/Character.cs @@ -111,7 +111,7 @@ var attack = this.Kampftalente.OrderBy(x => sc.Compare(talent, x.Name)).First(); if (sc.Compare(talent, attack.Name) > SpellCorrect.ErrorThreshold) { - SoundEffects.Play(Sound.Wrong).Wait(); + SoundEffects.Play(Sound.Wrong); return $"{this.Name} kann nicht mit der Waffenart {talent} umgehen..."; } @@ -135,7 +135,7 @@ if (sc.Compare(talent, attack.Name) > SpellCorrect.ErrorThreshold) { - SoundEffects.Play(Sound.Wrong).Wait(); + SoundEffects.Play(Sound.Wrong); return $"{this.Name} kann nicht mit der Waffenart {talent} umgehen..."; } @@ -159,7 +159,7 @@ var attack = this.Talente.OrderBy(x => sc.Compare(talent, x.Name)).First(); if (sc.Compare(talent, attack.Name) > SpellCorrect.ErrorThreshold) { - SoundEffects.Play(Sound.Wrong).Wait(); + SoundEffects.Play(Sound.Wrong); return $"{this.Name} kann nicht mit der Waffenart {talent} umgehen..."; } diff --git a/DiscoBot/Program.cs b/DiscoBot/Program.cs index 3518fa9..05577ce 100644 --- a/DiscoBot/Program.cs +++ b/DiscoBot/Program.cs @@ -11,7 +11,6 @@ using Microsoft.Extensions.DependencyInjection; namespace DiscoBot { using DiscoBot.Audio; - using DiscoBot.Commands; using DiscoBot.DSA_Game; public class Program -- cgit v1.2.3-54-g00ecf