diff --git a/locale/Messages.resx b/locale/Messages.resx
index b03c9f1..7f7e209 100644
--- a/locale/Messages.resx
+++ b/locale/Messages.resx
@@ -525,11 +525,20 @@
Nitro booster since
-
- The minimum number is greater than the maximum!
+
+ Random number for {0} is:
-
- Your random number is:
+
+ Isn't it obvious?
+
+
+ Minimum number: {0}
+
+
+ Maximum number: {0}
+
+
+ (default)
Timestamp for {0}:
diff --git a/locale/Messages.ru.resx b/locale/Messages.ru.resx
index 7e0d6cd..5f3dcf5 100644
--- a/locale/Messages.ru.resx
+++ b/locale/Messages.ru.resx
@@ -525,11 +525,20 @@
Начал бустить сервер
-
- Минимальное число больше максимального!
+
+ Случайное число для {0}:
-
- Ваше случайное число:
+
+ Разве это не очевидно?
+
+
+ Максимальное число: {0}
+
+
+ Минимальное число: {0}
+
+
+ (по умолчанию)
Временная метка для {0}:
diff --git a/locale/Messages.tt-ru.resx b/locale/Messages.tt-ru.resx
index b27104b..ce0ef61 100644
--- a/locale/Messages.tt-ru.resx
+++ b/locale/Messages.tt-ru.resx
@@ -525,11 +525,20 @@
бустит сервер со времен
-
- почему минимальное > максимальное
+
+ рандомное число {0}:
-
- ваше рандомное число:
+
+ ну чувак...
+
+
+ наибольшее: {0}
+
+
+ наименьшее: {0}
+
+
+ (дефолт)
таймштамп для {0}:
diff --git a/src/Commands/ToolsCommandGroup.cs b/src/Commands/ToolsCommandGroup.cs
index 6abb918..445140d 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: 0
///
/// A feedback sending result which may or may not have succeeded.
///
@@ -242,21 +242,15 @@ public class ToolsCommandGroup : CommandGroup
[Description("Generates a random number")]
[UsedImplicitly]
public async Task ExecuteRandomAsync(
- [Description("Maximum number")] int max,
- [Description("Minumum number (Default: 1)")]
- int min = 1)
+ [Description("First number")] long first,
+ [Description("Second number (Default: 0)")]
+ long? second = null)
{
if (!_context.TryGetContextIDs(out var guildId, out _, out var userId))
{
return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context");
}
- var currentUserResult = await _userApi.GetCurrentUserAsync(CancellationToken);
- if (!currentUserResult.IsDefined(out var currentUser))
- {
- return Result.FromError(currentUserResult);
- }
-
var userResult = await _userApi.GetUserAsync(userId, CancellationToken);
if (!userResult.IsDefined(out var user))
{
@@ -266,25 +260,47 @@ public class ToolsCommandGroup : CommandGroup
var data = await _guildData.GetData(guildId, CancellationToken);
Messages.Culture = GuildSettings.Language.Get(data.Settings);
- return await SendRandomNumberAsync(max, min, user, currentUser, CancellationToken);
+ return await SendRandomNumberAsync(first, second, user, CancellationToken);
}
- private async Task SendRandomNumberAsync(int max, int min, IUser user, IUser currentUser, CancellationToken ct)
+ private async Task SendRandomNumberAsync(long first, long? secondNullable,
+ IUser user, CancellationToken ct)
{
- if (min > max)
- {
- var failedEmbed = new EmbedBuilder().WithSmallTitle(
- Messages.RandomMinGreaterThanMax, currentUser)
- .WithColour(ColorsList.Red).Build();
+ const long secondDefault = 0;
+ var second = secondNullable ?? secondDefault;
- return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct);
+ var min = Math.Min(first, second);
+ var max = Math.Max(first, second);
+
+ var i = Random.Shared.NextInt64(min, max + 1);
+
+ var description = new StringBuilder().Append("# ").Append(i);
+
+ description.AppendLine().Append("- ").Append(string.Format(
+ Messages.RandomMin, Markdown.InlineCode(min.ToString())));
+ if (secondNullable is null && first >= secondDefault)
+ {
+ description.Append(' ').Append(Messages.Default);
}
- var i = Random.Shared.Next(min, max + 1);
+ description.AppendLine().Append("- ").Append(string.Format(
+ Messages.RandomMax, Markdown.InlineCode(max.ToString())));
+ if (secondNullable is null && first < secondDefault)
+ {
+ description.Append(' ').Append(Messages.Default);
+ }
- var embed = new EmbedBuilder().WithSmallTitle(Messages.RandomOutput, user)
- .WithDescription($"# {i}\n({min}-{max})")
- .WithColour(ColorsList.Blue)
+ var embedColor = ColorsList.Blue;
+ if (secondNullable is not null && min == max)
+ {
+ description.AppendLine().Append(Markdown.Italicise(Messages.RandomMinMaxSame));
+ embedColor = ColorsList.Red;
+ }
+
+ var embed = new EmbedBuilder().WithSmallTitle(
+ string.Format(Messages.RandomTitle, user.GetTag()), user)
+ .WithDescription(description.ToString())
+ .WithColour(embedColor)
.Build();
return await _feedback.SendContextualEmbedResultAsync(embed, ct);
diff --git a/src/Messages.Designer.cs b/src/Messages.Designer.cs
index aef4b7a..bcdc9cd 100644
--- a/src/Messages.Designer.cs
+++ b/src/Messages.Designer.cs
@@ -882,17 +882,38 @@ namespace Octobot {
}
}
- internal static string RandomMinGreaterThanMax
+ internal static string RandomTitle
{
get {
- return ResourceManager.GetString("RandomMinGreaterThanMax", resourceCulture);
+ return ResourceManager.GetString("RandomTitle", resourceCulture);
}
}
- internal static string RandomOutput
+ internal static string RandomMinMaxSame
{
get {
- return ResourceManager.GetString("RandomOutput", resourceCulture);
+ return ResourceManager.GetString("RandomMinMaxSame", resourceCulture);
+ }
+ }
+
+ internal static string RandomMax
+ {
+ get {
+ return ResourceManager.GetString("RandomMax", resourceCulture);
+ }
+ }
+
+ internal static string RandomMin
+ {
+ get {
+ return ResourceManager.GetString("RandomMin", resourceCulture);
+ }
+ }
+
+ internal static string Default
+ {
+ get {
+ return ResourceManager.GetString("Default", resourceCulture);
}
}