From f6bb62cb32e265da3092ec1fdc49bbe18f8e8213 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Fri, 4 Mar 2016 22:54:03 +0100 Subject: [PATCH] improved blacklist server, small cleanup --- NadekoBot/Classes/Music/MusicControls.cs | 33 ++++++++++-------------- NadekoBot/Classes/Music/Song.cs | 2 -- NadekoBot/Modules/Permissions.cs | 13 +++++----- 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/NadekoBot/Classes/Music/MusicControls.cs b/NadekoBot/Classes/Music/MusicControls.cs index fac665c3..97de9534 100644 --- a/NadekoBot/Classes/Music/MusicControls.cs +++ b/NadekoBot/Classes/Music/MusicControls.cs @@ -43,7 +43,7 @@ namespace NadekoBot.Classes.Music { public Channel PlaybackVoiceChannel { get; private set; } - private bool Stopped { get; set; } = false; + private bool Destroyed { get; set; } = false; public MusicPlayer(Channel startingVoiceChannel, float? defaultVolume) { if (startingVoiceChannel == null) @@ -57,30 +57,25 @@ namespace NadekoBot.Classes.Music { cancelToken = SongCancelSource.Token; Task.Run(async () => { - while (!Stopped) { + while (!Destroyed) { try { audioClient = await PlaybackVoiceChannel.JoinAudio(); - } - catch { + } catch { await Task.Delay(1000); continue; } CurrentSong = GetNextSong(); - if (CurrentSong != null) { + var curSong = CurrentSong; + if (curSong != null) { try { - OnStarted(CurrentSong); - await CurrentSong.Play(audioClient, cancelToken); - } - catch (OperationCanceledException) { + OnStarted(curSong); + await curSong.Play(audioClient, cancelToken); + } catch (OperationCanceledException) { Console.WriteLine("Song canceled"); - } - catch (Exception ex) { + } catch (Exception ex) { Console.WriteLine($"Exception in PlaySong: {ex}"); } - try { - OnCompleted(CurrentSong); - } - catch { } + OnCompleted(curSong); SongCancelSource = new CancellationTokenSource(); cancelToken = SongCancelSource.Token; } @@ -101,6 +96,7 @@ namespace NadekoBot.Classes.Music { public void Stop() { lock (playlistLock) { playlist.Clear(); + CurrentSong = null; if (!SongCancelSource.IsCancellationRequested) SongCancelSource.Cancel(); } @@ -174,13 +170,10 @@ namespace NadekoBot.Classes.Music { public void Destroy() { lock (playlistLock) { playlist.Clear(); + Destroyed = true; if (!SongCancelSource.IsCancellationRequested) SongCancelSource.Cancel(); - try { - Stopped = true; - audioClient.Disconnect(); - } - catch {} + audioClient.Disconnect(); } } } diff --git a/NadekoBot/Classes/Music/Song.cs b/NadekoBot/Classes/Music/Song.cs index 3ab59603..e15db946 100644 --- a/NadekoBot/Classes/Music/Song.cs +++ b/NadekoBot/Classes/Music/Song.cs @@ -209,8 +209,6 @@ namespace NadekoBot.Classes.Music { while (this.MusicPlayer.Paused) await Task.Delay(200, cancelToken); buffer = AdjustVolume(buffer, MusicPlayer.Volume); - Console.WriteLine("ADJUST VOLUME ERROR"); - voiceClient.Send(buffer, 0, read); } await bufferTask; diff --git a/NadekoBot/Modules/Permissions.cs b/NadekoBot/Modules/Permissions.cs index 22dd21bd..a8ed6731 100644 --- a/NadekoBot/Modules/Permissions.cs +++ b/NadekoBot/Modules/Permissions.cs @@ -451,9 +451,9 @@ namespace NadekoBot.Modules { }); }); - cgb.CreateCommand(Prefix + "ucl") + cgb.CreateCommand(Prefix + "cbl") .Description("Blacklists a mentioned channel (#general for example).\n**Usage**: ;ubl [channel_mention]") - .Parameter("user", ParameterType.Unparsed) + .Parameter("channel", ParameterType.Unparsed) .Do(async e => { await Task.Run(async () => { if (!e.Message.MentionedChannels.Any()) return; @@ -464,15 +464,16 @@ namespace NadekoBot.Modules { }); }); - cgb.CreateCommand(Prefix + "usl") + cgb.CreateCommand(Prefix + "sbl") .Description("Blacklists a server by a name or id (#general for example).\n**Usage**: ;usl [servername/serverid]") - .Parameter("user", ParameterType.Unparsed) + .Parameter("server", ParameterType.Unparsed) .Do(async e => { await Task.Run(async () => { - var arg = e.GetArg("user"); + var arg = e.GetArg("server")?.Trim(); if (string.IsNullOrWhiteSpace(arg)) return; - var server = NadekoBot.Client.FindServers(arg.Trim()).FirstOrDefault(); + var server = NadekoBot.Client.Servers.FirstOrDefault(s => s.Id.ToString() == arg) ?? + NadekoBot.Client.FindServers(arg.Trim()).FirstOrDefault(); if (server == null) { await e.Channel.SendMessage("Cannot find that server"); return;