mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-01-31 17:19:00 +03:00
Octol1ttle
84e730838b
*I'll start working on features and bugfixes after this PR, I promise* very short summary: - no more braceless statements - braces are on new lines now - `sealed` on everything that can be `sealed` - no more awkwardly looking alignment of fields/parameters - no more `Service` suffix on service fields. yeah. - no more `else`s. who needs them? - code style is now enforced by CI --------- Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
using System.Text.Json.Nodes;
|
|
using System.Text.RegularExpressions;
|
|
using Remora.Discord.Extensions.Formatting;
|
|
using Remora.Rest.Core;
|
|
using Remora.Results;
|
|
|
|
namespace Boyfriend.Data.Options;
|
|
|
|
public sealed partial class SnowflakeOption : Option<Snowflake>
|
|
{
|
|
public SnowflakeOption(string name) : base(name, 0UL.ToSnowflake()) { }
|
|
|
|
public override string Display(JsonNode settings)
|
|
{
|
|
return Name.EndsWith("Channel", StringComparison.Ordinal)
|
|
? Mention.Channel(Get(settings))
|
|
: Mention.Role(Get(settings));
|
|
}
|
|
|
|
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(NonNumbers().Replace(from, ""), out var parsed))
|
|
{
|
|
return new ArgumentInvalidError(nameof(from), Messages.InvalidSettingValue);
|
|
}
|
|
|
|
settings[Name] = parsed;
|
|
return Result.FromSuccess();
|
|
}
|
|
|
|
[GeneratedRegex("[^0-9]")]
|
|
private static partial Regex NonNumbers();
|
|
}
|