generated from array-in-a-matrix/matrix-bot-template
delete messages after n time passes
This commit is contained in:
parent
82eaae1d02
commit
4e8c2a6574
22
index.js
22
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 <prefix + command> 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)
|
||||
}
|
||||
})
|
||||
|
||||
})
|
Loading…
Reference in a new issue