diff --git a/ASFEnhance/Data/SubModuleInfo.cs b/ASFEnhance/Data/SubModuleInfo.cs index 36e2b96c..27326fbc 100644 --- a/ASFEnhance/Data/SubModuleInfo.cs +++ b/ASFEnhance/Data/SubModuleInfo.cs @@ -26,5 +26,12 @@ internal sealed record SubModuleInfo /// /// 参数列表 /// - public List ParamList { get; set; } = null!; + public List ParamList { get; set; } = null!; + + /// + /// 判断CmdPrefix是否匹配 + /// + /// + /// + public bool MatchCmdPrefix(string text) => !string.IsNullOrEmpty(CmdPrefix) && CmdPrefix == text; } diff --git a/ASFEnhance/_Adapter_/Endpoint.cs b/ASFEnhance/_Adapter_/Endpoint.cs index 36e6e333..39ab3d89 100644 --- a/ASFEnhance/_Adapter_/Endpoint.cs +++ b/ASFEnhance/_Adapter_/Endpoint.cs @@ -41,10 +41,10 @@ public static string RegisterModule(string pluginName, string pluginId, string? throw new ArgumentNullException(nameof(cmdHandler)); } - var paramList = new List(); + var paramList = new List(); foreach (var paramInfo in cmdHandler.GetParameters()) { - paramList.Add(paramInfo.Name ?? "null"); + paramList.Add(paramInfo.Name?.ToUpperInvariant()); } var subModule = new SubModuleInfo diff --git a/ASFEnhance/_Adapter_/ExtensionCore.cs b/ASFEnhance/_Adapter_/ExtensionCore.cs index 0326d582..b52cb62a 100644 --- a/ASFEnhance/_Adapter_/ExtensionCore.cs +++ b/ASFEnhance/_Adapter_/ExtensionCore.cs @@ -28,17 +28,18 @@ public static class ExtensionCore /// private static Task? Invoke(this SubModuleInfo subModule, Bot bot, EAccess access, string cmd, string message, string[] args, ulong steamId) { + // 根据参数名称填入参数 var objList = new List(); foreach (var paramName in subModule.ParamList) { object? obj = paramName switch { - "bot" => bot, - "access" => access, - "cmd" => cmd, - "message" => message, - "args" => args, - "steamId" => steamId, + "BOT" => bot, + "ACCESS" => access, + "CMD" => cmd, + "MESSAGE" => message, + "ARGS" => args, + "STEAMID" => steamId, _ => null, }; objList.Add(obj); @@ -73,7 +74,7 @@ public static class ExtensionCore { foreach (var (pluginId, subModule) in SubModules) { - if (cmd == pluginId || (!string.IsNullOrEmpty(subModule.CmdPrefix) && subModule.CmdPrefix == cmd)) + if (cmd == pluginId || subModule.MatchCmdPrefix(cmd)) { // 响应 Plugin Info 命令 var pluginInfo = string.Format("{0} {1} [已接入 ASFEnhance]", subModule.PluginName, subModule.PluginVersion); @@ -108,13 +109,13 @@ public static class ExtensionCore { foreach (var (pluginId, subModule) in SubModules) { - if (cmd == pluginId || (!string.IsNullOrEmpty(subModule.CmdPrefix) && subModule.CmdPrefix == cmd)) + if (cmd == pluginId || subModule.MatchCmdPrefix(cmd)) { // 响应 Plugin Info 命令 var pluginInfo = string.Format("{0} {1} [已接入 ASFEnhance]", subModule.PluginName, subModule.PluginVersion); return Task.FromResult(pluginInfo); } - else if (pluginId == pluginName || (!string.IsNullOrEmpty(subModule.CmdPrefix) && subModule.CmdPrefix == pluginName)) + else if (pluginId == pluginName || subModule.MatchCmdPrefix(pluginName)) { //PluginIdenty 和 CmdPrefix 匹配时响应命令 var response = subModule.Invoke(bot, access, cmd, message, args, steamId);