Split responders into separate class files
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
fe4793f5f9
commit
6017a46f38
30 changed files with 434 additions and 393 deletions
|
@ -1,5 +1,4 @@
|
|||
using System.Text.Json.Nodes;
|
||||
using Boyfriend.locale;
|
||||
using Remora.Results;
|
||||
|
||||
namespace Boyfriend.Data.Options;
|
||||
|
@ -7,6 +6,10 @@ namespace Boyfriend.Data.Options;
|
|||
public class BoolOption : Option<bool> {
|
||||
public BoolOption(string name, bool defaultValue) : base(name, defaultValue) { }
|
||||
|
||||
public override string Display(JsonNode settings) {
|
||||
return Get(settings) ? Messages.Yes : Messages.No;
|
||||
}
|
||||
|
||||
public override Result Set(JsonNode settings, string from) {
|
||||
if (!TryParseBool(from, out var value))
|
||||
return Result.FromError(new ArgumentInvalidError(nameof(from), Messages.InvalidSettingValue));
|
||||
|
|
|
@ -5,6 +5,6 @@ namespace Boyfriend.Data.Options;
|
|||
|
||||
public interface IOption {
|
||||
string Name { get; }
|
||||
object GetAsObject(JsonNode settings);
|
||||
Result Set(JsonNode settings, string from);
|
||||
string Display(JsonNode settings);
|
||||
Result Set(JsonNode settings, string from);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using System.Globalization;
|
||||
using System.Text.Json.Nodes;
|
||||
using Boyfriend.locale;
|
||||
using Remora.Discord.Extensions.Formatting;
|
||||
using Remora.Results;
|
||||
|
||||
namespace Boyfriend.Data.Options;
|
||||
|
@ -15,6 +15,10 @@ public class LanguageOption : Option<CultureInfo> {
|
|||
|
||||
public LanguageOption(string name, string defaultValue) : base(name, CultureInfoCache[defaultValue]) { }
|
||||
|
||||
public override string Display(JsonNode settings) {
|
||||
return Markdown.InlineCode(settings[Name]?.GetValue<string>() ?? "en");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override CultureInfo Get(JsonNode settings) {
|
||||
var property = settings[Name];
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.Text.Json.Nodes;
|
||||
using Remora.Discord.Extensions.Formatting;
|
||||
using Remora.Results;
|
||||
|
||||
namespace Boyfriend.Data.Options;
|
||||
|
@ -7,7 +8,8 @@ namespace Boyfriend.Data.Options;
|
|||
/// Represents an per-guild option.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the option.</typeparam>
|
||||
public class Option<T> : IOption {
|
||||
public class Option<T> : IOption
|
||||
where T : notnull {
|
||||
internal readonly T DefaultValue;
|
||||
|
||||
public Option(string name, T defaultValue) {
|
||||
|
@ -17,8 +19,8 @@ public class Option<T> : IOption {
|
|||
|
||||
public string Name { get; }
|
||||
|
||||
public object GetAsObject(JsonNode settings) {
|
||||
return Get(settings)!;
|
||||
public virtual string Display(JsonNode settings) {
|
||||
return Markdown.InlineCode(Get(settings).ToString()!);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using System.Text.Json.Nodes;
|
||||
using Boyfriend.locale;
|
||||
using Remora.Discord.Extensions.Formatting;
|
||||
using Remora.Rest.Core;
|
||||
using Remora.Results;
|
||||
|
||||
|
@ -8,6 +8,10 @@ namespace Boyfriend.Data.Options;
|
|||
public class SnowflakeOption : Option<Snowflake> {
|
||||
public SnowflakeOption(string name) : base(name, 0UL.ToSnowflake()) { }
|
||||
|
||||
public override string Display(JsonNode settings) {
|
||||
return Name.EndsWith("Channel") ? 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;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System.Text.Json.Nodes;
|
||||
using Boyfriend.locale;
|
||||
using Remora.Commands.Parsers;
|
||||
using Remora.Results;
|
||||
|
||||
|
|
Reference in a new issue