Various commands with 'at' support depth values

f7d3a1c942b338b43f28738bb4f5b41cb4b8f6cf

Wolfsblvt <wolfsblvt@gmx.de>

1 files changed, +33 -8Showing whitespace changes
public/scripts/slash-commands.js+33 -8
@@ -177,7 +177,7 @@ export function initDefaultSlashCommands() {
177177 ),
178178 SlashCommandNamedArgument.fromProps({
179179 name: 'at',
180- description: 'position to insert the message',
180+ description: 'position to insert the message (index-based, corresponding to message id). If not set, the message will be inserted at the end of the chat.\nNegative values are accepted and will work similarly to how \'depth\' usually works. For example, -1 will insert the message right before the last message in chat.',
181181 typeList: [ARGUMENT_TYPE.NUMBER],
182182 enumProvider: commonEnumProviders.messages({ allowIdAfter: true }),
183183 }),
@@ -220,7 +220,7 @@ export function initDefaultSlashCommands() {
220220 ),
221221 SlashCommandNamedArgument.fromProps({
222222 name: 'at',
223- description: 'position to insert the message',
223+ description: 'position to insert the message (index-based, corresponding to message id). If not set, the message will be inserted at the end of the chat.\nNegative values are accepted and will work similarly to how \'depth\' usually works. For example, -1 will insert the message right before the last message in chat.',
224224 typeList: [ARGUMENT_TYPE.NUMBER],
225225 enumProvider: commonEnumProviders.messages({ allowIdAfter: true }),
226226 }),
@@ -274,7 +274,7 @@ export function initDefaultSlashCommands() {
274274 ),
275275 SlashCommandNamedArgument.fromProps({
276276 name: 'at',
277- description: 'position to insert the message',
277+ description: 'position to insert the message (index-based, corresponding to message id). If not set, the message will be inserted at the end of the chat.\nNegative values are accepted and will work similarly to how \'depth\' usually works. For example, -1 will insert the message right before the last message in chat.',
278278 typeList: [ARGUMENT_TYPE.NUMBER],
279279 enumProvider: commonEnumProviders.messages({ allowIdAfter: true }),
280280 }),
@@ -459,7 +459,7 @@ export function initDefaultSlashCommands() {
459459 ),
460460 SlashCommandNamedArgument.fromProps({
461461 name: 'at',
462- description: 'position to insert the message',
462+ description: 'position to insert the message (index-based, corresponding to message id). If not set, the message will be inserted at the end of the chat.\nNegative values are accepted and will work similarly to how \'depth\' usually works. For example, -1 will insert the message right before the last message in chat.',
463463 typeList: [ARGUMENT_TYPE.NUMBER],
464464 enumProvider: commonEnumProviders.messages({ allowIdAfter: true }),
465465 }),
@@ -2429,7 +2429,14 @@ async function sendUserMessageCallback(args, text) {
24292429 text = text.trim();
24302430 const compact = isTrueBoolean(args?.compact);
24312431 const bias = extractMessageBias(text);
2432- const insertAt = Number(args?.at);
2432+
2433+ let insertAt = Number(args?.at);
2434+
2435+ // Convert possible depth parameter to index
2436+ if (!isNaN(insertAt) && (insertAt < 0 || insertAt === Number(-0))) {
2437+ // Negative value means going back from current chat length. (E.g.: 8 messages, Depth 1 means insert at index 7)
2438+ insertAt = chat.length + insertAt;
2439+ }
24332440
24342441 if ('name' in args) {
24352442 const name = args.name || '';
@@ -2738,7 +2745,13 @@ export async function sendMessageAs(args, text) {
27382745 },
27392746 }];
27402747
27412748 constlet insertAt = Number(args.at);
2749+
2750+ // Convert possible depth parameter to index
2751+ if (!isNaN(insertAt) && (insertAt < 0 || insertAt === Number(-0))) {
2752+ // Negative value means going back from current chat length. (E.g.: 8 messages, Depth 1 means insert at index 7)
2753+ insertAt = chat.length + insertAt;
2754+ }
27422755
27432756 if (!isNaN(insertAt) && insertAt >= 0 && insertAt <= chat.length) {
27442757 chat.splice(insertAt, 0, message);
@@ -2785,7 +2798,13 @@ export async function sendNarratorMessage(args, text) {
27852798 },
27862799 };
27872800
27882801 constlet insertAt = Number(args.at);
2802+
2803+ // Convert possible depth parameter to index
2804+ if (!isNaN(insertAt) && (insertAt < 0 || insertAt === Number(-0))) {
2805+ // Negative value means going back from current chat length. (E.g.: 8 messages, Depth 1 means insert at index 7)
2806+ insertAt = chat.length + insertAt;
2807+ }
27892808
27902809 if (!isNaN(insertAt) && insertAt >= 0 && insertAt <= chat.length) {
27912810 chat.splice(insertAt, 0, message);
@@ -2867,7 +2886,13 @@ async function sendCommentMessage(args, text) {
28672886 },
28682887 };
28692888
28702889 constlet insertAt = Number(args.at);
2890+
2891+ // Convert possible depth parameter to index
2892+ if (!isNaN(insertAt) && (insertAt < 0 || insertAt === Number(-0))) {
2893+ // Negative value means going back from current chat length. (E.g.: 8 messages, Depth 1 means insert at index 7)
2894+ insertAt = chat.length + insertAt;
2895+ }
28712896
28722897 if (!isNaN(insertAt) && insertAt >= 0 && insertAt <= chat.length) {
28732898 chat.splice(insertAt, 0, message);