Merge pull request #2438 from SillyTavern/commands-send-at-supports-depth Various commands with 'at' support depth values

bf28ae07b338709d4201664aa8871270bae6372a

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

Signed
1 files changed, +33 -8Showing whitespace changes
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 }),
@@ -2490,7 +2490,14 @@ async function sendUserMessageCallback(args, text) {
2490 text = text.trim();2490 text = text.trim();
2491 const compact = isTrueBoolean(args?.compact);2491 const compact = isTrueBoolean(args?.compact);
2492 const bias = extractMessageBias(text);2492 const bias = extractMessageBias(text);
2493 const insertAt = Number(args?.at);2493
2494 let insertAt = Number(args?.at);
2495
2496 // Convert possible depth parameter to index
2497 if (!isNaN(insertAt) && (insertAt < 0 || insertAt === Number(-0))) {
2498 // Negative value means going back from current chat length. (E.g.: 8 messages, Depth 1 means insert at index 7)
2499 insertAt = chat.length + insertAt;
2500 }
24942501
2495 if ('name' in args) {2502 if ('name' in args) {
2496 const name = args.name || '';2503 const name = args.name || '';
@@ -2799,7 +2806,13 @@ export async function sendMessageAs(args, text) {
2799 },2806 },
2800 }];2807 }];
28012808
2802 const insertAt = Number(args.at);2809 let insertAt = Number(args.at);
2810
2811 // Convert possible depth parameter to index
2812 if (!isNaN(insertAt) && (insertAt < 0 || insertAt === Number(-0))) {
2813 // Negative value means going back from current chat length. (E.g.: 8 messages, Depth 1 means insert at index 7)
2814 insertAt = chat.length + insertAt;
2815 }
28032816
2804 if (!isNaN(insertAt) && insertAt >= 0 && insertAt <= chat.length) {2817 if (!isNaN(insertAt) && insertAt >= 0 && insertAt <= chat.length) {
2805 chat.splice(insertAt, 0, message);2818 chat.splice(insertAt, 0, message);
@@ -2846,7 +2859,13 @@ export async function sendNarratorMessage(args, text) {
2846 },2859 },
2847 };2860 };
28482861
2849 const insertAt = Number(args.at);2862 let insertAt = Number(args.at);
2863
2864 // Convert possible depth parameter to index
2865 if (!isNaN(insertAt) && (insertAt < 0 || insertAt === Number(-0))) {
2866 // Negative value means going back from current chat length. (E.g.: 8 messages, Depth 1 means insert at index 7)
2867 insertAt = chat.length + insertAt;
2868 }
28502869
2851 if (!isNaN(insertAt) && insertAt >= 0 && insertAt <= chat.length) {2870 if (!isNaN(insertAt) && insertAt >= 0 && insertAt <= chat.length) {
2852 chat.splice(insertAt, 0, message);2871 chat.splice(insertAt, 0, message);
@@ -2928,7 +2947,13 @@ async function sendCommentMessage(args, text) {
2928 },2947 },
2929 };2948 };
29302949
2931 const insertAt = Number(args.at);2950 let insertAt = Number(args.at);
2951
2952 // Convert possible depth parameter to index
2953 if (!isNaN(insertAt) && (insertAt < 0 || insertAt === Number(-0))) {
2954 // Negative value means going back from current chat length. (E.g.: 8 messages, Depth 1 means insert at index 7)
2955 insertAt = chat.length + insertAt;
2956 }
29322957
2933 if (!isNaN(insertAt) && insertAt >= 0 && insertAt <= chat.length) {2958 if (!isNaN(insertAt) && insertAt >= 0 && insertAt <= chat.length) {
2934 chat.splice(insertAt, 0, message);2959 chat.splice(insertAt, 0, message);