vanish/index.js

19 lines
923 B
JavaScript
Raw Normal View History

2023-01-09 13:23:14 -05:00
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);
2023-01-09 15:58:19 -05:00
client.start().then(() => console.log(`Vanishing messages...`));
2023-01-09 13:23:14 -05:00
2023-01-09 15:58:19 -05:00
let timeInMS = config.time * 3_600_000 //? converts hours to milliseconds
2023-01-09 13:23:14 -05:00
2023-01-09 15:58:19 -05:00
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)
2023-01-09 13:23:14 -05:00
}
2023-01-09 15:58:19 -05:00
})