Add {{firstDisplayedMessageId}} macro
| @@ -212,6 +212,21 @@ function getFirstIncludedMessageId() { | |||
| 212 | } | 212 | } |
| 213 | 213 | ||
| 214 | /** | 214 | /** |
| 215 | * Returns the ID of the first displayed message in the chat. | ||
| 216 | * | ||
| 217 | * @returns {number|null} The ID of the first displayed message | ||
| 218 | */ | ||
| 219 | function getFirstDisplayedMessageId() { | ||
| 220 | const mesId = Number(document.querySelector('#chat .mes')?.getAttribute('mesid')); | ||
| 221 | |||
| 222 | if (!isNaN(mesId) && mesId >= 0) { | ||
| 223 | return mesId; | ||
| 224 | } | ||
| 225 | |||
| 226 | return null; | ||
| 227 | } | ||
| 228 | |||
| 229 | /** | ||
| 215 | * Returns the last message in the chat | 230 | * Returns the last message in the chat |
| 216 | * | 231 | * |
| 217 | * @returns {string} The last message in the chat | 232 | * @returns {string} The last message in the chat |
| @@ -467,6 +482,7 @@ export function evaluateMacros(content, env, postProcessFn) { | |||
| 467 | { regex: /{{lastUserMessage}}/gi, replace: () => getLastUserMessage() }, | 482 | { regex: /{{lastUserMessage}}/gi, replace: () => getLastUserMessage() }, |
| 468 | { regex: /{{lastCharMessage}}/gi, replace: () => getLastCharMessage() }, | 483 | { regex: /{{lastCharMessage}}/gi, replace: () => getLastCharMessage() }, |
| 469 | { regex: /{{firstIncludedMessageId}}/gi, replace: () => String(getFirstIncludedMessageId() ?? '') }, | 484 | { regex: /{{firstIncludedMessageId}}/gi, replace: () => String(getFirstIncludedMessageId() ?? '') }, |
| 485 | { regex: /{{firstDisplayedMessageId}}/gi, replace: () => String(getFirstDisplayedMessageId() ?? '') }, | ||
| 470 | { regex: /{{lastSwipeId}}/gi, replace: () => String(getLastSwipeId() ?? '') }, | 486 | { regex: /{{lastSwipeId}}/gi, replace: () => String(getLastSwipeId() ?? '') }, |
| 471 | { regex: /{{currentSwipeId}}/gi, replace: () => String(getCurrentSwipeId() ?? '') }, | 487 | { regex: /{{currentSwipeId}}/gi, replace: () => String(getCurrentSwipeId() ?? '') }, |
| 472 | { regex: /{{reverse:(.+?)}}/gi, replace: (_, str) => Array.from(str).reverse().join('') }, | 488 | { regex: /{{reverse:(.+?)}}/gi, replace: (_, str) => Array.from(str).reverse().join('') }, |
| @@ -29,6 +29,7 @@ | |||
| 29 | <li><tt>{{lastCharMessage}}</tt> – <span data-i18n="help_macros_lastChar">the text of the latest character chat message.</span></li> | 29 | <li><tt>{{lastCharMessage}}</tt> – <span data-i18n="help_macros_lastChar">the text of the latest character chat message.</span></li> |
| 30 | <li><tt>{{lastMessageId}}</tt> – <span data-i18n="help_macros_21">index # of the latest chat message. Useful for slash command batching.</span></li> | 30 | <li><tt>{{lastMessageId}}</tt> – <span data-i18n="help_macros_21">index # of the latest chat message. Useful for slash command batching.</span></li> |
| 31 | <li><tt>{{firstIncludedMessageId}}</tt> – <span data-i18n="help_macros_22">the ID of the first message included in the context. Requires generation to be ran at least once in the current session.</span></li> | 31 | <li><tt>{{firstIncludedMessageId}}</tt> – <span data-i18n="help_macros_22">the ID of the first message included in the context. Requires generation to be ran at least once in the current session.</span></li> |
| 32 | <li><tt>{{firstDisplayedMessageId}}</tt> – <span data-i18n="help_macros_firstDisplayedMessageId">the ID of the first message loaded into the visible chat.</span></li> | ||
| 32 | <li><tt>{{currentSwipeId}}</tt> – <span data-i18n="help_macros_23">the 1-based ID of the current swipe in the last chat message. Empty string if the last message is user or prompt-hidden.</span></li> | 33 | <li><tt>{{currentSwipeId}}</tt> – <span data-i18n="help_macros_23">the 1-based ID of the current swipe in the last chat message. Empty string if the last message is user or prompt-hidden.</span></li> |
| 33 | <li><tt>{{lastSwipeId}}</tt> – <span data-i18n="help_macros_24">the number of swipes in the last chat message. Empty string if the last message is user or prompt-hidden.</span></li> | 34 | <li><tt>{{lastSwipeId}}</tt> – <span data-i18n="help_macros_24">the number of swipes in the last chat message. Empty string if the last message is user or prompt-hidden.</span></li> |
| 34 | <li><tt>{{reverse:(content)}}</tt> – <span data-i18n="help_macros_reverse">reverses the content of the macro.</span></li> | 35 | <li><tt>{{reverse:(content)}}</tt> – <span data-i18n="help_macros_reverse">reverses the content of the macro.</span></li> |