1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-05-18 11:44:45 +03:00

style: move root namespace to TeamOctolings.Octobot

This commit is contained in:
Octol1ttle 2024-05-16 18:11:01 +05:00
parent 19fadead91
commit 3e6240f4b8
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF
61 changed files with 421 additions and 441 deletions

View file

@ -0,0 +1,40 @@
using System.Text.Json.Nodes;
using System.Text.RegularExpressions;
using Remora.Discord.Extensions.Formatting;
using Remora.Rest.Core;
using Remora.Results;
using TeamOctolings.Octobot.Extensions;
namespace TeamOctolings.Octobot.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.Success;
}
[GeneratedRegex("[^0-9]")]
private static partial Regex NonNumbers();
}