Merge branch 'staging' into pr/2204

This commit is contained in:
steve02081504
2024-05-12 08:51:47 +08:00
12 changed files with 1560 additions and 53 deletions

View File

@ -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);