mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-04-19 16:33:36 +03:00
Auto-detect max & min numbers
Signed-off-by: Macintosh II <95250141+mctaylors@users.noreply.github.com>
This commit is contained in:
parent
8e77aba10b
commit
b76a5cc6f5
1 changed files with 7 additions and 13 deletions
|
@ -232,8 +232,8 @@ public class ToolsCommandGroup : CommandGroup
|
|||
/// <summary>
|
||||
/// A slash command that generates a random number using maximum and minimum numbers.
|
||||
/// </summary>
|
||||
/// <param name="max">The maximum number for randomization.</param>
|
||||
/// <param name="min">The minimum number for randomization. Default value: 1</param>
|
||||
/// <param name="first">The first number used for randomization.</param>
|
||||
/// <param name="second">The second number used for randomization. Default value: 1</param>
|
||||
/// <returns>
|
||||
/// A feedback sending result which may or may not have succeeded.
|
||||
/// </returns>
|
||||
|
@ -242,9 +242,9 @@ public class ToolsCommandGroup : CommandGroup
|
|||
[Description("Generates a random number")]
|
||||
[UsedImplicitly]
|
||||
public async Task<Result> 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<Result> 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);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue