mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-05-05 05:26:28 +03:00
this commit is illegal
This commit is contained in:
parent
07e8784d2e
commit
e0161037bb
8 changed files with 63 additions and 3 deletions
|
@ -12,6 +12,18 @@ public sealed class BoolOption : GuildOption<bool>
|
|||
return Get(settings) ? Messages.Yes : Messages.No;
|
||||
}
|
||||
|
||||
public override Result ValueEquals(JsonNode settings, string value, out bool equals)
|
||||
{
|
||||
if (!TryParseBool(value, out var boolean))
|
||||
{
|
||||
equals = false;
|
||||
return new ArgumentInvalidError(nameof(value), Messages.InvalidSettingValue);
|
||||
}
|
||||
|
||||
equals = Value(settings).Equals(boolean.ToString());
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
public override Result Set(JsonNode settings, string from)
|
||||
{
|
||||
if (!TryParseBool(from, out var value))
|
||||
|
|
|
@ -21,9 +21,20 @@ public class GuildOption<T> : IGuildOption
|
|||
|
||||
public string Name { get; }
|
||||
|
||||
public virtual string Value(JsonNode settings)
|
||||
{
|
||||
return Get(settings).ToString() ?? throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
public virtual string Display(JsonNode settings)
|
||||
{
|
||||
return Markdown.InlineCode(Get(settings).ToString() ?? throw new InvalidOperationException());
|
||||
return Markdown.InlineCode(Value(settings));
|
||||
}
|
||||
|
||||
public virtual Result ValueEquals(JsonNode settings, string value, out bool equals)
|
||||
{
|
||||
equals = Value(settings).Equals(value);
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -6,7 +6,9 @@ namespace TeamOctolings.Octobot.Data.Options;
|
|||
public interface IGuildOption
|
||||
{
|
||||
string Name { get; }
|
||||
string Value(JsonNode settings);
|
||||
string Display(JsonNode settings);
|
||||
Result ValueEquals(JsonNode settings, string value, out bool equals);
|
||||
Result Set(JsonNode settings, string from);
|
||||
Result Reset(JsonNode settings);
|
||||
}
|
||||
|
|
|
@ -16,9 +16,9 @@ public sealed class LanguageOption : GuildOption<CultureInfo>
|
|||
|
||||
public LanguageOption(string name, string defaultValue) : base(name, CultureInfoCache[defaultValue]) { }
|
||||
|
||||
public override string Display(JsonNode settings)
|
||||
public override string Value(JsonNode settings)
|
||||
{
|
||||
return Markdown.InlineCode(settings[Name]?.GetValue<string>() ?? "en");
|
||||
return settings[Name]?.GetValue<string>() ?? "en";
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue