diff --git a/Izzy-Moonbot/Modules/QuotesModule.cs b/Izzy-Moonbot/Modules/QuotesModule.cs index e53511e1..dd2b0809 100644 --- a/Izzy-Moonbot/Modules/QuotesModule.cs +++ b/Izzy-Moonbot/Modules/QuotesModule.cs @@ -137,6 +137,18 @@ public async Task TestableQuoteCommandAsync( return; } + var quoteCount = _quoteService.GetQuoteCount((ulong)userId); + if (quoteCount is null) + { + await context.Channel.SendMessageAsync($"<@{userId}> doesn't have any quotes", allowedMentions: AllowedMentions.None); + return; + } + if (number.Value > quoteCount) + { + await context.Channel.SendMessageAsync($"<@{userId}> only has {quoteCount} quote(s)", allowedMentions: AllowedMentions.None); + return; + } + var quote = _quoteService.GetQuote((ulong)userId, number.Value - 1); if (quote == null) { diff --git a/Izzy-Moonbot/Service/QuoteService.cs b/Izzy-Moonbot/Service/QuoteService.cs index 819c1c18..a1ba39d1 100644 --- a/Izzy-Moonbot/Service/QuoteService.cs +++ b/Izzy-Moonbot/Service/QuoteService.cs @@ -94,6 +94,14 @@ public string[] GetKeyList(IIzzyGuild guild) }).ToArray(); } + public int? GetQuoteCount(ulong userId) + { + if (!_quoteStorage.Quotes.TryGetValue(userId.ToString(), out var quotes)) + return null; + + return quotes.Count; + } + public string? GetQuote(ulong userId, int index) { if (!_quoteStorage.Quotes.TryGetValue(userId.ToString(), out var quotes)) diff --git a/Izzy-MoonbotTests/Tests/QuoteModuleTests.cs b/Izzy-MoonbotTests/Tests/QuoteModuleTests.cs index 36d9570d..1e8f9f83 100644 --- a/Izzy-MoonbotTests/Tests/QuoteModuleTests.cs +++ b/Izzy-MoonbotTests/Tests/QuoteModuleTests.cs @@ -53,7 +53,7 @@ public async Task QuoteCommand_Tests() context = await client.AddMessageAsync(guild.Id, generalChannel.Id, sunny.Id, $".quote <@{sunny.Id}> 2"); await qm.TestableQuoteCommandAsync(context, $"<@{sunny.Id}> 2"); - Assert.AreEqual("I couldn't find that quote, sorry!", generalChannel.Messages.Last().Content); + Assert.AreEqual($"<@{sunny.Id}> only has 1 quote(s)", generalChannel.Messages.Last().Content); //