From c5c9e98b516a6ef4aa51999e306be429e803aa9c Mon Sep 17 00:00:00 2001 From: Kwoth Date: Wed, 20 Jul 2016 22:41:02 +0200 Subject: [PATCH 01/17] fix #429 --- NadekoBot/Modules/Searches/SearchesModule.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NadekoBot/Modules/Searches/SearchesModule.cs b/NadekoBot/Modules/Searches/SearchesModule.cs index 15c1c9be..1a2ed20b 100644 --- a/NadekoBot/Modules/Searches/SearchesModule.cs +++ b/NadekoBot/Modules/Searches/SearchesModule.cs @@ -226,10 +226,10 @@ $@"๐ŸŒ **Weather for** ใ€{obj["target"]}ใ€‘ .Parameter("terms", ParameterType.Unparsed) .Do(async e => { - var terms = e.GetArg("terms")?.Trim().Replace(' ', '+'); + var terms = e.GetArg("terms")?.Trim(); if (string.IsNullOrWhiteSpace(terms)) return; - await e.Channel.SendMessage($"https://google.com/search?q={ HttpUtility.UrlEncode(terms) }") + await e.Channel.SendMessage($"https://google.com/search?q={ HttpUtility.UrlEncode(terms).Replace(' ', '+') }") .ConfigureAwait(false); }); From 2e6bdc9f08d1af46cd5b4cc788b2405cab89a0df Mon Sep 17 00:00:00 2001 From: Kwoth Date: Wed, 20 Jul 2016 22:51:41 +0200 Subject: [PATCH 02/17] woops, fixed #426 , no longer saying queue full when its not --- NadekoBot/Modules/Music/Classes/MusicControls.cs | 2 -- NadekoBot/Modules/Music/MusicModule.cs | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/NadekoBot/Modules/Music/Classes/MusicControls.cs b/NadekoBot/Modules/Music/Classes/MusicControls.cs index 41e8c7c1..146ca5ea 100644 --- a/NadekoBot/Modules/Music/Classes/MusicControls.cs +++ b/NadekoBot/Modules/Music/Classes/MusicControls.cs @@ -27,8 +27,6 @@ namespace NadekoBot.Modules.Music.Classes public class MusicPlayer { - public static int MaximumPlaylistSize => 50; - private IAudioClient audioClient { get; set; } private readonly List playlist = new List(); diff --git a/NadekoBot/Modules/Music/MusicModule.cs b/NadekoBot/Modules/Music/MusicModule.cs index c9900e7c..18b8966c 100644 --- a/NadekoBot/Modules/Music/MusicModule.cs +++ b/NadekoBot/Modules/Music/MusicModule.cs @@ -151,7 +151,7 @@ namespace NadekoBot.Modules.Music else if (musicPlayer.RepeatPlaylist) toSend += "๐Ÿ”"; toSend += $" **{musicPlayer.Playlist.Count}** `tracks currently queued. Showing page {page}` "; - if (musicPlayer.Playlist.Count >= MusicPlayer.MaximumPlaylistSize) + if (musicPlayer.Playlist.Count >= musicPlayer.MaxQueueSize) toSend += "**Song queue is full!**\n"; else toSend += "\n"; From ae6deee1db4c6fefaf196b6e77cda8266b6b7cd0 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Wed, 20 Jul 2016 22:58:41 +0200 Subject: [PATCH 03/17] ace is the strongest high card #423 --- NadekoBot/Modules/Gambling/Helpers/Cards.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NadekoBot/Modules/Gambling/Helpers/Cards.cs b/NadekoBot/Modules/Gambling/Helpers/Cards.cs index 76dc73a5..1cd4ba95 100644 --- a/NadekoBot/Modules/Gambling/Helpers/Cards.cs +++ b/NadekoBot/Modules/Gambling/Helpers/Cards.cs @@ -226,7 +226,7 @@ namespace NadekoBot.Modules.Gambling.Helpers { return kvp.Key; } - return "High card " + cards.Max().GetName(); + return "High card " + (cards.FirstOrDefault(c => c.Number == 1)?.GetName() ?? cards.Max().GetName()); } } } From c06047b67c670c23aab70d4cc07584875d3880ef Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 21 Jul 2016 01:51:47 +0200 Subject: [PATCH 04/17] reduced per user cooldown to 1 second --- NadekoBot/Modules/Permissions/Classes/PermissionChecker.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NadekoBot/Modules/Permissions/Classes/PermissionChecker.cs b/NadekoBot/Modules/Permissions/Classes/PermissionChecker.cs index 94de43f6..412ce69a 100644 --- a/NadekoBot/Modules/Permissions/Classes/PermissionChecker.cs +++ b/NadekoBot/Modules/Permissions/Classes/PermissionChecker.cs @@ -26,8 +26,8 @@ namespace NadekoBot.Modules.Permissions.Classes { while (true) { - //blacklist is cleared every 1.75 seconds. That is the most time anyone will be blocked - await Task.Delay(1750).ConfigureAwait(false); + //blacklist is cleared every 1.00 seconds. That is the most time anyone will be blocked + await Task.Delay(1000).ConfigureAwait(false); timeBlackList.Clear(); } }); From b506064d37ed837a24acfd9d6927bd80399211b8 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 21 Jul 2016 02:13:16 +0200 Subject: [PATCH 05/17] rewrite started --- .../Modules/Music/Classes/MusicControls.cs | 200 ++++++++++-------- 1 file changed, 111 insertions(+), 89 deletions(-) diff --git a/NadekoBot/Modules/Music/Classes/MusicControls.cs b/NadekoBot/Modules/Music/Classes/MusicControls.cs index 146ca5ea..2f0082ee 100644 --- a/NadekoBot/Modules/Music/Classes/MusicControls.cs +++ b/NadekoBot/Modules/Music/Classes/MusicControls.cs @@ -2,7 +2,9 @@ using Discord.Audio; using NadekoBot.Extensions; using System; +using System.Collections.Concurrent; using System.Collections.Generic; +using System.Linq; using System.Threading; using System.Threading.Tasks; namespace NadekoBot.Modules.Music.Classes @@ -52,6 +54,8 @@ namespace NadekoBot.Modules.Music.Classes public bool Autoplay { get; set; } = false; public uint MaxQueueSize { get; set; } = 0; + private ConcurrentQueue actionQueue { get; set; } = new ConcurrentQueue(); + public MusicPlayer(Channel startingVoiceChannel, float? defaultVolume) { if (startingVoiceChannel == null) @@ -66,65 +70,92 @@ namespace NadekoBot.Modules.Music.Classes Task.Run(async () => { - while (!Destroyed) + try { - try - { - if (audioClient?.State != ConnectionState.Connected) - audioClient = await PlaybackVoiceChannel.JoinAudio().ConfigureAwait(false); - } - catch - { - await Task.Delay(1000).ConfigureAwait(false); - continue; - } - CurrentSong = GetNextSong(); - var curSong = CurrentSong; - if (curSong != null) + while (!Destroyed) { try { - OnStarted(this, curSong); - await curSong.Play(audioClient, cancelToken).ConfigureAwait(false); + Action action; + if (actionQueue.TryDequeue(out action)) + { + action(); + } } - catch (OperationCanceledException) + finally { - Console.WriteLine("Song canceled"); + await Task.Delay(100).ConfigureAwait(false); } - catch (Exception ex) - { - Console.WriteLine($"Exception in PlaySong: {ex}"); - } - OnCompleted(this, curSong); - curSong = CurrentSong; //to check if its null now - if (curSong != null) - if (RepeatSong) - playlist.Insert(0, curSong); - else if (RepeatPlaylist) - playlist.Insert(playlist.Count, curSong); - SongCancelSource = new CancellationTokenSource(); - cancelToken = SongCancelSource.Token; } - await Task.Delay(1000).ConfigureAwait(false); } - }); + catch (Exception ex) + { + Console.WriteLine("Action queue crashed"); + Console.WriteLine(ex); + } + }).ConfigureAwait(false); + + var t = new Thread(new ThreadStart(async () => + { + try + { + while (!Destroyed) + { + try + { + if (audioClient.State != ConnectionState.Connected) + { + audioClient = await PlaybackVoiceChannel.JoinAudio(); + continue; + } + + var song = CurrentSong; + + if (song == null) + continue; + + try + { + await song.Play(audioClient, cancelToken); + } + catch (OperationCanceledException) + { + Console.WriteLine("Song canceled"); + SongCancelSource = new CancellationTokenSource(); + cancelToken = SongCancelSource.Token; + } + OnCompleted(this, song); + + if (RepeatPlaylist) + AddSong(song, song.QueuerName); + + if (RepeatSong) + AddSong(song, 0); + } + finally + { + await Task.Delay(300).ConfigureAwait(false); + } + } + } + catch (Exception ex) { + Console.WriteLine("Music thread crashed."); + Console.WriteLine(ex); + } + })); + + t.Start(); } public void Next() { - lock (playlistLock) - { - if (!SongCancelSource.IsCancellationRequested) - { - Paused = false; - SongCancelSource.Cancel(); - } - } + Paused = false; + SongCancelSource.Cancel(); } public void Stop() { - lock (playlistLock) + actionQueue.Enqueue(() => { playlist.Clear(); CurrentSong = null; @@ -132,19 +163,11 @@ namespace NadekoBot.Modules.Music.Classes RepeatSong = false; if (!SongCancelSource.IsCancellationRequested) SongCancelSource.Cancel(); - } + }); } public void TogglePause() => Paused = !Paused; - public void Shuffle() - { - lock (playlistLock) - { - playlist.Shuffle(); - } - } - public int SetVolume(int volume) { if (volume < 0) @@ -156,16 +179,15 @@ namespace NadekoBot.Modules.Music.Classes return volume; } - private Song GetNextSong() + private Song GetNextSong() => + playlist.FirstOrDefault(); + + public void Shuffle() { - lock (playlistLock) + actionQueue.Enqueue(() => { - if (playlist.Count == 0) - return null; - var toReturn = playlist[0]; - playlist.RemoveAt(0); - return toReturn; - } + playlist.Shuffle(); + }); } public void AddSong(Song s, string username) @@ -173,42 +195,63 @@ namespace NadekoBot.Modules.Music.Classes if (s == null) throw new ArgumentNullException(nameof(s)); ThrowIfQueueFull(); - lock (playlistLock) + actionQueue.Enqueue(() => { s.MusicPlayer = this; s.QueuerName = username.TrimTo(10); playlist.Add(s); - } + }); } public void AddSong(Song s, int index) { if (s == null) throw new ArgumentNullException(nameof(s)); - lock (playlistLock) + actionQueue.Enqueue(() => { playlist.Insert(index, s); - } + }); } public void RemoveSong(Song s) { if (s == null) throw new ArgumentNullException(nameof(s)); - lock (playlistLock) + actionQueue.Enqueue(() => { playlist.Remove(s); - } + }); } public void RemoveSongAt(int index) { - lock (playlistLock) + actionQueue.Enqueue(() => { if (index < 0 || index >= playlist.Count) - throw new ArgumentException("Invalid index"); + return; playlist.RemoveAt(index); - } + }); + } + + internal void ClearQueue() + { + actionQueue.Enqueue(() => + { + playlist.Clear(); + }); + } + + public void Destroy() + { + actionQueue.Enqueue(() => + { + playlist.Clear(); + Destroyed = true; + CurrentSong = null; + if (!SongCancelSource.IsCancellationRequested) + SongCancelSource.Cancel(); + audioClient.Disconnect(); + }); } internal Task MoveToVoiceChannel(Channel voiceChannel) @@ -219,27 +262,6 @@ namespace NadekoBot.Modules.Music.Classes return PlaybackVoiceChannel.JoinAudio(); } - internal void ClearQueue() - { - lock (playlistLock) - { - playlist.Clear(); - } - } - - public void Destroy() - { - lock (playlistLock) - { - playlist.Clear(); - Destroyed = true; - CurrentSong = null; - if (!SongCancelSource.IsCancellationRequested) - SongCancelSource.Cancel(); - audioClient.Disconnect(); - } - } - internal bool ToggleRepeatSong() => this.RepeatSong = !this.RepeatSong; internal bool ToggleRepeatPlaylist() => this.RepeatPlaylist = !this.RepeatPlaylist; From c6af3a6c3eccb58c5f378aa09e50ec3ac405152f Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 21 Jul 2016 12:42:17 +0200 Subject: [PATCH 06/17] more musicplayer fixes/rewrites --- .../Modules/Music/Classes/MusicControls.cs | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/NadekoBot/Modules/Music/Classes/MusicControls.cs b/NadekoBot/Modules/Music/Classes/MusicControls.cs index 2f0082ee..7cc43771 100644 --- a/NadekoBot/Modules/Music/Classes/MusicControls.cs +++ b/NadekoBot/Modules/Music/Classes/MusicControls.cs @@ -22,7 +22,6 @@ namespace NadekoBot.Modules.Music.Classes { Resolving, Queued, - Buffering, //not using it atm Playing, Completed } @@ -35,7 +34,7 @@ namespace NadekoBot.Modules.Music.Classes public IReadOnlyCollection Playlist => playlist; private readonly object playlistLock = new object(); - public Song CurrentSong { get; set; } = default(Song); + public Song CurrentSong { get; private set; } private CancellationTokenSource SongCancelSource { get; set; } private CancellationToken cancelToken { get; set; } @@ -103,20 +102,22 @@ namespace NadekoBot.Modules.Music.Classes { try { - if (audioClient.State != ConnectionState.Connected) + if (audioClient?.State != ConnectionState.Connected) { audioClient = await PlaybackVoiceChannel.JoinAudio(); continue; } - var song = CurrentSong; + CurrentSong = GetNextSong(); + RemoveSongAt(0); - if (song == null) + if (CurrentSong == null) continue; try { - await song.Play(audioClient, cancelToken); + OnStarted(this, CurrentSong); + await CurrentSong.Play(audioClient, cancelToken); } catch (OperationCanceledException) { @@ -124,17 +125,19 @@ namespace NadekoBot.Modules.Music.Classes SongCancelSource = new CancellationTokenSource(); cancelToken = SongCancelSource.Token; } - OnCompleted(this, song); + OnCompleted(this, CurrentSong); if (RepeatPlaylist) - AddSong(song, song.QueuerName); + AddSong(CurrentSong, CurrentSong.QueuerName); if (RepeatSong) - AddSong(song, 0); + AddSong(CurrentSong, 0); + } finally { await Task.Delay(300).ConfigureAwait(false); + CurrentSong = null; } } } @@ -149,18 +152,20 @@ namespace NadekoBot.Modules.Music.Classes public void Next() { - Paused = false; - SongCancelSource.Cancel(); + actionQueue.Enqueue(() => + { + Paused = false; + SongCancelSource.Cancel(); + }); } public void Stop() { actionQueue.Enqueue(() => { - playlist.Clear(); - CurrentSong = null; RepeatPlaylist = false; RepeatSong = false; + playlist.Clear(); if (!SongCancelSource.IsCancellationRequested) SongCancelSource.Cancel(); }); @@ -245,9 +250,10 @@ namespace NadekoBot.Modules.Music.Classes { actionQueue.Enqueue(() => { - playlist.Clear(); + RepeatPlaylist = false; + RepeatSong = false; Destroyed = true; - CurrentSong = null; + playlist.Clear(); if (!SongCancelSource.IsCancellationRequested) SongCancelSource.Cancel(); audioClient.Disconnect(); From a8f33e56656ba15de910cead14a0c51d59747876 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 21 Jul 2016 12:42:48 +0200 Subject: [PATCH 07/17] song queue full real fix --- NadekoBot/Modules/Games/Commands/PlantPick.cs | 1 - NadekoBot/Modules/Games/Commands/SpeedTyping.cs | 2 -- NadekoBot/Modules/Music/MusicModule.cs | 3 +-- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/NadekoBot/Modules/Games/Commands/PlantPick.cs b/NadekoBot/Modules/Games/Commands/PlantPick.cs index ec56fc3c..6af69857 100644 --- a/NadekoBot/Modules/Games/Commands/PlantPick.cs +++ b/NadekoBot/Modules/Games/Commands/PlantPick.cs @@ -102,7 +102,6 @@ namespace NadekoBot.Modules.Games.Commands var file = GetRandomCurrencyImagePath(); Message msg; - //todo send message after, not in lock if (file == null) msg = e.Channel.SendMessage(NadekoBot.Config.CurrencySign).GetAwaiter().GetResult(); else diff --git a/NadekoBot/Modules/Games/Commands/SpeedTyping.cs b/NadekoBot/Modules/Games/Commands/SpeedTyping.cs index 8a807208..c224de1d 100644 --- a/NadekoBot/Modules/Games/Commands/SpeedTyping.cs +++ b/NadekoBot/Modules/Games/Commands/SpeedTyping.cs @@ -190,8 +190,6 @@ namespace NadekoBot.Modules.Games.Commands await e.Channel.SendMessage("Added new article for typing game.").ConfigureAwait(false); }); - - //todo add user submissions } } } diff --git a/NadekoBot/Modules/Music/MusicModule.cs b/NadekoBot/Modules/Music/MusicModule.cs index 18b8966c..9148c6b9 100644 --- a/NadekoBot/Modules/Music/MusicModule.cs +++ b/NadekoBot/Modules/Music/MusicModule.cs @@ -151,7 +151,7 @@ namespace NadekoBot.Modules.Music else if (musicPlayer.RepeatPlaylist) toSend += "๐Ÿ”"; toSend += $" **{musicPlayer.Playlist.Count}** `tracks currently queued. Showing page {page}` "; - if (musicPlayer.Playlist.Count >= musicPlayer.MaxQueueSize) + if (musicPlayer.MaxQueueSize != 0 && musicPlayer.Playlist.Count >= musicPlayer.MaxQueueSize) toSend += "**Song queue is full!**\n"; else toSend += "\n"; @@ -300,7 +300,6 @@ namespace NadekoBot.Modules.Music await e.Channel.SendMessage($"๐ŸŽต `Failed to find any songs.`").ConfigureAwait(false); return; } - //todo TEMPORARY SOLUTION, USE RESOLVE QUEUE IN THE FUTURE var idArray = ids as string[] ?? ids.ToArray(); var count = idArray.Length; var msg = From f1cf11ae8e6703880f29aea277ca396b024cfbd6 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 21 Jul 2016 12:50:33 +0200 Subject: [PATCH 08/17] ~trans now correctly translates multiple sentences at once. Thanks @Myoshu --- NadekoBot/Modules/Translator/Helpers/GoogleTranslator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NadekoBot/Modules/Translator/Helpers/GoogleTranslator.cs b/NadekoBot/Modules/Translator/Helpers/GoogleTranslator.cs index 1743af45..e6abf475 100644 --- a/NadekoBot/Modules/Translator/Helpers/GoogleTranslator.cs +++ b/NadekoBot/Modules/Translator/Helpers/GoogleTranslator.cs @@ -60,7 +60,7 @@ namespace NadekoBot.Modules.Translator.Helpers text = await http.GetStringAsync(url).ConfigureAwait(false); } - return JArray.Parse(text)[0][0][0].ToString(); + return (string.Join("", JArray.Parse(text)[0].Select(x => x[0]))); } #endregion From ee415d166eee0175481a5fefc04bbff82cce1fbb Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 21 Jul 2016 12:57:57 +0200 Subject: [PATCH 09/17] string.join("" -> string.concat --- NadekoBot/Classes/Extensions.cs | 6 +++--- NadekoBot/Classes/SearchHelper.cs | 2 +- NadekoBot/Modules/Gambling/Helpers/Cards.cs | 2 +- NadekoBot/Modules/Searches/Commands/MemegenCommands.cs | 2 +- NadekoBot/Modules/Translator/Helpers/GoogleTranslator.cs | 2 +- NadekoBot/Modules/Utility/UtilityModule.cs | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/NadekoBot/Classes/Extensions.cs b/NadekoBot/Classes/Extensions.cs index 1b162209..a4071ded 100644 --- a/NadekoBot/Classes/Extensions.cs +++ b/NadekoBot/Classes/Extensions.cs @@ -46,10 +46,10 @@ namespace NadekoBot.Extensions if (num == 0) return string.Empty; if (num <= 3) - return string.Join("", str.Select(c => '.')); + return string.Concat(str.Select(c => '.')); if (str.Length < num) return str; - return string.Join("", str.Take(num - 3)) + (hideDots ? "" : "..."); + return string.Concat(str.Take(num - 3)) + (hideDots ? "" : "..."); } /// /// Removes trailing S or ES (if specified) on the given string if the num is 1 @@ -237,7 +237,7 @@ namespace NadekoBot.Extensions public static string Matrix(this string s) => - string.Join("", s.Select(c => c.ToString() + " ฬฌอ‹ฬ‰ฬœอ‰ฬžฬŽฬญฬตอฌฬ”ฬ‡ฬ–ฬŒฬฐฬขอ€".TrimTo(rng.Next(0, 12), true))); + string.Concat(s.Select(c => c.ToString() + " ฬฌอ‹ฬ‰ฬœอ‰ฬžฬŽฬญฬตอฌฬ”ฬ‡ฬ–ฬŒฬฐฬขอ€".TrimTo(rng.Next(0, 12), true))); //.Replace("`", ""); public static void ForEach(this IEnumerable source, Action action) diff --git a/NadekoBot/Classes/SearchHelper.cs b/NadekoBot/Classes/SearchHelper.cs index 77c46151..43bfbe37 100644 --- a/NadekoBot/Classes/SearchHelper.cs +++ b/NadekoBot/Classes/SearchHelper.cs @@ -384,7 +384,7 @@ namespace NadekoBot.Classes { var i = 0; return "```xl\n" + string.Join("\n", items.GroupBy(item => (i++) / cols) - .Select(ig => string.Join("", ig.Select(el => howToPrint(el))))) + .Select(ig => string.Concat(ig.Select(el => howToPrint(el))))) + $"\n```"; } } diff --git a/NadekoBot/Modules/Gambling/Helpers/Cards.cs b/NadekoBot/Modules/Gambling/Helpers/Cards.cs index 1cd4ba95..8408535e 100644 --- a/NadekoBot/Modules/Gambling/Helpers/Cards.cs +++ b/NadekoBot/Modules/Gambling/Helpers/Cards.cs @@ -146,7 +146,7 @@ namespace NadekoBot.Modules.Gambling.Helpers var orderedPool = cardPool.OrderBy(x => r.Next()); cardPool = cardPool as List ?? orderedPool.ToList(); } - public override string ToString() => string.Join("", cardPool.Select(c => c.ToString())) + Environment.NewLine; + public override string ToString() => string.Concat(cardPool.Select(c => c.ToString())) + Environment.NewLine; private static void InitHandValues() { diff --git a/NadekoBot/Modules/Searches/Commands/MemegenCommands.cs b/NadekoBot/Modules/Searches/Commands/MemegenCommands.cs index ebbdbf34..5eff7c78 100644 --- a/NadekoBot/Modules/Searches/Commands/MemegenCommands.cs +++ b/NadekoBot/Modules/Searches/Commands/MemegenCommands.cs @@ -25,7 +25,7 @@ namespace NadekoBot.Modules.Searches.Commands string.Join("\n", JsonConvert.DeserializeObject>(await SearchHelper.GetResponseStringAsync("http://memegen.link/templates/")) .Select(kvp => Path.GetFileName(kvp.Value)) .GroupBy(item => (i++) / 4) - .Select(ig => string.Join("", ig.Select(el => $"{el,-17}")))) + .Select(ig => string.Concat(ig.Select(el => $"{el,-17}")))) + $"\n```").ConfigureAwait(false); }); diff --git a/NadekoBot/Modules/Translator/Helpers/GoogleTranslator.cs b/NadekoBot/Modules/Translator/Helpers/GoogleTranslator.cs index e6abf475..b1a10a8c 100644 --- a/NadekoBot/Modules/Translator/Helpers/GoogleTranslator.cs +++ b/NadekoBot/Modules/Translator/Helpers/GoogleTranslator.cs @@ -60,7 +60,7 @@ namespace NadekoBot.Modules.Translator.Helpers text = await http.GetStringAsync(url).ConfigureAwait(false); } - return (string.Join("", JArray.Parse(text)[0].Select(x => x[0]))); + return (string.Concat(JArray.Parse(text)[0].Select(x => x[0]))); } #endregion diff --git a/NadekoBot/Modules/Utility/UtilityModule.cs b/NadekoBot/Modules/Utility/UtilityModule.cs index c85348aa..380e5acf 100644 --- a/NadekoBot/Modules/Utility/UtilityModule.cs +++ b/NadekoBot/Modules/Utility/UtilityModule.cs @@ -48,7 +48,7 @@ namespace NadekoBot.Modules.Utility if (arr.Length == 0) await e.Channel.SendMessage("Nobody. (not 100% sure)").ConfigureAwait(false); else - await e.Channel.SendMessage("```xl\n" + string.Join("\n", arr.GroupBy(item => (i++) / 3).Select(ig => string.Join("", ig.Select(el => $"• {el,-35}")))) + "\n```").ConfigureAwait(false); + await e.Channel.SendMessage("```xl\n" + string.Join("\n", arr.GroupBy(item => (i++) / 3).Select(ig => string.Concat(ig.Select(el => $"• {el,-35}")))) + "\n```").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "inrole") From d69c783f3fdb294ea542745fb7b93cbd886e4c6a Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 21 Jul 2016 13:23:22 +0200 Subject: [PATCH 10/17] `@nadeko fire` makes more sense now. --- .../Modules/Conversations/Conversations.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/NadekoBot/Modules/Conversations/Conversations.cs b/NadekoBot/Modules/Conversations/Conversations.cs index cdc6eb26..328be562 100644 --- a/NadekoBot/Modules/Conversations/Conversations.cs +++ b/NadekoBot/Modules/Conversations/Conversations.cs @@ -9,13 +9,14 @@ using System; using System.Diagnostics; using System.IO; using System.Linq; +using System.Text; using System.Threading.Tasks; namespace NadekoBot.Modules.Conversations { internal class Conversations : DiscordModule { - private const string firestr = "๐Ÿ”ฅ เธ”เน‰เน‰เน‰เน‰เน‰เน‡เน‡เน‡เน‡เน‡เน‰เน‰เน‰เน‰เน‰เน‡เน‡เน‡เน‡เน‡เน‰เน‰เน‰เน‰เน‰เน‰เน‰เน‰เน‡เน‡เน‡เน‡เน‡เน‰เน‰เน‰เน‰เน‰เน‡เน‡เธ”เน‰เน‰เน‰เน‰เน‰เน‡เน‡เน‡เน‡เน‡เน‰เน‰เน‰เน‰เน‰เน‡เน‡เน‡เน‡เน‡เน‰เน‰เน‰เน‰เน‰เน‰เน‰เน‰เน‡เน‡เน‡เน‡เน‡เน‰เน‰เน‰เน‰เน‰เน‡เน‡เน‡เน‡เน‡เน‰เน‰เน‰เน‰เน‰เน‰เน‰เน‰เน‡เน‡เน‡เธ”เน‰เน‰เน‰เน‰เน‰เน‡เน‡เน‡เน‡เน‡เน‰เน‰เน‰เน‰เน‰เน‡เน‡เน‡เน‡เน‡เน‰เน‰เน‰เน‰เน‰เน‰เน‰เน‰เน‡เน‡เน‡เน‡เน‡เน‰เน‰เน‰เน‰เน‰เน‡เน‡เน‡เน‡เน‡เน‰เน‰เน‰เน‰ ๐Ÿ”ฅ"; + private const string firestr = "๐Ÿ”ฅ เธ”เน‰เน‰เน‰เน‰เน‰เน‡เน‡เน‡เน‡เน‡เน‰เน‰เน‰เน‰เน‰เน‡เน‡เน‡เน‡เน‡เน‰เน‰เน‰เน‰เน‰เน‰เน‰เน‰เน‡เธ”เน‰เน‰เน‰เน‰เน‰เน‡เน‡เน‡เน‡เน‡เน‰เน‰เน‰เน‰เน‰เน‡เน‡เน‡เน‡เน‡เน‰เน‰เน‰เน‰เน‰เน‰เน‰เน‰เน‡เน‡เน‡เน‡เน‡เน‰เน‰เน‰เน‰เน‰เน‡เน‡เน‡เน‡เน‡เน‰เน‰เน‰เน‰เน‰เน‰เน‰เน‰เน‡เน‡เน‡เธ”เน‰เน‰เน‰เน‰เน‰เน‡เน‡เน‡เน‡เน‡เน‰เน‰เน‰เน‰เน‰เน‡เน‡เน‡เน‡เน‡เน‰เน‰เน‰เน‰เน‰เน‰เน‰เน‰เน‡เน‡เน‡เน‡เน‡เน‰เน‰เน‰เน‰เน‰เน‡เน‡เน‡เน‡เน‡เน‰เน‰เน‰เน‰ ๐Ÿ”ฅ"; public Conversations() { commands.Add(new RipCommand(this)); @@ -153,22 +154,23 @@ namespace NadekoBot.Modules.Conversations .Parameter("times", ParameterType.Optional) .Do(async e => { - var count = 1; - int.TryParse(e.Args[0], out count); - if (count == 0) + int count; + if (string.IsNullOrWhiteSpace(e.Args[0])) count = 1; + else + int.TryParse(e.Args[0], out count); if (count < 1 || count > 12) { - await e.Channel.SendMessage("Number must be between 0 and 12").ConfigureAwait(false); + await e.Channel.SendMessage("Number must be between 1 and 12").ConfigureAwait(false); return; } - var str = ""; + var str = new StringBuilder(); for (var i = 0; i < count; i++) { - str += firestr; + str.Append(firestr); } - await e.Channel.SendMessage(str).ConfigureAwait(false); + await e.Channel.SendMessage(str.ToString()).ConfigureAwait(false); }); cgb.CreateCommand("dump") From 1195a4c9c8ecee1657eb4c19a97cf54c8f035b54 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 21 Jul 2016 14:07:26 +0200 Subject: [PATCH 11/17] resetting buffer? --- NadekoBot/Modules/Music/Classes/Song.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/NadekoBot/Modules/Music/Classes/Song.cs b/NadekoBot/Modules/Music/Classes/Song.cs index e718302e..025863e0 100644 --- a/NadekoBot/Modules/Music/Classes/Song.cs +++ b/NadekoBot/Modules/Music/Classes/Song.cs @@ -31,7 +31,7 @@ namespace NadekoBot.Modules.Music.Classes public SongInfo SongInfo { get; } public string QueuerName { get; set; } - private PoopyBuffer songBuffer { get; } = new PoopyBuffer(NadekoBot.Config.BufferSize); + private PoopyBuffer songBuffer { get; set; } private bool prebufferingComplete { get; set; } = false; public MusicPlayer MusicPlayer { get; set; } @@ -137,6 +137,9 @@ namespace NadekoBot.Modules.Music.Classes internal async Task Play(IAudioClient voiceClient, CancellationToken cancelToken) { + // initialize the buffer here because if this song was playing before (requeued), we must delete old buffer data + songBuffer = new PoopyBuffer(NadekoBot.Config.BufferSize); + var bufferTask = BufferSong(cancelToken).ConfigureAwait(false); var bufferAttempts = 0; const int waitPerAttempt = 500; @@ -145,7 +148,6 @@ namespace NadekoBot.Modules.Music.Classes { await Task.Delay(waitPerAttempt, cancelToken).ConfigureAwait(false); } - cancelToken.ThrowIfCancellationRequested(); Console.WriteLine($"Prebuffering done? in {waitPerAttempt * bufferAttempts}"); const int blockSize = 3840; var attempt = 0; From dfc710cb86df58b16e6830a76288bc2c617bc632 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 21 Jul 2016 14:07:58 +0200 Subject: [PATCH 12/17] fixed "-h command name" when there is no alias --- NadekoBot/Modules/Help/Commands/HelpCommand.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/NadekoBot/Modules/Help/Commands/HelpCommand.cs b/NadekoBot/Modules/Help/Commands/HelpCommand.cs index 3bf86435..623490e4 100644 --- a/NadekoBot/Modules/Help/Commands/HelpCommand.cs +++ b/NadekoBot/Modules/Help/Commands/HelpCommand.cs @@ -24,8 +24,13 @@ namespace NadekoBot.Classes.Help.Commands var com = NadekoBot.Client.GetService().AllCommands .FirstOrDefault(c => c.Text.ToLowerInvariant().Equals(comToFind) || c.Aliases.Select(a => a.ToLowerInvariant()).Contains(comToFind)); + + var str = ""; + var alias = com.Aliases.FirstOrDefault(); + if (alias != null) + str = $" / `{ com.Aliases.FirstOrDefault()}`"; if (com != null) - await e.Channel.SendMessage($"**__Help for `{com.Text}`__ / __`{("" + com.Aliases.FirstOrDefault() + "" ?? "")}`__**\n**Desc:** {com.Description.Replace("|", "\n**Usage:**")}").ConfigureAwait(false); + await e.Channel.SendMessage($@"**__Help for:__ `{com.Text}`**" + str + $"\n**Desc:** {com.Description.Replace("|", "\n**Usage:**")}").ConfigureAwait(false); }).ConfigureAwait(false); }; public static string HelpString { From 1437f60d75f7b284c949d61bc330f28d605a41bb Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 21 Jul 2016 22:35:49 +0200 Subject: [PATCH 13/17] fixed -h for .send --- NadekoBot/Modules/Help/Commands/HelpCommand.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NadekoBot/Modules/Help/Commands/HelpCommand.cs b/NadekoBot/Modules/Help/Commands/HelpCommand.cs index 623490e4..4d3fa441 100644 --- a/NadekoBot/Modules/Help/Commands/HelpCommand.cs +++ b/NadekoBot/Modules/Help/Commands/HelpCommand.cs @@ -5,6 +5,7 @@ using NadekoBot.Modules.Permissions.Classes; using System; using System.IO; using System.Linq; +using System.Text.RegularExpressions; using System.Threading.Tasks; namespace NadekoBot.Classes.Help.Commands @@ -30,7 +31,7 @@ namespace NadekoBot.Classes.Help.Commands if (alias != null) str = $" / `{ com.Aliases.FirstOrDefault()}`"; if (com != null) - await e.Channel.SendMessage($@"**__Help for:__ `{com.Text}`**" + str + $"\n**Desc:** {com.Description.Replace("|", "\n**Usage:**")}").ConfigureAwait(false); + await e.Channel.SendMessage($@"**__Help for:__ `{com.Text}`**" + str + $"\n**Desc:** {new Regex(@"\|").Replace(com.Description, "\n**Usage:**",1)}").ConfigureAwait(false); }).ConfigureAwait(false); }; public static string HelpString { From bd2d0098e03ccbc2ecadbde7f4c78b65464104bb Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 22 Jul 2016 13:11:49 +0200 Subject: [PATCH 14/17] Print error to console when .iam throws an exception --- .../Administration/Commands/SelfAssignedRolesCommand.cs | 4 +++- NadekoBot/Modules/Music/Classes/MusicControls.cs | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs b/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs index 51bf8859..d5855eb4 100644 --- a/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs +++ b/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs @@ -1,6 +1,7 @@ ๏ปฟusing Discord.Commands; using NadekoBot.Classes; using NadekoBot.Modules.Permissions.Classes; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -144,9 +145,10 @@ namespace NadekoBot.Modules.Administration.Commands { await e.User.AddRoles(role).ConfigureAwait(false); } - catch + catch (Exception ex) { await e.Channel.SendMessage($":anger:`I am unable to add that role to you. I can't add roles to owners or other roles higher than my role in the role hierarchy.`").ConfigureAwait(false); + Console.WriteLine(ex); } var msg = await e.Channel.SendMessage($":ok:You now have {role.Name} role.").ConfigureAwait(false); await Task.Delay(3000).ConfigureAwait(false); diff --git a/NadekoBot/Modules/Music/Classes/MusicControls.cs b/NadekoBot/Modules/Music/Classes/MusicControls.cs index 7cc43771..bcd661f8 100644 --- a/NadekoBot/Modules/Music/Classes/MusicControls.cs +++ b/NadekoBot/Modules/Music/Classes/MusicControls.cs @@ -32,7 +32,6 @@ namespace NadekoBot.Modules.Music.Classes private readonly List playlist = new List(); public IReadOnlyCollection Playlist => playlist; - private readonly object playlistLock = new object(); public Song CurrentSong { get; private set; } private CancellationTokenSource SongCancelSource { get; set; } From 9a6695cc90778560103c64cd55bc826608040008 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 22 Jul 2016 13:26:05 +0200 Subject: [PATCH 15/17] changed submodule to point to my fork of discord.net --- .gitmodules | 2 +- discord.net | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 9ff1a297..1fa69c2d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "discord.net"] path = discord.net - url = git://github.com/rogueexception/discord.net.git + url = git://github.com/kwoth/discord.net.git diff --git a/discord.net b/discord.net index 6bfeaadd..3e519b5e 160000 --- a/discord.net +++ b/discord.net @@ -1 +1 @@ -Subproject commit 6bfeaaddf0cbc83fe0ca44e6164f61c6f8fdaf27 +Subproject commit 3e519b5e0b33175e5a5ca247322b7082de484e15 From 8a9f6f4e2677c97ca5b8569fe34a36f017ab4d1e Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 22 Jul 2016 13:41:41 +0200 Subject: [PATCH 16/17] .send is now correctly splitting on "|", not "-" (fixed .send) --- NadekoBot/Modules/Administration/AdministrationModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NadekoBot/Modules/Administration/AdministrationModule.cs b/NadekoBot/Modules/Administration/AdministrationModule.cs index cff95af4..ab6dafae 100644 --- a/NadekoBot/Modules/Administration/AdministrationModule.cs +++ b/NadekoBot/Modules/Administration/AdministrationModule.cs @@ -738,7 +738,7 @@ namespace NadekoBot.Modules.Administration if (string.IsNullOrWhiteSpace(msg)) return; - var ids = e.GetArg("ids").Split('-'); + var ids = e.GetArg("ids").Split('|'); if (ids.Length != 2) return; var sid = ulong.Parse(ids[0]); From 68a66e281e367b3e0fa1ca67140935e96f3a1b11 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 22 Jul 2016 15:17:19 +0200 Subject: [PATCH 17/17] fixed error message when doing `.iam`, thanks PeaceLord<3 for debugging --- .../Administration/Commands/SelfAssignedRolesCommand.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs b/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs index d5855eb4..2ef54772 100644 --- a/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs +++ b/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs @@ -1,4 +1,5 @@ ๏ปฟusing Discord.Commands; +using Discord.Net; using NadekoBot.Classes; using NadekoBot.Modules.Permissions.Classes; using System; @@ -145,10 +146,12 @@ namespace NadekoBot.Modules.Administration.Commands { await e.User.AddRoles(role).ConfigureAwait(false); } - catch (Exception ex) + catch(HttpException ex) when (ex.StatusCode == System.Net.HttpStatusCode.InternalServerError) + { + } + catch (Exception) { await e.Channel.SendMessage($":anger:`I am unable to add that role to you. I can't add roles to owners or other roles higher than my role in the role hierarchy.`").ConfigureAwait(false); - Console.WriteLine(ex); } var msg = await e.Channel.SendMessage($":ok:You now have {role.Name} role.").ConfigureAwait(false); await Task.Delay(3000).ConfigureAwait(false);