Various commands with 'at' support depth values

f7d3a1c942b338b43f28738bb4f5b41cb4b8f6cf

Wolfsblvt <wolfsblvt@gmx.de>

1 files changed, +33 -8Ignore whitespace
public/scripts/slash-commands.js+33 -8
@@ -177,7 +177,7 @@ export function initDefaultSlashCommands() {
177 ),177 ),
178 SlashCommandNamedArgument.fromProps({178 SlashCommandNamedArgument.fromProps({
179 name: 'at',179 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.',
181 typeList: [ARGUMENT_TYPE.NUMBER],181 typeList: [ARGUMENT_TYPE.NUMBER],
182 enumProvider: commonEnumProviders.messages({ allowIdAfter: true }),182 enumProvider: commonEnumProviders.messages({ allowIdAfter: true }),
183 }),183 }),
@@ -220,7 +220,7 @@ export function initDefaultSlashCommands() {
220 ),220 ),
221 SlashCommandNamedArgument.fromProps({221 SlashCommandNamedArgument.fromProps({
222 name: 'at',222 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.',
224 typeList: [ARGUMENT_TYPE.NUMBER],224 typeList: [ARGUMENT_TYPE.NUMBER],
225 enumProvider: commonEnumProviders.messages({ allowIdAfter: true }),225 enumProvider: commonEnumProviders.messages({ allowIdAfter: true }),
226 }),226 }),
@@ -274,7 +274,7 @@ export function initDefaultSlashCommands() {
274 ),274 ),
275 SlashCommandNamedArgument.fromProps({275 SlashCommandNamedArgument.fromProps({
276 name: 'at',276 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.',
278 typeList: [ARGUMENT_TYPE.NUMBER],278 typeList: [ARGUMENT_TYPE.NUMBER],
279 enumProvider: commonEnumProviders.messages({ allowIdAfter: true }),279 enumProvider: commonEnumProviders.messages({ allowIdAfter: true }),
280 }),280 }),
@@ -459,7 +459,7 @@ export function initDefaultSlashCommands() {
459 ),459 ),
460 SlashCommandNamedArgument.fromProps({460 SlashCommandNamedArgument.fromProps({
461 name: 'at',461 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.',
463 typeList: [ARGUMENT_TYPE.NUMBER],463 typeList: [ARGUMENT_TYPE.NUMBER],
464 enumProvider: commonEnumProviders.messages({ allowIdAfter: true }),464 enumProvider: commonEnumProviders.messages({ allowIdAfter: true }),
465 }),465 }),
@@ -2429,7 +2429,14 @@ async function sendUserMessageCallback(args, text) {
2429 text = text.trim();2429 text = text.trim();
2430 const compact = isTrueBoolean(args?.compact);2430 const compact = isTrueBoolean(args?.compact);
2431 const bias = extractMessageBias(text);2431 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
2434 if ('name' in args) {2441 if ('name' in args) {
2435 const name = args.name || '';2442 const name = args.name || '';
@@ -2738,7 +2745,13 @@ export async function sendMessageAs(args, text) {
2738 },2745 },
2739 }];2746 }];
27402747
2741 const insertAt = Number(args.at);2748 let 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
2743 if (!isNaN(insertAt) && insertAt >= 0 && insertAt <= chat.length) {2756 if (!isNaN(insertAt) && insertAt >= 0 && insertAt <= chat.length) {
2744 chat.splice(insertAt, 0, message);2757 chat.splice(insertAt, 0, message);
@@ -2785,7 +2798,13 @@ export async function sendNarratorMessage(args, text) {
2785 },2798 },
2786 };2799 };
27872800
2788 const insertAt = Number(args.at);2801 let 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
2790 if (!isNaN(insertAt) && insertAt >= 0 && insertAt <= chat.length) {2809 if (!isNaN(insertAt) && insertAt >= 0 && insertAt <= chat.length) {
2791 chat.splice(insertAt, 0, message);2810 chat.splice(insertAt, 0, message);
@@ -2867,7 +2886,13 @@ async function sendCommentMessage(args, text) {
2867 },2886 },
2868 };2887 };
28692888
2870 const insertAt = Number(args.at);2889 let 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
2872 if (!isNaN(insertAt) && insertAt >= 0 && insertAt <= chat.length) {2897 if (!isNaN(insertAt) && insertAt >= 0 && insertAt <= chat.length) {
2873 chat.splice(insertAt, 0, message);2898 chat.splice(insertAt, 0, message);