mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-04-20 00:43: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>
|
/// <summary>
|
||||||
/// A slash command that generates a random number using maximum and minimum numbers.
|
/// A slash command that generates a random number using maximum and minimum numbers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="max">The maximum number for randomization.</param>
|
/// <param name="first">The first number used for randomization.</param>
|
||||||
/// <param name="min">The minimum number for randomization. Default value: 1</param>
|
/// <param name="second">The second number used for randomization. Default value: 1</param>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// A feedback sending result which may or may not have succeeded.
|
/// A feedback sending result which may or may not have succeeded.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
|
@ -242,9 +242,9 @@ public class ToolsCommandGroup : CommandGroup
|
||||||
[Description("Generates a random number")]
|
[Description("Generates a random number")]
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public async Task<Result> ExecuteRandomAsync(
|
public async Task<Result> ExecuteRandomAsync(
|
||||||
[Description("Maximum number")] int max,
|
[Description("First number")] int first,
|
||||||
[Description("Minumum number (Default: 0)")]
|
[Description("Second number (Default: 0)")]
|
||||||
int min = 0)
|
int second = 0)
|
||||||
{
|
{
|
||||||
if (!_context.TryGetContextIDs(out var guildId, out _, out var userId))
|
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)
|
private async Task<Result> SendRandomNumberAsync(int max, int min, IUser user, IUser currentUser, CancellationToken ct)
|
||||||
{
|
{
|
||||||
if (min > max)
|
var max = Math.Max(first, second);
|
||||||
{
|
var min = Math.Min(first, second);
|
||||||
var failedEmbed = new EmbedBuilder().WithSmallTitle(
|
|
||||||
Messages.RandomMinGreaterThanMax, currentUser)
|
|
||||||
.WithColour(ColorsList.Red).Build();
|
|
||||||
|
|
||||||
return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
var i = Random.Shared.Next(min, max + 1);
|
var i = Random.Shared.Next(min, max + 1);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue