dev: Renamed some classes, making the new string model work

This commit is contained in:
Kwoth
2024-05-07 22:55:56 +00:00
parent 3e71d9f1ba
commit 577d62a1c1
6 changed files with 31 additions and 9 deletions

View File

@@ -16,3 +16,6 @@ public sealed class CmdAttribute : CommandAttribute
Summary = memberName.ToLowerInvariant(); Summary = memberName.ToLowerInvariant();
} }
} }
[AttributeUsage(AttributeTargets.Method)]
public sealed class PromptableAttribute: Attribute;

View File

@@ -1,3 +1,4 @@
using NadekoBot.Common.Yml;
using YamlDotNet.Serialization; using YamlDotNet.Serialization;
namespace NadekoBot.Common.Attributes; namespace NadekoBot.Common.Attributes;
@@ -15,6 +16,14 @@ public static class CommandNameLoadHelper
return _deserializer.Deserialize<Dictionary<string, string[]>>(text); return _deserializer.Deserialize<Dictionary<string, string[]>>(text);
} }
public static Dictionary<string, CommandStrings> LoadCommandStrings(
string commandsFilePath = "data/strings/commands.yml")
{
var text = File.ReadAllText(commandsFilePath);
return Yaml.Deserializer.Deserialize<Dictionary<string, CommandStrings>>(text);
}
public static string[] GetAliasesFor(string methodName) public static string[] GetAliasesFor(string methodName)
=> _lazyCommandAliases.Value.TryGetValue(methodName.ToLowerInvariant(), out var aliases) && aliases.Length > 1 => _lazyCommandAliases.Value.TryGetValue(methodName.ToLowerInvariant(), out var aliases) && aliases.Length > 1
? aliases.ToArray() ? aliases.ToArray()

View File

@@ -179,9 +179,15 @@ public sealed partial class ResponseBuilder
if (text is SmartPlainText spt) if (text is SmartPlainText spt)
plainText = spt.Text; plainText = spt.Text;
else if (text is SmartEmbedText set) else if (text is SmartEmbedText set)
{
plainText = set.PlainText ?? plainText;
embedBuilder = set.GetEmbed(); embedBuilder = set.GetEmbed();
}
else if (text is SmartEmbedTextArray ser) else if (text is SmartEmbedTextArray ser)
{
plainText = ser.Content ?? plainText;
embeds = ser.GetEmbedBuilders(); embeds = ser.GetEmbedBuilders();
}
return this; return this;
} }

View File

@@ -21,30 +21,32 @@ public sealed class ModuleTypeReader : NadekoTypeReader<ModuleInfo>
} }
} }
public sealed class ModuleOrCrTypeReader : NadekoTypeReader<ModuleOrCrInfo> public sealed class ModuleOrExprTypeReader : NadekoTypeReader<ModuleOrExpr>
{ {
private readonly CommandService _cmds; private readonly CommandService _cmds;
public ModuleOrCrTypeReader(CommandService cmds) public ModuleOrExprTypeReader(CommandService cmds)
=> _cmds = cmds; => _cmds = cmds;
public override ValueTask<TypeReaderResult<ModuleOrCrInfo>> ReadAsync(ICommandContext context, string input) public override ValueTask<TypeReaderResult<ModuleOrExpr>> ReadAsync(ICommandContext context, string input)
{ {
input = input.ToUpperInvariant(); input = input.ToUpperInvariant();
var module = _cmds.Modules.GroupBy(m => m.GetTopLevelModule()) var module = _cmds.Modules.GroupBy(m => m.GetTopLevelModule())
.FirstOrDefault(m => m.Key.Name.ToUpperInvariant() == input) .FirstOrDefault(m => m.Key.Name.ToUpperInvariant() == input)
?.Key; ?.Key;
if (module is null && input != "ACTUALEXPRESSIONS") if (module is null && input != "ACTUALEXPRESSIONS")
return new(TypeReaderResult.FromError<ModuleOrCrInfo>(CommandError.ParseFailed, "No such module found.")); return new(TypeReaderResult.FromError<ModuleOrExpr>(CommandError.ParseFailed, "No such module found."));
return new(TypeReaderResult.FromSuccess(new ModuleOrCrInfo return new(TypeReaderResult.FromSuccess(new ModuleOrExpr
{ {
Name = input Name = input
})); }));
} }
} }
public sealed class ModuleOrCrInfo // todo chagne commands.en-us to have the new type name
public sealed class ModuleOrExpr
{ {
public string Name { get; set; } public string Name { get; set; }
} }

View File

@@ -7,7 +7,9 @@ namespace NadekoBot.Common.Yml;
public class Yaml public class Yaml
{ {
public static ISerializer Serializer public static ISerializer Serializer
=> new SerializerBuilder().WithTypeInspector(inner => new CommentGatheringTypeInspector(inner)) => new SerializerBuilder()
.WithTypeInspector(inner => new CommentGatheringTypeInspector(inner))
.DisableAliases()
.WithEmissionPhaseObjectGraphVisitor(args .WithEmissionPhaseObjectGraphVisitor(args
=> new CommentsObjectGraphVisitor(args.InnerVisitor)) => new CommentsObjectGraphVisitor(args.InnerVisitor))
.WithEventEmitter(args => new MultilineScalarFlowStyleEmitter(args)) .WithEventEmitter(args => new MultilineScalarFlowStyleEmitter(args))

View File

@@ -154,7 +154,7 @@ public static class Extensions
} }
else else
{ {
args = strings.GetCommandStrings(cmd.Summary, culture).Args; args = strings.GetCommandStrings(cmd.Summary, culture).Examples;
} }
return args.Map(arg => GetFullUsage(cmd.Aliases.First(), arg, prefix)); return args.Map(arg => GetFullUsage(cmd.Aliases.First(), arg, prefix));