vanish/index.js
2023-01-09 15:58:19 -05:00

19 lines
923 B
JavaScript

import config from './config.json' assert {type: "json"};
import { MatrixClient, SimpleFsStorageProvider, AutojoinRoomsMixin } from "matrix-bot-sdk";
const storage = new SimpleFsStorageProvider("storage.json");
const client = new MatrixClient(config.homeserver, config.token, storage);
AutojoinRoomsMixin.setupOnClient(client);
client.start().then(() => console.log(`Vanishing messages...`));
let timeInMS = config.time * 3_600_000 //? converts hours to milliseconds
client.on("room.message", (roomId, event) => {
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)
}
})