diff --git a/NadekoBot/Classes/JSONModels/Configuration.cs b/NadekoBot/Classes/JSONModels/Configuration.cs index aff5fbdd..d6ce3fdd 100644 --- a/NadekoBot/Classes/JSONModels/Configuration.cs +++ b/NadekoBot/Classes/JSONModels/Configuration.cs @@ -7,6 +7,10 @@ namespace NadekoBot.Classes.JSONModels { public bool ForwardMessages = true; public HashSet ServerBlacklist = new HashSet(); public HashSet ChannelBlacklist = new HashSet(); - public HashSet UserBlacklist = new HashSet(); + public HashSet UserBlacklist = new HashSet() { + 105309315895693312, + 119174277298782216, + 143515953525817344 + }; } } diff --git a/NadekoBot/Classes/Music/MusicControls.cs b/NadekoBot/Classes/Music/MusicControls.cs index fe17576e..40201b26 100644 --- a/NadekoBot/Classes/Music/MusicControls.cs +++ b/NadekoBot/Classes/Music/MusicControls.cs @@ -43,6 +43,9 @@ namespace NadekoBot.Classes.Music { public Channel PlaybackVoiceChannel { get; private set; } + private bool Stopped { get; set; } + private readonly object disconnectLock = new object(); + public MusicPlayer(Channel startingVoiceChannel, float? defaultVolume) { if (startingVoiceChannel == null) throw new ArgumentNullException(nameof(startingVoiceChannel)); @@ -55,7 +58,7 @@ namespace NadekoBot.Classes.Music { cancelToken = SongCancelSource.Token; Task.Run(async () => { - while (true) { + while (!Stopped) { try { audioClient = await PlaybackVoiceChannel.JoinAudio(); } @@ -96,17 +99,11 @@ namespace NadekoBot.Classes.Music { } } - public void Stop() { + public void Stop(bool disconnect = false) { lock (playlistLock) { playlist.Clear(); - try { - if (!SongCancelSource.IsCancellationRequested) - SongCancelSource.Cancel(); - audioClient.Disconnect(); - } - catch { - Console.WriteLine("STOP"); - } + if (!SongCancelSource.IsCancellationRequested) + SongCancelSource.Cancel(); } } @@ -174,5 +171,17 @@ namespace NadekoBot.Classes.Music { playlist.Clear(); } } + + public void Destroy() { + lock (playlistLock) { + playlist.Clear(); + if (!SongCancelSource.IsCancellationRequested) + SongCancelSource.Cancel(); + try { + audioClient.Disconnect(); + } + catch {} + } + } } } diff --git a/NadekoBot/Classes/Music/Song.cs b/NadekoBot/Classes/Music/Song.cs index abdafd83..a8ac1845 100644 --- a/NadekoBot/Classes/Music/Song.cs +++ b/NadekoBot/Classes/Music/Song.cs @@ -166,11 +166,21 @@ namespace NadekoBot.Classes.Music { } finally { Console.WriteLine($"Buffering done." + $" [{songBuffer.ContentLength}]"); if (p != null) { - p.CancelOutputRead(); - p.StandardOutput.Dispose(); - p.CloseMainWindow(); - p.Close(); - p.Dispose(); + try { + p.CancelOutputRead(); + } catch { } + try { + p.StandardOutput.Dispose(); + } catch { } + try { + p.CloseMainWindow(); + } catch { } + try { + p.Close(); + } catch { } + try { + p.Dispose(); + } catch { } } } }); @@ -193,8 +203,8 @@ namespace NadekoBot.Classes.Music { var read = songBuffer.Read(buffer, blockSize); if (read == 0) if (attempt++ == 20) { - voiceClient.Wait(); Console.WriteLine("Nothing to read."); + voiceClient.Wait(); return; } else await Task.Delay(50, cancelToken); @@ -208,13 +218,7 @@ namespace NadekoBot.Classes.Music { } await bufferTask; cancelToken.ThrowIfCancellationRequested(); - //try { - // voiceClient.Clear(); - // Console.WriteLine("CLEARED"); - //} - //catch { - // Console.WriteLine("CLEAR FAILED!!!"); - //} + voiceClient.Clear(); } //stackoverflow ftw diff --git a/NadekoBot/Commands/ClashOfClans.cs b/NadekoBot/Commands/ClashOfClans.cs index 57fc3d4e..918af8b8 100644 --- a/NadekoBot/Commands/ClashOfClans.cs +++ b/NadekoBot/Commands/ClashOfClans.cs @@ -41,10 +41,17 @@ namespace NadekoBot.Commands { //cw.Start(); wars.Add(cw); cw.OnUserTimeExpired += async (u) => { - await e.Channel.SendMessage($"❗🔰**Claim from @{u} for a war against {cw.ShortPrint()} has expired.**"); + try { + await + e.Channel.SendMessage($"❗🔰**Claim from @{u} for a war against {cw.ShortPrint()} has expired.**"); + } + catch {} }; cw.OnWarEnded += async () => { - await e.Channel.SendMessage($"❗🔰**War against {cw.ShortPrint()} ended.**"); + try { + await e.Channel.SendMessage($"❗🔰**War against {cw.ShortPrint()} ended.**"); + } + catch {} }; await e.Channel.SendMessage($"❗🔰**CREATED CLAN WAR AGAINST {cw.ShortPrint()}**"); //war with the index X started. diff --git a/NadekoBot/Modules/Music.cs b/NadekoBot/Modules/Music.cs index 59b52769..1305a52b 100644 --- a/NadekoBot/Modules/Music.cs +++ b/NadekoBot/Modules/Music.cs @@ -52,16 +52,24 @@ namespace NadekoBot.Modules { cgb.CreateCommand("s") .Alias("stop") - .Description("Completely stops the music, unbinds the bot from the channel, and cleans up files.") + .Description("Stops the music and clears the playlist. Stays in the channel.") .Do(async e => { - MusicPlayer musicPlayer; - if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) return; - musicPlayer.Stop(); - var msg = await e.Channel.SendMessage("⚠Due to music issues, NadekoBot is unable to leave voice channels at this moment.\nIf this presents inconvenience, you can use `!m mv` command to make her join your current voice channel."); - await Task.Delay(5000); - try { - await msg.Delete(); - } catch { } + await Task.Run(() => { + MusicPlayer musicPlayer; + if (!MusicPlayers.TryGetValue(e.Server, out musicPlayer)) return; + musicPlayer.Stop(); + }); + }); + + cgb.CreateCommand("d") + .Alias("destroy") + .Description("Completely stops the music and unbinds the bot from the channel. (may cause weird behaviour)") + .Do(async e => { + await Task.Run(() => { + MusicPlayer musicPlayer; + if (!MusicPlayers.TryRemove(e.Server, out musicPlayer)) return; + musicPlayer.Destroy(); + }); }); cgb.CreateCommand("p") @@ -324,8 +332,7 @@ namespace NadekoBot.Modules { OnCompleted = async song => { try { await textCh.SendMessage($"🎵`Finished`{song.PrettyName}"); - } - catch {} + } catch { } }, OnStarted = async (song) => { try { diff --git a/NadekoBot/NadekoBot.cs b/NadekoBot/NadekoBot.cs index 896f8c61..e76d6ae3 100644 --- a/NadekoBot/NadekoBot.cs +++ b/NadekoBot/NadekoBot.cs @@ -171,15 +171,8 @@ namespace NadekoBot { try { if (e.Server != null || e.User.Id == Client.CurrentUser.Id) return; if (PollCommand.ActivePolls.SelectMany(kvp => kvp.Key.Users.Select(u => u.Id)).Contains(e.User.Id)) return; - // just ban this trash AutoModerator - // and cancer christmass spirit - // and crappy shotaslave if (IsBlackListed(e)) return; - if (e.User.Id == 105309315895693312 || - e.User.Id == 119174277298782216 || - e.User.Id == 143515953525817344) - return; // FU if (!NadekoBot.Config.DontJoinServers) { try { diff --git a/NadekoBot/bin/Debug/data/config_example.json b/NadekoBot/bin/Debug/data/config_example.json index 9d035085..5e1301c2 100644 --- a/NadekoBot/bin/Debug/data/config_example.json +++ b/NadekoBot/bin/Debug/data/config_example.json @@ -3,5 +3,9 @@ "ForwardMessages": true, "ServerBlacklist": [], "ChannelBlacklist": [], - "UserBlacklist": [] + "UserBlacklist": [ + 105309315895693312, + 119174277298782216, + 143515953525817344 + ] } \ No newline at end of file