From e9fc488661571f67e38fc7e8f6499eed836c6e7e Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Wed, 4 Dec 2024 12:53:34 +0000 Subject: [PATCH 1/2] Properly check for -0 --- public/scripts/slash-commands.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index a5ef925d9..bf54f55e5 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -3025,7 +3025,7 @@ async function sendUserMessageCallback(args, text) { let insertAt = Number(args?.at); // Convert possible depth parameter to index - if (!isNaN(insertAt) && (insertAt < 0 || insertAt === Number(-0))) { + if (!isNaN(insertAt) && (insertAt < 0 || Object.is(insertAt, -0))) { // Negative value means going back from current chat length. (E.g.: 8 messages, Depth 1 means insert at index 7) insertAt = chat.length + insertAt; } @@ -3399,7 +3399,7 @@ export async function sendMessageAs(args, text) { let insertAt = Number(args.at); // Convert possible depth parameter to index - if (!isNaN(insertAt) && (insertAt < 0 || insertAt === Number(-0))) { + if (!isNaN(insertAt) && (insertAt < 0 || Object.is(insertAt, -0))) { // Negative value means going back from current chat length. (E.g.: 8 messages, Depth 1 means insert at index 7) insertAt = chat.length + insertAt; } @@ -3453,7 +3453,7 @@ export async function sendNarratorMessage(args, text) { let insertAt = Number(args.at); // Convert possible depth parameter to index - if (!isNaN(insertAt) && (insertAt < 0 || insertAt === Number(-0))) { + if (!isNaN(insertAt) && (insertAt < 0 || Object.is(insertAt, -0))) { // Negative value means going back from current chat length. (E.g.: 8 messages, Depth 1 means insert at index 7) insertAt = chat.length + insertAt; } @@ -3542,7 +3542,7 @@ async function sendCommentMessage(args, text) { let insertAt = Number(args.at); // Convert possible depth parameter to index - if (!isNaN(insertAt) && (insertAt < 0 || insertAt === Number(-0))) { + if (!isNaN(insertAt) && (insertAt < 0 || Object.is(insertAt, -0))) { // Negative value means going back from current chat length. (E.g.: 8 messages, Depth 1 means insert at index 7) insertAt = chat.length + insertAt; } From 23e59a1189dda4a665a66c6ff290a3575fb4947b Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Wed, 4 Dec 2024 12:57:02 +0000 Subject: [PATCH 2/2] Document that -0 is supported --- public/scripts/slash-commands.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index bf54f55e5..a36cdce2e 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -269,7 +269,7 @@ export function initDefaultSlashCommands() { }), SlashCommandNamedArgument.fromProps({ name: 'at', - 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.', + 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 (including -0) 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.', typeList: [ARGUMENT_TYPE.NUMBER], enumProvider: commonEnumProviders.messages({ allowIdAfter: true }), }), @@ -325,7 +325,7 @@ export function initDefaultSlashCommands() { ), SlashCommandNamedArgument.fromProps({ name: 'at', - 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.', + 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 (including -0) 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.', typeList: [ARGUMENT_TYPE.NUMBER], enumProvider: commonEnumProviders.messages({ allowIdAfter: true }), }), @@ -388,7 +388,7 @@ export function initDefaultSlashCommands() { ), SlashCommandNamedArgument.fromProps({ name: 'at', - 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.', + 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 (including -0) 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.', typeList: [ARGUMENT_TYPE.NUMBER], enumProvider: commonEnumProviders.messages({ allowIdAfter: true }), }), @@ -606,7 +606,7 @@ export function initDefaultSlashCommands() { ), SlashCommandNamedArgument.fromProps({ name: 'at', - 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.', + 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 (including -0) 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.', typeList: [ARGUMENT_TYPE.NUMBER], enumProvider: commonEnumProviders.messages({ allowIdAfter: true }), }),