Skip to content

Commit d4449ae

Browse files
fix CustomCommand arguments being incorrectly parsed
1 parent 84aefc1 commit d4449ae

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

Code/FlagSystem/Flags/CustomCommandFlag.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using SER.Code.ScriptSystem;
1111
using SER.Code.ScriptSystem.Structures;
1212
using SER.Code.TokenSystem;
13+
using SER.Code.TokenSystem.Tokens.Interfaces;
1314
using SER.Code.TokenSystem.Tokens.ValueTokens;
1415
using SER.Code.ValueSystem;
1516
using SER.Code.VariableSystem.Variables;
@@ -418,13 +419,32 @@ public static Result RunAttachedScript(CustomCommand cmd, ScriptExecutor sender,
418419
var slice = provided[index];
419420
var argVariable = cmd.Usage[index];
420421
var name = argVariable[0].ToString().ToLowerInvariant() + argVariable[1..];
422+
423+
if (Tokenizer.GetTokenFromSlice(slice, null, null)
424+
.HasErrored(out error, out var token))
425+
{
426+
return $"Cannot understand input '{slice.Value}' for argument '{argVariable}'. ".AsError() +
427+
error.AsError();
428+
}
429+
430+
LiteralValue value;
431+
if (token is IValueToken { IsConstant: true } valToken
432+
&& valToken.Value().WasSuccessful(out var tempVal)
433+
&& tempVal is LiteralValue tempVal2)
434+
{
435+
value = tempVal2;
436+
}
437+
else
438+
{
439+
value = new StaticTextValue(token.BestStaticTextRepr());
440+
}
421441

422442
if (name.Last() == '?')
423443
{
424444
name = name[..^1];
425445
}
426446

427-
script.AddLocalVariable(new LiteralVariable<TextValue>(name, new StaticTextValue(slice.Value)));
447+
script.AddLocalVariable(new LiteralVariable(name, value));
428448
}
429449

430450
script.AddLocalVariable(new ReferenceVariable("command", new ReferenceValue<CustomCommand>(cmd)));

0 commit comments

Comments
 (0)