mirror of
https://github.com/hack-chat/main.git
synced 2024-03-22 13:20:33 +08:00
Merge pull request #224 from AnnikaV9/version-2-dev
Add `complete` mode to `updateMessage`
This commit is contained in:
commit
b3c885f44c
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -93,5 +96,5 @@ export const info = {
|
|||
category: 'core',
|
||||
description: 'Update a message you have sent.',
|
||||
usage: `
|
||||
API: { cmd: 'updateMessage', mode: 'overwrite'|'append'|'prepand', text: '<text to apply>',customId: '<customId sent with the chat message>' }`,
|
||||
API: { cmd: 'updateMessage', mode: 'overwrite'|'append'|'prepend'|'complete', text: '<text to apply>', customId: '<customId sent with the chat message>' }`,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user