From b76a5cc6f5f42c7c2e20c0249d5f531c338977da Mon Sep 17 00:00:00 2001 From: Macintosh II <95250141+mctaylors@users.noreply.github.com> Date: Mon, 2 Oct 2023 10:47:23 +0300 Subject: [PATCH] Auto-detect max & min numbers Signed-off-by: Macintosh II <95250141+mctaylors@users.noreply.github.com> --- src/Commands/ToolsCommandGroup.cs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/Commands/ToolsCommandGroup.cs b/src/Commands/ToolsCommandGroup.cs index d75c3fe..f1cc3b8 100644 --- a/src/Commands/ToolsCommandGroup.cs +++ b/src/Commands/ToolsCommandGroup.cs @@ -232,8 +232,8 @@ public class ToolsCommandGroup : CommandGroup /// /// A slash command that generates a random number using maximum and minimum numbers. /// - /// The maximum number for randomization. - /// The minimum number for randomization. Default value: 1 + /// The first number used for randomization. + /// The second number used for randomization. Default value: 1 /// /// A feedback sending result which may or may not have succeeded. /// @@ -242,9 +242,9 @@ public class ToolsCommandGroup : CommandGroup [Description("Generates a random number")] [UsedImplicitly] public async Task ExecuteRandomAsync( - [Description("Maximum number")] int max, - [Description("Minumum number (Default: 0)")] - int min = 0) + [Description("First number")] int first, + [Description("Second number (Default: 0)")] + int second = 0) { if (!_context.TryGetContextIDs(out var guildId, out _, out var userId)) { @@ -271,14 +271,8 @@ public class ToolsCommandGroup : CommandGroup private async Task SendRandomNumberAsync(int max, int min, IUser user, IUser currentUser, CancellationToken ct) { - if (min > max) - { - var failedEmbed = new EmbedBuilder().WithSmallTitle( - Messages.RandomMinGreaterThanMax, currentUser) - .WithColour(ColorsList.Red).Build(); - - return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct); - } + var max = Math.Max(first, second); + var min = Math.Min(first, second); var i = Random.Shared.Next(min, max + 1);