Substitute macro in character editor token counter

This commit is contained in:
Cohee 2023-10-21 14:39:01 +03:00
parent 6fe4232f75
commit 703965aec8
2 changed files with 8 additions and 4 deletions

View File

@ -1674,7 +1674,7 @@ function substituteParams(content, _name1, _name2, _original, _group) {
if (typeof _original === 'string') {
content = content.replace(/{{original}}/i, _original);
}
content = content.replace(/{{input}}/gi, $('#send_textarea').val());
content = content.replace(/{{input}}/gi, String($('#send_textarea').val()));
content = content.replace(/{{user}}/gi, _name1);
content = content.replace(/{{char}}/gi, _name2);
content = content.replace(/{{charIfNotGroup}}/gi, _group);
@ -1692,7 +1692,7 @@ function substituteParams(content, _name1, _name2, _original, _group) {
content = content.replace(/{{weekday}}/gi, moment().format('dddd'));
content = content.replace(/{{isotime}}/gi, moment().format('HH:mm'));
content = content.replace(/{{isodate}}/gi, moment().format('YYYY-MM-DD'));
content = content.replace(/{{datetimeformat +([^}]*)}}/gi, (_, format) => {
const formattedTime = moment().format(format);
return formattedTime;
@ -8090,7 +8090,7 @@ jQuery(async function () {
easing: 'ease-in-out'
});
}
});
});
}
});

View File

@ -18,6 +18,8 @@ import {
getThumbnailUrl,
selectCharacterById,
eventSource,
menu_type,
substituteParams,
} from "../script.js";
import {
@ -234,7 +236,9 @@ export function RA_CountCharTokens() {
total_tokens += Number(counter.text());
permanent_tokens += isPermanent ? Number(counter.text()) : 0;
} else {
const tokens = getTokenCount(value);
// We substitute macro for existing characters, but not for the character being created
const valueToCount = menu_type === 'create' ? value : substituteParams(value);
const tokens = getTokenCount(valueToCount);
counter.text(tokens);
total_tokens += tokens;
permanent_tokens += isPermanent ? tokens : 0;