mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-12 10:00:36 +01:00
Merge pull request #2215 from Hydroerotic/staging
Added {{timeDiff}} macro.
This commit is contained in:
commit
2f310c72fa
@ -259,6 +259,25 @@ function diceRollReplace(input, invalidRollPlaceholder = '') {
|
||||
});
|
||||
}
|
||||
|
||||
/* Returns the difference between two times. Works with any time format acceptable by moment().
|
||||
* Can work with {{date}} {{time}} macros
|
||||
*/
|
||||
function timeDiffReplace(input) {
|
||||
const timeDiffPattern = /{{timeDiff::(.*?)::(.*?)}}/gi;
|
||||
|
||||
const output = input.replace(timeDiffPattern, (match, matchPart1, matchPart2) => {
|
||||
|
||||
const time1 = new moment(matchPart1);
|
||||
|
||||
const time2 = new 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.
|
||||
@ -327,6 +346,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);
|
||||
|
@ -33,6 +33,7 @@
|
||||
<li><tt>{{isodate}}</tt> – the current ISO date (YYYY-MM-DD)</li>
|
||||
<li><tt>{{datetimeformat …}}</tt> – the current date/time in the specified format, e. g. for German date/time: <tt>{{datetimeformat DD.MM.YYYY HH:mm}}</tt></li>
|
||||
<li><tt>{{time_UTC±#}}</tt> – the current time in the specified UTC time zone offset, e.g. UTC-4 or UTC+2</li>
|
||||
<li><tt>{{timeDiff::(time1)::(time2)}}</tt> – the time difference between time1 and time2. Accepts time and date macros. (Ex: {{timeDiff::{{isodate}} {{time}}::2024/5/11 12:30:00}})</li>
|
||||
<li><tt>{{idle_duration}}</tt> – the time since the last user message was sent</li>
|
||||
<li><tt>{{bias "text here"}}</tt> – sets a behavioral bias for the AI until the next user input. Quotes around the text are important.</li>
|
||||
<li><tt>{{roll:(formula)}}</tt> – rolls a dice. (ex: <tt>>{{roll:1d6}}</tt> will roll a 6-sided dice and return a number between 1 and 6)</li>
|
||||
|
Loading…
x
Reference in New Issue
Block a user