Merge pull request #3147 from SillyTavern/off-by-one Fix -0 comparison
Signed| @@ -269,7 +269,7 @@ export function initDefaultSlashCommands() { | |||
| 269 | }), | 269 | }), |
| 270 | SlashCommandNamedArgument.fromProps({ | 270 | SlashCommandNamedArgument.fromProps({ |
| 271 | name: 'at', | 271 | name: 'at', |
| 272 | 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.', | 272 | 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.', |
| 273 | typeList: [ARGUMENT_TYPE.NUMBER], | 273 | typeList: [ARGUMENT_TYPE.NUMBER], |
| 274 | enumProvider: commonEnumProviders.messages({ allowIdAfter: true }), | 274 | enumProvider: commonEnumProviders.messages({ allowIdAfter: true }), |
| 275 | }), | 275 | }), |
| @@ -325,7 +325,7 @@ export function initDefaultSlashCommands() { | |||
| 325 | ), | 325 | ), |
| 326 | SlashCommandNamedArgument.fromProps({ | 326 | SlashCommandNamedArgument.fromProps({ |
| 327 | name: 'at', | 327 | name: 'at', |
| 328 | 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.', | 328 | 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.', |
| 329 | typeList: [ARGUMENT_TYPE.NUMBER], | 329 | typeList: [ARGUMENT_TYPE.NUMBER], |
| 330 | enumProvider: commonEnumProviders.messages({ allowIdAfter: true }), | 330 | enumProvider: commonEnumProviders.messages({ allowIdAfter: true }), |
| 331 | }), | 331 | }), |
| @@ -388,7 +388,7 @@ export function initDefaultSlashCommands() { | |||
| 388 | ), | 388 | ), |
| 389 | SlashCommandNamedArgument.fromProps({ | 389 | SlashCommandNamedArgument.fromProps({ |
| 390 | name: 'at', | 390 | name: 'at', |
| 391 | 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.', | 391 | 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.', |
| 392 | typeList: [ARGUMENT_TYPE.NUMBER], | 392 | typeList: [ARGUMENT_TYPE.NUMBER], |
| 393 | enumProvider: commonEnumProviders.messages({ allowIdAfter: true }), | 393 | enumProvider: commonEnumProviders.messages({ allowIdAfter: true }), |
| 394 | }), | 394 | }), |
| @@ -606,7 +606,7 @@ export function initDefaultSlashCommands() { | |||
| 606 | ), | 606 | ), |
| 607 | SlashCommandNamedArgument.fromProps({ | 607 | SlashCommandNamedArgument.fromProps({ |
| 608 | name: 'at', | 608 | name: 'at', |
| 609 | 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.', | 609 | 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.', |
| 610 | typeList: [ARGUMENT_TYPE.NUMBER], | 610 | typeList: [ARGUMENT_TYPE.NUMBER], |
| 611 | enumProvider: commonEnumProviders.messages({ allowIdAfter: true }), | 611 | enumProvider: commonEnumProviders.messages({ allowIdAfter: true }), |
| 612 | }), | 612 | }), |
| @@ -3025,7 +3025,7 @@ async function sendUserMessageCallback(args, text) { | |||
| 3025 | let insertAt = Number(args?.at); | 3025 | let insertAt = Number(args?.at); |
| 3026 | 3026 | ||
| 3027 | // Convert possible depth parameter to index | 3027 | // Convert possible depth parameter to index |
| 3028 | if (!isNaN(insertAt) && (insertAt < 0 || insertAt === Number(-0))) { | 3028 | if (!isNaN(insertAt) && (insertAt < 0 || Object.is(insertAt, -0))) { |
| 3029 | // Negative value means going back from current chat length. (E.g.: 8 messages, Depth 1 means insert at index 7) | 3029 | // Negative value means going back from current chat length. (E.g.: 8 messages, Depth 1 means insert at index 7) |
| 3030 | insertAt = chat.length + insertAt; | 3030 | insertAt = chat.length + insertAt; |
| 3031 | } | 3031 | } |
| @@ -3399,7 +3399,7 @@ export async function sendMessageAs(args, text) { | |||
| 3399 | let insertAt = Number(args.at); | 3399 | let insertAt = Number(args.at); |
| 3400 | 3400 | ||
| 3401 | // Convert possible depth parameter to index | 3401 | // Convert possible depth parameter to index |
| 3402 | if (!isNaN(insertAt) && (insertAt < 0 || insertAt === Number(-0))) { | 3402 | if (!isNaN(insertAt) && (insertAt < 0 || Object.is(insertAt, -0))) { |
| 3403 | // Negative value means going back from current chat length. (E.g.: 8 messages, Depth 1 means insert at index 7) | 3403 | // Negative value means going back from current chat length. (E.g.: 8 messages, Depth 1 means insert at index 7) |
| 3404 | insertAt = chat.length + insertAt; | 3404 | insertAt = chat.length + insertAt; |
| 3405 | } | 3405 | } |
| @@ -3453,7 +3453,7 @@ export async function sendNarratorMessage(args, text) { | |||
| 3453 | let insertAt = Number(args.at); | 3453 | let insertAt = Number(args.at); |
| 3454 | 3454 | ||
| 3455 | // Convert possible depth parameter to index | 3455 | // Convert possible depth parameter to index |
| 3456 | if (!isNaN(insertAt) && (insertAt < 0 || insertAt === Number(-0))) { | 3456 | if (!isNaN(insertAt) && (insertAt < 0 || Object.is(insertAt, -0))) { |
| 3457 | // Negative value means going back from current chat length. (E.g.: 8 messages, Depth 1 means insert at index 7) | 3457 | // Negative value means going back from current chat length. (E.g.: 8 messages, Depth 1 means insert at index 7) |
| 3458 | insertAt = chat.length + insertAt; | 3458 | insertAt = chat.length + insertAt; |
| 3459 | } | 3459 | } |
| @@ -3542,7 +3542,7 @@ async function sendCommentMessage(args, text) { | |||
| 3542 | let insertAt = Number(args.at); | 3542 | let insertAt = Number(args.at); |
| 3543 | 3543 | ||
| 3544 | // Convert possible depth parameter to index | 3544 | // Convert possible depth parameter to index |
| 3545 | if (!isNaN(insertAt) && (insertAt < 0 || insertAt === Number(-0))) { | 3545 | if (!isNaN(insertAt) && (insertAt < 0 || Object.is(insertAt, -0))) { |
| 3546 | // Negative value means going back from current chat length. (E.g.: 8 messages, Depth 1 means insert at index 7) | 3546 | // Negative value means going back from current chat length. (E.g.: 8 messages, Depth 1 means insert at index 7) |
| 3547 | insertAt = chat.length + insertAt; | 3547 | insertAt = chat.length + insertAt; |
| 3548 | } | 3548 | } |