feat(commands): add support for optional args

This commit is contained in:
Oliver Booth 2023-05-06 16:00:41 +01:00
parent 487bb8ca88
commit 65a9a0e1e3
No known key found for this signature in database
GPG Key ID: 20BEB9DC87961025
1 changed files with 6 additions and 1 deletions

View File

@ -253,7 +253,7 @@ public sealed class CommandsExtension : VirtualParadiseClientExtension
}
ParameterInfo[] parameters = commandMethod.GetParameters();
if (parameters.Length != arguments.Length)
if (parameters.Length != arguments.Length || parameters[arguments.Length..].Any(p => !p.IsOptional))
{
return base.OnMessageReceived(args);
}
@ -286,6 +286,11 @@ public sealed class CommandsExtension : VirtualParadiseClientExtension
}
}
for (int index = arguments.Length; index < parameters.Length; index++)
{
arguments[index] = parameters[index].DefaultValue;
}
object? returnValue = commandMethod.Invoke(command.Module, arguments);
if (returnValue is Task task)
{