mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-05-05 21:46:28 +03:00
style: move root namespace to TeamOctolings.Octobot
This commit is contained in:
parent
19fadead91
commit
3e6240f4b8
61 changed files with 421 additions and 441 deletions
27
TeamOctolings.Octobot/Data/Options/TimeSpanOption.cs
Normal file
27
TeamOctolings.Octobot/Data/Options/TimeSpanOption.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using System.Text.Json.Nodes;
|
||||
using Remora.Results;
|
||||
using TeamOctolings.Octobot.Parsers;
|
||||
|
||||
namespace TeamOctolings.Octobot.Data.Options;
|
||||
|
||||
public sealed class TimeSpanOption : Option<TimeSpan>
|
||||
{
|
||||
public TimeSpanOption(string name, TimeSpan defaultValue) : base(name, defaultValue) { }
|
||||
|
||||
public override TimeSpan Get(JsonNode settings)
|
||||
{
|
||||
var property = settings[Name];
|
||||
return property != null ? TimeSpanParser.TryParse(property.GetValue<string>()).Entity : DefaultValue;
|
||||
}
|
||||
|
||||
public override Result Set(JsonNode settings, string from)
|
||||
{
|
||||
if (!TimeSpanParser.TryParse(from).IsDefined(out var span))
|
||||
{
|
||||
return new ArgumentInvalidError(nameof(from), Messages.InvalidSettingValue);
|
||||
}
|
||||
|
||||
settings[Name] = span.ToString();
|
||||
return Result.Success;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue