Add {{firstDisplayedMessageId}} macro

a585f3abcc26c81f24bb3e5eb0c1703ee9910052

Cohee <18619528+Cohee1207@users.noreply.github.com>

2 files changed, +17 -0Showing whitespace changes
public/scripts/macros.js+16 -0
@@ -212,6 +212,21 @@ function getFirstIncludedMessageId() {
212}212}
213213
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 */
219function 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 chat230 * Returns the last message in the chat
216 *231 *
217 * @returns {string} The last message in the chat232 * @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('') },
public/scripts/templates/macros.html+1 -0
@@ -29,6 +29,7 @@
29 <li><tt>&lcub;&lcub;lastCharMessage&rcub;&rcub;</tt> – <span data-i18n="help_macros_lastChar">the text of the latest character chat message.</span></li>29 <li><tt>&lcub;&lcub;lastCharMessage&rcub;&rcub;</tt> – <span data-i18n="help_macros_lastChar">the text of the latest character chat message.</span></li>
30 <li><tt>&lcub;&lcub;lastMessageId&rcub;&rcub;</tt> – <span data-i18n="help_macros_21">index # of the latest chat message. Useful for slash command batching.</span></li>30 <li><tt>&lcub;&lcub;lastMessageId&rcub;&rcub;</tt> – <span data-i18n="help_macros_21">index # of the latest chat message. Useful for slash command batching.</span></li>
31 <li><tt>&lcub;&lcub;firstIncludedMessageId&rcub;&rcub;</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>&lcub;&lcub;firstIncludedMessageId&rcub;&rcub;</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>&lcub;&lcub;firstDisplayedMessageId&rcub;&rcub;</tt> – <span data-i18n="help_macros_firstDisplayedMessageId">the ID of the first message loaded into the visible chat.</span></li>
32 <li><tt>&lcub;&lcub;currentSwipeId&rcub;&rcub;</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>&lcub;&lcub;currentSwipeId&rcub;&rcub;</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>&lcub;&lcub;lastSwipeId&rcub;&rcub;</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>&lcub;&lcub;lastSwipeId&rcub;&rcub;</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>&lcub;&lcub;reverse:(content)&rcub;&rcub;</tt> – <span data-i18n="help_macros_reverse">reverses the content of the macro.</span></li>35 <li><tt>&lcub;&lcub;reverse:(content)&rcub;&rcub;</tt> – <span data-i18n="help_macros_reverse">reverses the content of the macro.</span></li>