Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better error messages when .q user N finds <N quotes for user #506

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Izzy-Moonbot/Modules/QuotesModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
8 changes: 8 additions & 0 deletions Izzy-Moonbot/Service/QuoteService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion Izzy-MoonbotTests/Tests/QuoteModuleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

//

Expand Down
Loading