Skip to content

Commit

Permalink
feat 参数名改为大写
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed Oct 17, 2023
1 parent 5747a32 commit 2bf315f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
9 changes: 8 additions & 1 deletion ASFEnhance/Data/SubModuleInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,12 @@ internal sealed record SubModuleInfo
/// <summary>
/// 参数列表
/// </summary>
public List<string> ParamList { get; set; } = null!;
public List<string?> ParamList { get; set; } = null!;

/// <summary>
/// 判断CmdPrefix是否匹配
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public bool MatchCmdPrefix(string text) => !string.IsNullOrEmpty(CmdPrefix) && CmdPrefix == text;
}
4 changes: 2 additions & 2 deletions ASFEnhance/_Adapter_/Endpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public static string RegisterModule(string pluginName, string pluginId, string?
throw new ArgumentNullException(nameof(cmdHandler));
}

var paramList = new List<string>();
var paramList = new List<string?>();
foreach (var paramInfo in cmdHandler.GetParameters())
{
paramList.Add(paramInfo.Name ?? "null");
paramList.Add(paramInfo.Name?.ToUpperInvariant());
}

var subModule = new SubModuleInfo
Expand Down
19 changes: 10 additions & 9 deletions ASFEnhance/_Adapter_/ExtensionCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ public static class ExtensionCore
/// <returns></returns>
private static Task<string?>? Invoke(this SubModuleInfo subModule, Bot bot, EAccess access, string cmd, string message, string[] args, ulong steamId)
{
// 根据参数名称填入参数
var objList = new List<object?>();
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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<string?>(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);
Expand Down

0 comments on commit 2bf315f

Please sign in to comment.