1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-05-05 05:26:28 +03:00

Made guild settings code 10x better

Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
Octol1ttle 2023-07-11 00:28:49 +05:00
parent c00585e639
commit bbddb3790a
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF
26 changed files with 452 additions and 303 deletions

View file

@ -0,0 +1,23 @@
using System.Text.Json.Nodes;
using Boyfriend.locale;
using Remora.Rest.Core;
using Remora.Results;
namespace Boyfriend.Data.Options;
public class SnowflakeOption : Option<Snowflake> {
public SnowflakeOption(string name) : base(name, 0UL.ToSnowflake()) { }
public override Snowflake Get(JsonNode settings) {
var property = settings[Name];
return property != null ? property.GetValue<ulong>().ToSnowflake() : DefaultValue;
}
public override Result Set(JsonNode settings, string from) {
if (!ulong.TryParse(from, out var parsed))
return Result.FromError(new ArgumentInvalidError(nameof(from), Messages.InvalidSettingValue));
settings[Name] = parsed;
return Result.FromSuccess();
}
}