fix /let key= not given priority

This commit is contained in:
LenAnderson 2024-07-20 12:00:22 -04:00
parent 4336253b2f
commit 4191e3fa09
1 changed files with 20 additions and 13 deletions

View File

@ -798,24 +798,29 @@ function randValuesCallback(from, to, args) {
* @returns The variable's value * @returns The variable's value
*/ */
function letCallback(args, value) { function letCallback(args, value) {
if (Array.isArray(value)) { if (!Array.isArray(value)) value = [value];
args._scope.letVariable(value[0], typeof value[1] == 'string' ? value.slice(1).join(' ') : value[1]);
return value[1];
}
if (args.key !== undefined) { if (args.key !== undefined) {
const key = args.key; const key = args.key;
const val = value; if (typeof key != 'string') throw new Error('Key must be a string');
if (args._hasUnnamedArgument) {
const val = value.join(' ');
args._scope.letVariable(key, val);
return val;
} else {
args._scope.letVariable(key);
return '';
}
}
const key = value.shift();
if (typeof key != 'string') throw new Error('Key must be a string');
if (value.length > 0) {
const val = value.join(' ');
args._scope.letVariable(key, val); args._scope.letVariable(key, val);
return val; return val;
} else {
args._scope.letVariable(key);
return '';
} }
if (value instanceof SlashCommandClosure) throw new Error('/let unnamed argument does not support closures if no key is provided');
if (value.includes(' ')) {
const key = value.split(' ')[0];
const val = value.split(' ').slice(1).join(' ');
args._scope.letVariable(key, val);
return val;
}
args._scope.letVariable(value);
} }
/** /**
@ -828,6 +833,7 @@ function varCallback(args, value) {
if (!Array.isArray(value)) value = [value]; if (!Array.isArray(value)) value = [value];
if (args.key !== undefined) { if (args.key !== undefined) {
const key = args.key; const key = args.key;
if (typeof key != 'string') throw new Error('Key must be a string');
if (args._hasUnnamedArgument) { if (args._hasUnnamedArgument) {
const val = value.join(' '); const val = value.join(' ');
args._scope.setVariable(key, val, args.index); args._scope.setVariable(key, val, args.index);
@ -837,6 +843,7 @@ function varCallback(args, value) {
} }
} }
const key = value.shift(); const key = value.shift();
if (typeof key != 'string') throw new Error('Key must be a string');
if (value.length > 0) { if (value.length > 0) {
const val = value.join(' '); const val = value.join(' ');
args._scope.setVariable(key, val, args.index); args._scope.setVariable(key, val, args.index);