#1781 Fix /len and unescape for non-string arguments

This commit is contained in:
Cohee 2024-02-03 02:06:49 +02:00
parent 37d94a4331
commit 07677584c4
2 changed files with 30 additions and 13 deletions

View File

@ -1561,7 +1561,8 @@ async function executeSlashCommands(text, unescape = false) {
}
}
if (typeof unnamedArg === 'string' && /{{pipe}}/i.test(unnamedArg)) {
if (typeof unnamedArg === 'string') {
if (/{{pipe}}/i.test(unnamedArg)) {
unnamedArg = unnamedArg.replace(/{{pipe}}/i, pipeResult ?? '');
}
@ -1570,13 +1571,17 @@ async function executeSlashCommands(text, unescape = false) {
?.replace(/\\\{/g, '{')
?.replace(/\\\}/g, '}')
;
}
for (const [key, value] of Object.entries(result.args)) {
if (typeof value === 'string') {
result.args[key] = value
.replace(/\\\|/g, '|')
.replace(/\\\{/g, '{')
.replace(/\\\}/g, '}')
;
}
}
pipeResult = await result.command.callback(result.args, unnamedArg);

View File

@ -649,7 +649,19 @@ function lenValuesCallback(value) {
} catch {
// could not parse
}
if (Array.isArray(parsedValue)) {
return parsedValue.length;
}
switch (typeof parsedValue) {
case 'string':
return parsedValue.length;
case 'object':
return Object.keys(parsedValue).length;
case 'number':
return String(parsedValue).length;
default:
return 0;
}
}
function randValuesCallback(from, to, args) {