diff --git a/NadekoBot/Classes/Music/MusicControls.cs b/NadekoBot/Classes/Music/MusicControls.cs index 82465037..cf24af88 100644 --- a/NadekoBot/Classes/Music/MusicControls.cs +++ b/NadekoBot/Classes/Music/MusicControls.cs @@ -59,7 +59,8 @@ namespace NadekoBot.Classes.Music { Task.Run(async () => { while (!Destroyed) { try { - audioClient = await PlaybackVoiceChannel.JoinAudio(); + if(audioClient?.State != ConnectionState.Connected) + audioClient = await PlaybackVoiceChannel.JoinAudio(); } catch { await Task.Delay(1000); continue; @@ -171,6 +172,7 @@ namespace NadekoBot.Classes.Music { lock (playlistLock) { playlist.Clear(); Destroyed = true; + CurrentSong = null; if (!SongCancelSource.IsCancellationRequested) SongCancelSource.Cancel(); audioClient.Disconnect(); diff --git a/NadekoBot/Commands/DrawCommand.cs b/NadekoBot/Commands/DrawCommand.cs index ce132614..79db38fc 100644 --- a/NadekoBot/Commands/DrawCommand.cs +++ b/NadekoBot/Commands/DrawCommand.cs @@ -8,21 +8,13 @@ using NadekoBot.Extensions; namespace NadekoBot.Commands { internal class DrawCommand : IDiscordCommand { - private static ConcurrentDictionary AllDecks = new ConcurrentDictionary(); - - public DrawCommand() { - - } + private static readonly ConcurrentDictionary AllDecks = new ConcurrentDictionary(); public Func DoFunc() => async (e) => { - if (!AllDecks.ContainsKey(e.Server)) { - await e.Channel.SendMessage("Shuffling cards..."); - AllDecks.TryAdd(e.Server, new Cards()); - } + var cards = AllDecks.GetOrAdd(e.Server, (s) => new Cards()); try { - var cards = AllDecks[e.Server]; - int num = 1; + var num = 1; var isParsed = int.TryParse(e.GetArg("count"), out num); if (!isParsed || num < 2) { var c = cards.DrawACard(); @@ -32,9 +24,9 @@ namespace NadekoBot.Commands { if (num > 5) num = 5; - List images = new List(); - List cardObjects = new List(); - for (int i = 0; i < num; i++) { + var images = new List(); + var cardObjects = new List(); + for (var i = 0; i < num; i++) { if (cards.CardPool.Count == 0 && i != 0) { await e.Channel.SendMessage("No more cards in a deck."); break; @@ -43,7 +35,7 @@ namespace NadekoBot.Commands { cardObjects.Add(currentCard); images.Add(Properties.Resources.ResourceManager.GetObject(currentCard.Name) as Image); } - Bitmap bitmap = images.Merge(); + var bitmap = images.Merge(); await e.Channel.SendFile(images.Count + " cards.jpg", bitmap.ToStream()); if (cardObjects.Count == 5) { await e.Channel.SendMessage(Cards.GetHandValue(cardObjects)); @@ -63,9 +55,13 @@ namespace NadekoBot.Commands { .Alias("$reshuffle") .Description("Reshuffles all cards back into the deck.") .Do(async e => { - if (!AllDecks.ContainsKey(e.Server)) - AllDecks.TryAdd(e.Server, new Cards()); - AllDecks[e.Server].Restart(); + AllDecks.AddOrUpdate(e.Server, + (s) => new Cards(), + (s, c) => { + c.Restart(); + return c; + }); + await e.Channel.SendMessage("Deck reshuffled."); }); } diff --git a/NadekoBot/Modules/Games.cs b/NadekoBot/Modules/Games.cs index fb1377cb..913b3a84 100644 --- a/NadekoBot/Modules/Games.cs +++ b/NadekoBot/Modules/Games.cs @@ -11,7 +11,7 @@ using NadekoBot.Extensions; namespace NadekoBot.Modules { internal class Games : DiscordModule { private readonly string[] _8BallAnswers; - private Random rng = new Random(); + private readonly Random rng = new Random(); public Games() { commands.Add(new Trivia()); @@ -53,7 +53,7 @@ namespace NadekoBot.Modules { return; try { await e.Channel.SendMessage( - $":question: **Question**: `{question}` \n:crystal_ball: **8Ball Answers**: `{_8BallAnswers[rng.Next(0, _8BallAnswers.Length)]}`"); + $":question: **Question**: `{question}` \n🎱 **8Ball Answers**: `{_8BallAnswers[rng.Next(0, _8BallAnswers.Length)]}`"); } catch { } }); @@ -63,6 +63,10 @@ namespace NadekoBot.Modules { .Parameter("target", Discord.Commands.ParameterType.Required) .Do(async e => { var usr = e.Server.FindUsers(e.GetArg("target")).FirstOrDefault(); + if (usr == null) { + await e.Channel.SendMessage("No such person."); + return; + } var usrType = GetType(usr.Id); var response = ""; var dmg = GetDamage(usrType, e.GetArg("attack_type").ToLowerInvariant()); diff --git a/NadekoBot/NadekoBot.cs b/NadekoBot/NadekoBot.cs index 5b199cfd..3e4f5a20 100644 --- a/NadekoBot/NadekoBot.cs +++ b/NadekoBot/NadekoBot.cs @@ -67,7 +67,7 @@ namespace NadekoBot { //create new discord client and log Client = new DiscordClient(new DiscordConfigBuilder() { - MessageCacheSize = 20, + MessageCacheSize = 10, LogLevel = LogSeverity.Warning, LogHandler = (s, e) => Console.WriteLine($"Severity: {e.Severity}" +