Compare commits

...

3 commits

Author SHA1 Message Date
array-in-a-matrix 894700edd5 pnpm 2023-01-09 15:58:40 -05:00
array-in-a-matrix 4e8c2a6574 delete messages after n time passes 2023-01-09 15:58:19 -05:00
array-in-a-matrix 82eaae1d02 added key 2023-01-09 15:57:43 -05:00
4 changed files with 1178 additions and 14 deletions

View file

@ -2,6 +2,7 @@
"homeserver": "https://<DOMAIN.TLD>",
"token": "<TOKEN>",
"user": "@<USER>:<DOMAIN.TLD>",
"prefix": "!",
"time": "<HOUR>",
"key": "<PREFIX>"
}

View file

@ -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)
}
})
})

6
package.json Normal file
View file

@ -0,0 +1,6 @@
{
"dependencies": {
"matrix-bot-sdk": "^0.6.3"
},
"type": "module"
}

1161
pnpm-lock.yaml Normal file

File diff suppressed because it is too large Load diff