Substitute macro in character editor token counter
This commit is contained in:
parent
6fe4232f75
commit
703965aec8
|
@ -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'
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue