From 4e8c2a6574da9e409c8f8b8ae610bd1df11d1b2d Mon Sep 17 00:00:00 2001 From: array-in-a-matrix Date: Mon, 9 Jan 2023 15:58:19 -0500 Subject: [PATCH] delete messages after n time passes --- index.js | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 9b78f5f..d5911ea 100644 --- a/index.js +++ b/index.js @@ -5,19 +5,15 @@ const storage = new SimpleFsStorageProvider("storage.json"); const client = new MatrixClient(config.homeserver, config.token, storage); AutojoinRoomsMixin.setupOnClient(client); -client.start().then(() => console.log(`Client has started!`)); +client.start().then(() => console.log(`Vanishing messages...`)); + +let timeInMS = config.time * 3_600_000 //? converts hours to milliseconds -// ? event listener client.on("room.message", (roomId, event) => { - // ? check if the message's text is not empty and isn't sent by the bot itself - if (! event["content"] || event["sender"] === config.user) return; - // ? if message starts with the bot's then execute the command - if (event["content"]["body"].toLowerCase().startsWith(config.prefix + "COMMAND")){ - - // - // TODO: START CODE HERE - // - + if (event["sender"] === config.user) { + if (event["content"]["body"].startsWith(config.key)) return; //? if message starts with the key do NOT delete that message + console.table([roomId, event["content"]["body"]]) + function redactMessage(){client.redactEvent(roomId, event["event_id"], "Vanish")} //? define callback function + setTimeout(redactMessage, timeInMS) } -}) - +}) \ No newline at end of file