From 725d844131c4c68c31734454eeacba5e3be36011 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 5 Jan 2017 19:13:53 +0100 Subject: [PATCH 1/6] .rrc reduced to a minimum of 60 seconds. b1nzy wasn't happy about this --- src/NadekoBot/Modules/Utility/Utility.cs | 2 +- src/NadekoBot/Resources/CommandStrings.Designer.cs | 4 ++-- src/NadekoBot/Resources/CommandStrings.resx | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index 3abf4e04..eb7c7404 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -28,7 +28,7 @@ namespace NadekoBot.Modules.Utility { var channel = (ITextChannel)Context.Channel; - if (timeout < 0 || timeout > 3600) + if ((timeout < 60 && timeout != 0) || timeout > 3600) return; Timer t; diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index 17754f51..950eeaad 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -6063,7 +6063,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to Rotates a roles color on an interval with a list of supplied colors. First argument is interval in seconds. Second argument is a role, followed by a space-separated list of colors in hex. Provide a rolename with a 0 interval to disable.. + /// Looks up a localized string similar to Rotates a roles color on an interval with a list of supplied colors. First argument is interval in seconds (Minimum 60). Second argument is a role, followed by a space-separated list of colors in hex. Provide a rolename with a 0 interval to disable.. /// public static string rotaterolecolor_desc { get { @@ -6072,7 +6072,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to `{0}rrc 1 MyLsdRole #ff0000 #00ff00 #0000ff` or `{0}rrc 0 MyLsdRole`. + /// Looks up a localized string similar to `{0}rrc 60 MyLsdRole #ff0000 #00ff00 #0000ff` or `{0}rrc 0 MyLsdRole`. /// public static string rotaterolecolor_usage { get { diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index c6e2bd15..c540455d 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -2866,9 +2866,9 @@ rotaterolecolor rrc - Rotates a roles color on an interval with a list of supplied colors. First argument is interval in seconds. Second argument is a role, followed by a space-separated list of colors in hex. Provide a rolename with a 0 interval to disable. + Rotates a roles color on an interval with a list of supplied colors. First argument is interval in seconds (Minimum 60). Second argument is a role, followed by a space-separated list of colors in hex. Provide a rolename with a 0 interval to disable. - `{0}rrc 1 MyLsdRole #ff0000 #00ff00 #0000ff` or `{0}rrc 0 MyLsdRole` + `{0}rrc 60 MyLsdRole #ff0000 #00ff00 #0000ff` or `{0}rrc 0 MyLsdRole` \ No newline at end of file From 2d1cfad07f8edf09d3e097d2ad113d411ce23bb1 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 5 Jan 2017 21:44:31 +0100 Subject: [PATCH 2/6] Error logging --- .../Modules/Music/Classes/MusicControls.cs | 4 ++++ .../Modules/Music/Classes/SongHandler.cs | 19 ++++++++++++------- src/NadekoBot/Modules/Music/Music.cs | 5 +++-- src/NadekoBot/ShardedDiscordClient.cs | 3 ++- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/NadekoBot/Modules/Music/Classes/MusicControls.cs b/src/NadekoBot/Modules/Music/Classes/MusicControls.cs index be726c84..257b319f 100644 --- a/src/NadekoBot/Modules/Music/Classes/MusicControls.cs +++ b/src/NadekoBot/Modules/Music/Classes/MusicControls.cs @@ -152,6 +152,10 @@ namespace NadekoBot.Modules.Music.Classes } catch (OperationCanceledException) { } + catch (TimeoutException) { + Console.WriteLine("Bot couldn't connect to the channel. Most likely insufficient permissions. Fix permissions, then queue songs again"); + ClearQueue(); + } catch (Exception ex) { Console.WriteLine("Music thread almost crashed."); diff --git a/src/NadekoBot/Modules/Music/Classes/SongHandler.cs b/src/NadekoBot/Modules/Music/Classes/SongHandler.cs index 7892e278..496de92c 100644 --- a/src/NadekoBot/Modules/Music/Classes/SongHandler.cs +++ b/src/NadekoBot/Modules/Music/Classes/SongHandler.cs @@ -76,16 +76,21 @@ namespace NadekoBot.Modules.Music.Classes }) { TotalTime = TimeSpan.FromMilliseconds(svideo.Duration) }; } - + Console.WriteLine("Getting video id"); var link = (await NadekoBot.Google.GetVideosByKeywordsAsync(query).ConfigureAwait(false)).FirstOrDefault(); + Console.WriteLine("Done getting video id"); if (string.IsNullOrWhiteSpace(link)) throw new OperationCanceledException("Not a valid youtube query."); - var allVideos = await Task.Run(async () => { try { return await YouTube.Default.GetAllVideosAsync(link).ConfigureAwait(false); } catch { return Enumerable.Empty(); } }).ConfigureAwait(false); - var videos = allVideos.Where(v => v.AdaptiveKind == AdaptiveKind.Audio); - var video = videos - .Where(v => v.AudioBitrate < 256) - .OrderByDescending(v => v.AudioBitrate) - .FirstOrDefault(); + //var allVideos = await Task.Run(async () => { try { return await YouTube.Default.GetVideoAsync(link).ConfigureAwait(false); } catch { return Enumerable.Empty(); } }).ConfigureAwait(false); + //var videos = allVideos.Where(v => v.AdaptiveKind == AdaptiveKind.Audio); + //var video = videos + // .Where(v => v.AudioBitrate < 256) + // .OrderByDescending(v => v.AudioBitrate) + // .FirstOrDefault(); + + Console.WriteLine("Getting video itself"); + var video = await YouTube.Default.GetVideoAsync(link).ConfigureAwait(false); + Console.WriteLine("Done getting video"); if (video == null) // do something with this error throw new Exception("Could not load any video elements based on the query."); diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index 9751c938..a3b15204 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -325,7 +325,7 @@ $"{("tracks".SnPl(musicPlayer.Playlist.Count))} | {(int)total.TotalHours}h {tota while (ids.Any() && !cancelSource.IsCancellationRequested) { - var tasks = Task.WhenAll(ids.Take(5).Select(async id => + var tasks = Task.WhenAll(ids.Take(3).Select(async id => { if (cancelSource.Token.IsCancellationRequested) return; @@ -874,8 +874,9 @@ $"{("tracks".SnPl(musicPlayer.Playlist.Count))} | {(int)total.TotalHours}h {tota try { musicPlayer.ThrowIfQueueFull(); + Console.WriteLine("Resolving"); resolvedSong = await SongHandler.ResolveSong(query, musicType).ConfigureAwait(false); - + Console.WriteLine("Resolved"); if (resolvedSong == null) throw new SongNotFoundException(); diff --git a/src/NadekoBot/ShardedDiscordClient.cs b/src/NadekoBot/ShardedDiscordClient.cs index 259fe88f..c2300bd0 100644 --- a/src/NadekoBot/ShardedDiscordClient.cs +++ b/src/NadekoBot/ShardedDiscordClient.cs @@ -80,7 +80,8 @@ namespace NadekoBot private Task Client_Log(LogMessage arg) { - _log.Warn(arg.Exception, arg.Message); + _log.Warn(arg.Message); + _log.Error(arg.Exception); return Task.CompletedTask; } From 3e693ea2301ade5883ceafbaefc579151f99dd5a Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 5 Jan 2017 21:45:40 +0100 Subject: [PATCH 3/6] Revert "Error logging" This reverts commit 2d1cfad07f8edf09d3e097d2ad113d411ce23bb1. --- .../Modules/Music/Classes/MusicControls.cs | 4 ---- .../Modules/Music/Classes/SongHandler.cs | 19 +++++++------------ src/NadekoBot/Modules/Music/Music.cs | 5 ++--- src/NadekoBot/ShardedDiscordClient.cs | 3 +-- 4 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/NadekoBot/Modules/Music/Classes/MusicControls.cs b/src/NadekoBot/Modules/Music/Classes/MusicControls.cs index 257b319f..be726c84 100644 --- a/src/NadekoBot/Modules/Music/Classes/MusicControls.cs +++ b/src/NadekoBot/Modules/Music/Classes/MusicControls.cs @@ -152,10 +152,6 @@ namespace NadekoBot.Modules.Music.Classes } catch (OperationCanceledException) { } - catch (TimeoutException) { - Console.WriteLine("Bot couldn't connect to the channel. Most likely insufficient permissions. Fix permissions, then queue songs again"); - ClearQueue(); - } catch (Exception ex) { Console.WriteLine("Music thread almost crashed."); diff --git a/src/NadekoBot/Modules/Music/Classes/SongHandler.cs b/src/NadekoBot/Modules/Music/Classes/SongHandler.cs index 496de92c..7892e278 100644 --- a/src/NadekoBot/Modules/Music/Classes/SongHandler.cs +++ b/src/NadekoBot/Modules/Music/Classes/SongHandler.cs @@ -76,21 +76,16 @@ namespace NadekoBot.Modules.Music.Classes }) { TotalTime = TimeSpan.FromMilliseconds(svideo.Duration) }; } - Console.WriteLine("Getting video id"); + var link = (await NadekoBot.Google.GetVideosByKeywordsAsync(query).ConfigureAwait(false)).FirstOrDefault(); - Console.WriteLine("Done getting video id"); if (string.IsNullOrWhiteSpace(link)) throw new OperationCanceledException("Not a valid youtube query."); - //var allVideos = await Task.Run(async () => { try { return await YouTube.Default.GetVideoAsync(link).ConfigureAwait(false); } catch { return Enumerable.Empty(); } }).ConfigureAwait(false); - //var videos = allVideos.Where(v => v.AdaptiveKind == AdaptiveKind.Audio); - //var video = videos - // .Where(v => v.AudioBitrate < 256) - // .OrderByDescending(v => v.AudioBitrate) - // .FirstOrDefault(); - - Console.WriteLine("Getting video itself"); - var video = await YouTube.Default.GetVideoAsync(link).ConfigureAwait(false); - Console.WriteLine("Done getting video"); + var allVideos = await Task.Run(async () => { try { return await YouTube.Default.GetAllVideosAsync(link).ConfigureAwait(false); } catch { return Enumerable.Empty(); } }).ConfigureAwait(false); + var videos = allVideos.Where(v => v.AdaptiveKind == AdaptiveKind.Audio); + var video = videos + .Where(v => v.AudioBitrate < 256) + .OrderByDescending(v => v.AudioBitrate) + .FirstOrDefault(); if (video == null) // do something with this error throw new Exception("Could not load any video elements based on the query."); diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index a3b15204..9751c938 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -325,7 +325,7 @@ $"{("tracks".SnPl(musicPlayer.Playlist.Count))} | {(int)total.TotalHours}h {tota while (ids.Any() && !cancelSource.IsCancellationRequested) { - var tasks = Task.WhenAll(ids.Take(3).Select(async id => + var tasks = Task.WhenAll(ids.Take(5).Select(async id => { if (cancelSource.Token.IsCancellationRequested) return; @@ -874,9 +874,8 @@ $"{("tracks".SnPl(musicPlayer.Playlist.Count))} | {(int)total.TotalHours}h {tota try { musicPlayer.ThrowIfQueueFull(); - Console.WriteLine("Resolving"); resolvedSong = await SongHandler.ResolveSong(query, musicType).ConfigureAwait(false); - Console.WriteLine("Resolved"); + if (resolvedSong == null) throw new SongNotFoundException(); diff --git a/src/NadekoBot/ShardedDiscordClient.cs b/src/NadekoBot/ShardedDiscordClient.cs index c2300bd0..259fe88f 100644 --- a/src/NadekoBot/ShardedDiscordClient.cs +++ b/src/NadekoBot/ShardedDiscordClient.cs @@ -80,8 +80,7 @@ namespace NadekoBot private Task Client_Log(LogMessage arg) { - _log.Warn(arg.Message); - _log.Error(arg.Exception); + _log.Warn(arg.Exception, arg.Message); return Task.CompletedTask; } From 517bfc2294e49fbb128c01723374901964247416 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 5 Jan 2017 21:49:32 +0100 Subject: [PATCH 4/6] logging+ --- src/NadekoBot/ShardedDiscordClient.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/NadekoBot/ShardedDiscordClient.cs b/src/NadekoBot/ShardedDiscordClient.cs index 259fe88f..c2300bd0 100644 --- a/src/NadekoBot/ShardedDiscordClient.cs +++ b/src/NadekoBot/ShardedDiscordClient.cs @@ -80,7 +80,8 @@ namespace NadekoBot private Task Client_Log(LogMessage arg) { - _log.Warn(arg.Exception, arg.Message); + _log.Warn(arg.Message); + _log.Error(arg.Exception); return Task.CompletedTask; } From 871089bf26846dba07589f250806ec4d5f74cb28 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 5 Jan 2017 21:54:49 +0100 Subject: [PATCH 5/6] Fixed !!rm spam? --- .../Modules/Music/Classes/MusicControls.cs | 4 +-- src/NadekoBot/Modules/Music/Music.cs | 33 ++++++++++--------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/NadekoBot/Modules/Music/Classes/MusicControls.cs b/src/NadekoBot/Modules/Music/Classes/MusicControls.cs index be726c84..1e822f0a 100644 --- a/src/NadekoBot/Modules/Music/Classes/MusicControls.cs +++ b/src/NadekoBot/Modules/Music/Classes/MusicControls.cs @@ -77,7 +77,7 @@ namespace NadekoBot.Modules.Music.Classes public string PrettyVolume => $"🔉 {(int)(Volume * 100)}%"; - public event Action SongRemoved = delegate { }; + public event Action SongRemoved = delegate { }; public MusicPlayer(IVoiceChannel startingVoiceChannel, float? defaultVolume) { @@ -282,7 +282,7 @@ namespace NadekoBot.Modules.Music.Classes var song = playlist.ElementAtOrDefault(index); if (playlist.Remove(song) && !silent) { - SongRemoved(song); + SongRemoved(song, index); } }); diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index 9751c938..165ed935 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -466,22 +466,6 @@ $"{("tracks".SnPl(musicPlayer.Playlist.Count))} | {(int)total.TotalHours}h {tota if (((IGuildUser)Context.User).VoiceChannel != musicPlayer.PlaybackVoiceChannel) return; - musicPlayer.SongRemoved += async (song) => - { - try - { - var embed = new EmbedBuilder() - .WithAuthor(eab => eab.WithName("Removed song #" + num).WithMusicIcon()) - .WithDescription(song.PrettyName) - .WithFooter(ef => ef.WithText(song.PrettyInfo)) - .WithErrorColor(); - - await Context.Channel.EmbedAsync(embed).ConfigureAwait(false); - - } - catch { } - }; - musicPlayer.RemoveSongAt(num - 1); } @@ -868,6 +852,23 @@ $"{("tracks".SnPl(musicPlayer.Playlist.Count))} | {(int)total.TotalHours}h {tota } catch { } }; + + + mp.SongRemoved += async (song, index) => + { + try + { + var embed = new EmbedBuilder() + .WithAuthor(eab => eab.WithName("Removed song #" + (index + 1)).WithMusicIcon()) + .WithDescription(song.PrettyName) + .WithFooter(ef => ef.WithText(song.PrettyInfo)) + .WithErrorColor(); + + await textCh.EmbedAsync(embed).ConfigureAwait(false); + + } + catch { } + }; return mp; }); Song resolvedSong; From 22bad86d379c5761ce6e45c09d44e0138b423aeb Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 5 Jan 2017 21:58:11 +0100 Subject: [PATCH 6/6] Fixed music WARNINGS, not ERRORS - WARNINGS --- src/NadekoBot/Modules/Music/Music.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index 165ed935..536a00ae 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -99,16 +99,16 @@ namespace NadekoBot.Modules.Music [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] - public async Task Destroy() + public Task Destroy() { - //await Context.Channel.SendErrorAsync("This command is temporarily disabled.").ConfigureAwait(false); - MusicPlayer musicPlayer; - if (!MusicPlayers.TryGetValue(Context.Guild.Id, out musicPlayer)) return; + if (!MusicPlayers.TryGetValue(Context.Guild.Id, out musicPlayer)) return Task.CompletedTask; if (((IGuildUser)Context.User).VoiceChannel == musicPlayer.PlaybackVoiceChannel) if (MusicPlayers.TryRemove(Context.Guild.Id, out musicPlayer)) musicPlayer.Destroy(); + return Task.CompletedTask; + } [NadekoCommand, Usage, Description, Aliases] @@ -458,15 +458,16 @@ $"{("tracks".SnPl(musicPlayer.Playlist.Count))} | {(int)total.TotalHours}h {tota [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] [Priority(0)] - public async Task Remove(int num) + public Task Remove(int num) { MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(Context.Guild.Id, out musicPlayer)) - return; + return Task.CompletedTask; if (((IGuildUser)Context.User).VoiceChannel != musicPlayer.PlaybackVoiceChannel) - return; + return Task.CompletedTask; musicPlayer.RemoveSongAt(num - 1); + return Task.CompletedTask; } [NadekoCommand, Usage, Description, Aliases] @@ -474,8 +475,6 @@ $"{("tracks".SnPl(musicPlayer.Playlist.Count))} | {(int)total.TotalHours}h {tota [Priority(1)] public async Task Remove(string all) { - - if (all.Trim().ToUpperInvariant() != "ALL") return; MusicPlayer musicPlayer;