2024-03-19 18:46:56 +03:00
|
|
|
|
using System.Text.Json.Nodes;
|
|
|
|
|
using Remora.Results;
|
|
|
|
|
|
2024-06-02 07:56:12 +03:00
|
|
|
|
namespace TeamOctolings.Octobot.Data.Options;
|
2024-03-19 18:46:56 +03:00
|
|
|
|
|
2024-06-02 07:56:12 +03:00
|
|
|
|
public sealed class IntOption : GuildOption<int>
|
2024-03-19 18:46:56 +03:00
|
|
|
|
{
|
|
|
|
|
public IntOption(string name, int defaultValue) : base(name, defaultValue) { }
|
|
|
|
|
|
|
|
|
|
public override string Display(JsonNode settings)
|
|
|
|
|
{
|
|
|
|
|
return settings[Name]?.GetValue<string>() ?? "0";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Result Set(JsonNode settings, string from)
|
|
|
|
|
{
|
|
|
|
|
if (!int.TryParse(from, out _))
|
|
|
|
|
{
|
|
|
|
|
return new ArgumentInvalidError(nameof(from), Messages.InvalidSettingValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
settings[Name] = from;
|
|
|
|
|
return Result.FromSuccess();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int Get(JsonNode settings)
|
|
|
|
|
{
|
|
|
|
|
var property = settings[Name];
|
|
|
|
|
return property != null ? Convert.ToInt32(property.GetValue<string>()) : DefaultValue;
|
|
|
|
|
}
|
|
|
|
|
}
|