diff --git a/src/NadekoBot/Modules/Games/Commands/SpeedTypingCommands.cs b/src/NadekoBot/Modules/Games/Commands/SpeedTypingCommands.cs index 47724820..96866f0e 100644 --- a/src/NadekoBot/Modules/Games/Commands/SpeedTypingCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/SpeedTypingCommands.cs @@ -116,7 +116,7 @@ namespace NadekoBot.Modules.Games if (msg == null) return; - if (this.Channel == null || this.Channel.Id != this.Channel.Id) return; + if (this.Channel == null || this.Channel.Id != msg.Channel.Id) return; var guess = msg.Content; @@ -127,10 +127,10 @@ namespace NadekoBot.Modules.Games var wpm = CurrentSentence.Length / WORD_VALUE / sw.Elapsed.Seconds * 60; finishedUserIds.Add(msg.Author.Id); await this.Channel.EmbedAsync(new EmbedBuilder().WithOkColor() - .WithTitle((string)$"{msg.Author} finished the race!") + .WithTitle($"{msg.Author} finished the race!") .AddField(efb => efb.WithName("Place").WithValue($"#{finishedUserIds.Count}").WithIsInline(true)) - .AddField(efb => efb.WithName("WPM").WithValue($"{wpm:F2} *[{sw.Elapsed.Seconds.ToString()}sec]*").WithIsInline(true)) - .AddField(efb => efb.WithName((string)"Errors").WithValue((string)distance.ToString()).WithIsInline((bool)true))) + .AddField(efb => efb.WithName("WPM").WithValue($"{wpm:F2} *[{sw.Elapsed.TotalSeconds:F2}sec]*").WithIsInline(true)) + .AddField(efb => efb.WithName("Errors").WithValue(distance.ToString()).WithIsInline(true))) .ConfigureAwait(false); if (finishedUserIds.Count % 4 == 0) { @@ -150,11 +150,11 @@ namespace NadekoBot.Modules.Games { public static List TypingArticles { get; } = new List(); - const string typingArticlesPath = "data/typing_articles.json"; + private const string _typingArticlesPath = "data/typing_articles.json"; static SpeedTypingCommands() { - try { TypingArticles = JsonConvert.DeserializeObject>(File.ReadAllText(typingArticlesPath)); } catch { } + try { TypingArticles = JsonConvert.DeserializeObject>(File.ReadAllText(_typingArticlesPath)); } catch { } } public static ConcurrentDictionary RunningContests = new ConcurrentDictionary(); @@ -207,7 +207,7 @@ namespace NadekoBot.Modules.Games Text = text.SanitizeMentions(), }); - File.WriteAllText(typingArticlesPath, JsonConvert.SerializeObject(TypingArticles)); + File.WriteAllText(_typingArticlesPath, JsonConvert.SerializeObject(TypingArticles)); await channel.SendConfirmAsync("Added new article for typing game.").ConfigureAwait(false); } @@ -221,7 +221,7 @@ namespace NadekoBot.Modules.Games if (page < 1) return; - var articles = TypingArticles.Skip((page - 1) * 15).Take(15); + var articles = TypingArticles.Skip((page - 1) * 15).Take(15).ToArray(); if (!articles.Any()) { @@ -229,7 +229,7 @@ namespace NadekoBot.Modules.Games return; } var i = (page - 1) * 15; - await channel.SendConfirmAsync("List of articles for Type Race", String.Join("\n", articles.Select(a => $"`#{++i}` - {a.Text.TrimTo(50)}"))) + await channel.SendConfirmAsync("List of articles for Type Race", string.Join("\n", articles.Select(a => $"`#{++i}` - {a.Text.TrimTo(50)}"))) .ConfigureAwait(false); } @@ -247,7 +247,7 @@ namespace NadekoBot.Modules.Games var removed = TypingArticles[index]; TypingArticles.RemoveAt(index); - File.WriteAllText(typingArticlesPath, JsonConvert.SerializeObject(TypingArticles)); + File.WriteAllText(_typingArticlesPath, JsonConvert.SerializeObject(TypingArticles)); await channel.SendConfirmAsync($"`Removed typing article:` #{index + 1} - {removed.Text.TrimTo(50)}") .ConfigureAwait(false); diff --git a/src/NadekoBot/Modules/Music/Classes/MusicControls.cs b/src/NadekoBot/Modules/Music/Classes/MusicControls.cs index e11b680e..a1b0d0a9 100644 --- a/src/NadekoBot/Modules/Music/Classes/MusicControls.cs +++ b/src/NadekoBot/Modules/Music/Classes/MusicControls.cs @@ -67,7 +67,7 @@ namespace NadekoBot.Modules.Music.Classes public float Volume { get; private set; } public event Action OnCompleted = delegate { }; - public event Action OnStarted = delegate { }; + public event Action OnStarted = delegate { }; public event Action OnPauseChanged = delegate { }; public IVoiceChannel PlaybackVoiceChannel { get; private set; } @@ -130,13 +130,9 @@ namespace NadekoBot.Modules.Music.Classes { try { - if (audioClient?.ConnectionState != ConnectionState.Connected) - { - if (audioClient != null) - try { await audioClient.DisconnectAsync().ConfigureAwait(false); } catch { } - audioClient = await PlaybackVoiceChannel.ConnectAsync().ConfigureAwait(false); - continue; - } + if (audioClient != null) + try { await audioClient.DisconnectAsync().ConfigureAwait(false); } catch { } + audioClient = await PlaybackVoiceChannel.ConnectAsync().ConfigureAwait(false); CurrentSong = GetNextSong(); @@ -313,11 +309,15 @@ namespace NadekoBot.Modules.Music.Classes { var curSong = CurrentSong; var toUpdate = playlist.Where(s => s.SongInfo.ProviderType == MusicType.Normal && - s.TotalTime == TimeSpan.Zero); + s.TotalTime == TimeSpan.Zero) + .ToArray(); if (curSong != null) - toUpdate = toUpdate.Append(curSong); + { + Array.Resize(ref toUpdate, toUpdate.Length + 1); + toUpdate[toUpdate.Length - 1] = curSong; + } var ids = toUpdate.Select(s => s.SongInfo.Query.Substring(s.SongInfo.Query.LastIndexOf("?v=") + 3)) - .Distinct(); + .Distinct(); var durations = await NadekoBot.Google.GetVideoDurationsAsync(ids); diff --git a/src/NadekoBot/NadekoBot.xproj.DotSettings b/src/NadekoBot/NadekoBot.xproj.DotSettings index 3a1cb1b5..65ccbd58 100644 --- a/src/NadekoBot/NadekoBot.xproj.DotSettings +++ b/src/NadekoBot/NadekoBot.xproj.DotSettings @@ -1,3 +1,4 @@  True - True \ No newline at end of file + True + True \ No newline at end of file