mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-04-19 16:33:36 +03:00
felt like i needed to finish this thing
Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
This commit is contained in:
parent
9084bf28a3
commit
b4ef2170a0
2 changed files with 8 additions and 7 deletions
|
@ -17,7 +17,7 @@ using Remora.Discord.Extensions.Embeds;
|
|||
using Remora.Discord.Extensions.Formatting;
|
||||
using Remora.Rest.Core;
|
||||
using Remora.Results;
|
||||
using TimeSpanParser = Octobot.Parsers.TimeSpanParser;
|
||||
using Octobot.Parsers;
|
||||
|
||||
namespace Octobot.Commands;
|
||||
|
||||
|
@ -146,8 +146,8 @@ public class RemindCommandGroup : CommandGroup
|
|||
var data = await _guildData.GetData(guildId, CancellationToken);
|
||||
Messages.Culture = GuildSettings.Language.Get(data.Settings);
|
||||
|
||||
var timeSpan = TimeSpanParser.TryParse(stringTimeSpan, CancellationToken);
|
||||
if (timeSpan.Equals(TimeSpan.Zero))
|
||||
var parseResult = TimeSpanParser.TryParse(stringTimeSpan, CancellationToken);
|
||||
if (!parseResult.IsDefined(out var timeSpan))
|
||||
{
|
||||
var failedEmbed = new EmbedBuilder()
|
||||
.WithSmallTitle(Messages.InvalidTimeSpan, bot)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using System.Text.RegularExpressions;
|
||||
using JetBrains.Annotations;
|
||||
using Remora.Commands.Parsers;
|
||||
using Remora.Results;
|
||||
|
||||
namespace Octobot.Parsers;
|
||||
|
||||
|
@ -20,13 +21,13 @@ public partial class TimeSpanParser : AbstractTypeParser<TimeSpan>
|
|||
/// Parsed <see cref="TimeSpan"/>.
|
||||
/// </returns>
|
||||
/// <remarks>
|
||||
/// If parse wasn't successful, <see cref="TimeSpanParser"/> will return <see cref="TimeSpan.Zero"/>.
|
||||
/// If parse wasn't successful, <see cref="TimeSpanParser"/> will return <see cref="ArgumentInvalidError"/>.
|
||||
/// </remarks>
|
||||
public static TimeSpan TryParse(string timeSpanString, CancellationToken ct = default)
|
||||
public static Result<TimeSpan> TryParse(string timeSpanString, CancellationToken ct = default)
|
||||
{
|
||||
if (timeSpanString.StartsWith('-'))
|
||||
{
|
||||
return TimeSpan.Zero;
|
||||
return new ArgumentInvalidError(nameof(timeSpanString), "TimeSpan cannot be inverted.");
|
||||
}
|
||||
|
||||
if (TimeSpan.TryParse(timeSpanString, DateTimeFormatInfo.InvariantInfo, out var parsedTimeSpan))
|
||||
|
@ -37,7 +38,7 @@ public partial class TimeSpanParser : AbstractTypeParser<TimeSpan>
|
|||
var matches = ParseRegex().Matches(timeSpanString);
|
||||
if (matches.Count is 0)
|
||||
{
|
||||
return TimeSpan.Zero;
|
||||
return new ArgumentInvalidError(nameof(timeSpanString), "Invalid TimeSpan.");
|
||||
}
|
||||
|
||||
var timeSpan = TimeSpan.Zero;
|
||||
|
|
Loading…
Add table
Reference in a new issue