From aa65cbf8a16ac8f097d5f01a53c3abce2649e460 Mon Sep 17 00:00:00 2001 From: carrot <68383195+AnnikaV9@users.noreply.github.com> Date: Tue, 21 Nov 2023 22:31:15 +0800 Subject: [PATCH 1/5] Fix typo in `updateMessage` usage info --- commands/core/updateMessage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/core/updateMessage.js b/commands/core/updateMessage.js index 564a936..9318420 100644 --- a/commands/core/updateMessage.js +++ b/commands/core/updateMessage.js @@ -93,5 +93,5 @@ export const info = { category: 'core', description: 'Update a message you have sent.', usage: ` - API: { cmd: 'updateMessage', mode: 'overwrite'|'append'|'prepand', text: '',customId: '' }`, + API: { cmd: 'updateMessage', mode: 'overwrite'|'append'|'prepend', text: '', customId: '' }`, }; From b8fd2fb93175f15d0f19f4aa4f8a473f1e6a4735 Mon Sep 17 00:00:00 2001 From: carrot <68383195+AnnikaV9@users.noreply.github.com> Date: Tue, 21 Nov 2023 22:35:12 +0800 Subject: [PATCH 2/5] Add `complete` mode to `updateMessage` --- client/client.js | 4 ++++ commands/core/updateMessage.js | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/client/client.js b/client/client.js index f40e3f3..d40d779 100644 --- a/client/client.js +++ b/client/client.js @@ -412,6 +412,10 @@ var COMMANDS = { for (var i = 0; i < activeMessages.length; i++) { var msg = activeMessages[i]; if (msg.userid === args.userid && msg.customId === customId) { + if (mode === 'complete') { + activeMessages.splice(i, 1); + return; + } message = msg; break; } diff --git a/commands/core/updateMessage.js b/commands/core/updateMessage.js index 9318420..af1a6f1 100644 --- a/commands/core/updateMessage.js +++ b/commands/core/updateMessage.js @@ -3,14 +3,14 @@ import { isAdmin, isModerator } from "../utility/_UAC.js"; import { ACTIVE_MESSAGES, MAX_MESSAGE_ID_LENGTH } from "./chat.js"; export async function run({ core, server, socket, payload }) { - // undefined | "overwrite" | "append" | "prepend" + // undefined | "overwrite" | "append" | "prepend" | "complete" let mode = payload.mode; if (!mode) { mode = 'overwrite'; } - if (mode !== 'overwrite' && mode !== 'append' && mode !== 'prepend') { + if (mode !== 'overwrite' && mode !== 'append' && mode !== 'prepend' && mode !== 'complete') { return server.police.frisk(socket.address, 13); } @@ -93,5 +93,5 @@ export const info = { category: 'core', description: 'Update a message you have sent.', usage: ` - API: { cmd: 'updateMessage', mode: 'overwrite'|'append'|'prepend', text: '', customId: '' }`, + API: { cmd: 'updateMessage', mode: 'overwrite'|'append'|'prepend'|'complete', text: '', customId: '' }`, }; From 2ee96543ca29b88df8dae2fd8fe24004620b495a Mon Sep 17 00:00:00 2001 From: carrot <68383195+AnnikaV9@users.noreply.github.com> Date: Thu, 23 Nov 2023 09:52:51 +0800 Subject: [PATCH 3/5] Remove from `ACTIVE_MESSAGES` when sending `complete` --- commands/core/updateMessage.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/commands/core/updateMessage.js b/commands/core/updateMessage.js index af1a6f1..8d4e4cf 100644 --- a/commands/core/updateMessage.js +++ b/commands/core/updateMessage.js @@ -48,6 +48,9 @@ export async function run({ core, server, socket, payload }) { if (msg.userid === socket.userid && msg.customId === customId) { message = ACTIVE_MESSAGES[i]; + if (mode === 'complete') { + ACTIVE_MESSAGES.splice(i, 1); + } break; } } From 051d488c2168f98b1928e437621ec3f1feb12493 Mon Sep 17 00:00:00 2001 From: carrot <68383195+AnnikaV9@users.noreply.github.com> Date: Thu, 23 Nov 2023 17:42:49 +0800 Subject: [PATCH 4/5] Revert "Remove from `ACTIVE_MESSAGES` when sending `complete`" As it would cause race conditions. This reverts commit 2ee96543ca29b88df8dae2fd8fe24004620b495a. --- commands/core/updateMessage.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/commands/core/updateMessage.js b/commands/core/updateMessage.js index 8d4e4cf..af1a6f1 100644 --- a/commands/core/updateMessage.js +++ b/commands/core/updateMessage.js @@ -48,9 +48,6 @@ export async function run({ core, server, socket, payload }) { if (msg.userid === socket.userid && msg.customId === customId) { message = ACTIVE_MESSAGES[i]; - if (mode === 'complete') { - ACTIVE_MESSAGES.splice(i, 1); - } break; } } From 15135978cfe4d75dfa6c85fff5ad3b472e813e36 Mon Sep 17 00:00:00 2001 From: carrot <68383195+AnnikaV9@users.noreply.github.com> Date: Thu, 23 Nov 2023 18:07:24 +0800 Subject: [PATCH 5/5] Mark message for deletion on next cleanup --- commands/core/chat.js | 3 ++- commands/core/updateMessage.js | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/commands/core/chat.js b/commands/core/chat.js index 8c4cca1..5ba3dee 100644 --- a/commands/core/chat.js +++ b/commands/core/chat.js @@ -40,7 +40,7 @@ export function cleanActiveMessages() { const now = Date.now(); for (let i = 0; i < ACTIVE_MESSAGES.length; i++) { const message = ACTIVE_MESSAGES[i]; - if (now - message.sent > ACTIVE_TIMEOUT) { + if (now - message.sent > ACTIVE_TIMEOUT || message.toDelete) { ACTIVE_MESSAGES.splice(i, 1); i--; } @@ -62,6 +62,7 @@ export function addActiveMessage(customId, userid) { customId, userid, sent: Date.now(), + toDelete: false, }); } diff --git a/commands/core/updateMessage.js b/commands/core/updateMessage.js index af1a6f1..880d96c 100644 --- a/commands/core/updateMessage.js +++ b/commands/core/updateMessage.js @@ -48,6 +48,9 @@ export async function run({ core, server, socket, payload }) { if (msg.userid === socket.userid && msg.customId === customId) { message = ACTIVE_MESSAGES[i]; + if (mode === 'complete') { + ACTIVE_MESSAGES[i].toDelete = true; + } break; } }