diff --git a/src/Commands/BanCommandGroup.cs b/src/Commands/BanCommandGroup.cs
index bbcf459..e72a43c 100644
--- a/src/Commands/BanCommandGroup.cs
+++ b/src/Commands/BanCommandGroup.cs
@@ -4,6 +4,7 @@ using System.Text;
using JetBrains.Annotations;
using Octobot.Data;
using Octobot.Extensions;
+using Octobot.Parsers;
using Octobot.Services;
using Octobot.Services.Update;
using Remora.Commands.Attributes;
@@ -53,7 +54,7 @@ public class BanCommandGroup : CommandGroup
/// A slash command that bans a Discord user with the specified reason.
///
/// The user to ban.
- /// The duration for this ban. The user will be automatically unbanned after this duration.
+ /// The duration for this ban. The user will be automatically unbanned after this duration.
///
/// The reason for this ban. Must be encoded with when passed to
/// .
@@ -75,7 +76,8 @@ public class BanCommandGroup : CommandGroup
[Description("User to ban")] IUser target,
[Description("Ban reason")] [MaxLength(256)]
string reason,
- [Description("Ban duration")] TimeSpan? duration = null)
+ [Description("Ban duration")] [Option("duration")]
+ string? stringDuration = null)
{
if (!_context.TryGetContextIDs(out var guildId, out var channelId, out var executorId))
{
@@ -104,6 +106,23 @@ public class BanCommandGroup : CommandGroup
var data = await _guildData.GetData(guild.ID, CancellationToken);
Messages.Culture = GuildSettings.Language.Get(data.Settings);
+ if (stringDuration is null)
+ {
+ return await BanUserAsync(executor, target, reason, null, guild, data, channelId, bot,
+ CancellationToken);
+ }
+
+ var parseResult = TimeSpanParser.TryParse(stringDuration);
+ if (!parseResult.IsDefined(out var duration))
+ {
+ var failedEmbed = new EmbedBuilder()
+ .WithSmallTitle(Messages.InvalidTimeSpan, bot)
+ .WithColour(ColorsList.Red)
+ .Build();
+
+ return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct: CancellationToken);
+ }
+
return await BanUserAsync(executor, target, reason, duration, guild, data, channelId, bot, CancellationToken);
}
diff --git a/src/Commands/MuteCommandGroup.cs b/src/Commands/MuteCommandGroup.cs
index c7b21f6..0156f82 100644
--- a/src/Commands/MuteCommandGroup.cs
+++ b/src/Commands/MuteCommandGroup.cs
@@ -4,6 +4,7 @@ using System.Text;
using JetBrains.Annotations;
using Octobot.Data;
using Octobot.Extensions;
+using Octobot.Parsers;
using Octobot.Services;
using Octobot.Services.Update;
using Remora.Commands.Attributes;
@@ -50,7 +51,7 @@ public class MuteCommandGroup : CommandGroup
/// A slash command that mutes a Discord member with the specified reason.
///
/// The member to mute.
- /// The duration for this mute. The member will be automatically unmuted after this duration.
+ /// The duration for this mute. The member will be automatically unmuted after this duration.
///
/// The reason for this mute. Must be encoded with when passed to
/// .
@@ -72,7 +73,8 @@ public class MuteCommandGroup : CommandGroup
[Description("Member to mute")] IUser target,
[Description("Mute reason")] [MaxLength(256)]
string reason,
- [Description("Mute duration")] TimeSpan duration)
+ [Description("Mute duration")] [Option("duration")]
+ string stringDuration)
{
if (!_context.TryGetContextIDs(out var guildId, out var channelId, out var executorId))
{
@@ -104,6 +106,17 @@ public class MuteCommandGroup : CommandGroup
return await _feedback.SendContextualEmbedResultAsync(embed, ct: CancellationToken);
}
+ var parseResult = TimeSpanParser.TryParse(stringDuration);
+ if (!parseResult.IsDefined(out var duration))
+ {
+ var failedEmbed = new EmbedBuilder()
+ .WithSmallTitle(Messages.InvalidTimeSpan, bot)
+ .WithColour(ColorsList.Red)
+ .Build();
+
+ return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct: CancellationToken);
+ }
+
return await MuteUserAsync(executor, target, reason, duration, guildId, data, channelId, bot, CancellationToken);
}
diff --git a/src/Commands/ToolsCommandGroup.cs b/src/Commands/ToolsCommandGroup.cs
index 1dbf72d..b539355 100644
--- a/src/Commands/ToolsCommandGroup.cs
+++ b/src/Commands/ToolsCommandGroup.cs
@@ -4,6 +4,7 @@ using System.Text;
using JetBrains.Annotations;
using Octobot.Data;
using Octobot.Extensions;
+using Octobot.Parsers;
using Octobot.Services;
using Remora.Commands.Attributes;
using Remora.Commands.Groups;
@@ -418,7 +419,7 @@ public class ToolsCommandGroup : CommandGroup
///
/// A slash command that shows the current timestamp with an optional offset in all styles supported by Discord.
///
- /// The offset for the current timestamp.
+ /// The offset for the current timestamp.
///
/// A feedback sending result which may or may not have succeeded.
///
@@ -427,14 +428,20 @@ public class ToolsCommandGroup : CommandGroup
[Description("Shows a timestamp in all styles")]
[UsedImplicitly]
public async Task ExecuteTimestampAsync(
- [Description("Offset from current time")]
- TimeSpan? offset = null)
+ [Description("Offset from current time")] [Option("offset")]
+ string? stringOffset = null)
{
if (!_context.TryGetContextIDs(out var guildId, out _, out var executorId))
{
return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context");
}
+ var botResult = await _userApi.GetCurrentUserAsync(CancellationToken);
+ if (!botResult.IsDefined(out var bot))
+ {
+ return Result.FromError(botResult);
+ }
+
var executorResult = await _userApi.GetUserAsync(executorId, CancellationToken);
if (!executorResult.IsDefined(out var executor))
{
@@ -444,6 +451,22 @@ public class ToolsCommandGroup : CommandGroup
var data = await _guildData.GetData(guildId, CancellationToken);
Messages.Culture = GuildSettings.Language.Get(data.Settings);
+ if (stringOffset is null)
+ {
+ return await SendTimestampAsync(null, executor, CancellationToken);
+ }
+
+ var parseResult = TimeSpanParser.TryParse(stringOffset);
+ if (!parseResult.IsDefined(out var offset))
+ {
+ var failedEmbed = new EmbedBuilder()
+ .WithSmallTitle(Messages.InvalidTimeSpan, bot)
+ .WithColour(ColorsList.Red)
+ .Build();
+
+ return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct: CancellationToken);
+ }
+
return await SendTimestampAsync(offset, executor, CancellationToken);
}
diff --git a/src/Parsers/TimeSpanParser.cs b/src/Parsers/TimeSpanParser.cs
index 390bea9..1f44d46 100644
--- a/src/Parsers/TimeSpanParser.cs
+++ b/src/Parsers/TimeSpanParser.cs
@@ -73,6 +73,6 @@ public partial class TimeSpanParser : AbstractTypeParser
return timeSpan;
}
- [GeneratedRegex("(?\\d+(?=y|л|г))|(?\\d+(?=mo|мес))|(?\\d+(?=w|н|нед))|(?\\d+(?=d|дн))|(?\\d+(?=h|ч))|(?\\d+(?=m|min|мин|м))|(?\\d+(?=s|sec|с|сек))")]
+ [GeneratedRegex("(?\\d+(?=y|л|г))|(?\\d+(?=mo|мес))|(?\\d+(?=w|н|нед))|(?\\d+(?=d|д|дн))|(?\\d+(?=h|ч))|(?\\d+(?=m|min|мин|м))|(?\\d+(?=s|sec|с|сек))")]
private static partial Regex ParseRegex();
}