mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge branch 'staging' into pr/2204
This commit is contained in:
@ -259,6 +259,26 @@ function diceRollReplace(input, invalidRollPlaceholder = '') {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the difference between two times. Works with any time format acceptable by moment().
|
||||
* Can work with {{date}} {{time}} macros
|
||||
* @param {string} input - The string to replace time difference macros in.
|
||||
* @returns {string} The string with replaced time difference macros.
|
||||
*/
|
||||
function timeDiffReplace(input) {
|
||||
const timeDiffPattern = /{{timeDiff::(.*?)::(.*?)}}/gi;
|
||||
|
||||
const output = input.replace(timeDiffPattern, (_match, matchPart1, matchPart2) => {
|
||||
const time1 = moment(matchPart1);
|
||||
const time2 = moment(matchPart2);
|
||||
|
||||
const timeDifference = moment.duration(time1.diff(time2));
|
||||
return timeDifference.humanize();
|
||||
});
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Substitutes {{macro}} parameters in a string.
|
||||
* @param {string} content - The string to substitute parameters in.
|
||||
@ -330,6 +350,7 @@ export function evaluateMacros(content, env) {
|
||||
const utcTime = moment().utc().utcOffset(utcOffset).format('LT');
|
||||
return utcTime;
|
||||
});
|
||||
content = timeDiffReplace(content);
|
||||
content = bannedWordsReplace(content);
|
||||
content = randomReplace(content);
|
||||
content = pickReplace(content, rawContent);
|
||||
|
Reference in New Issue
Block a user