From 7bb470664d816b234dc7182eb8378cb492b31f17 Mon Sep 17 00:00:00 2001 From: leca Date: Wed, 7 Aug 2024 16:13:52 +0300 Subject: [PATCH] Bot now leaves from rooms which was left by users --- .gitignore | 1 + src/index.js | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index d290fb9..c7ae4f0 100644 --- a/.gitignore +++ b/.gitignore @@ -134,6 +134,7 @@ dist reg.js config.json +./config.json #Bot data encryption_bot_sled bot.json diff --git a/src/index.js b/src/index.js index 42d621c..dd0a3c5 100644 --- a/src/index.js +++ b/src/index.js @@ -22,6 +22,8 @@ import { appendUserPictures, checkForMutualLike, eraseUser, + eraseUserLikes, + eraseUserMedia, getAmountOfUserPictures, getCurrentUserAction, getUserCurrentlyViewingProfile, @@ -184,8 +186,14 @@ client.on("room.message", async (roomId, event) => { } }); -client.on("room.leave", async (roomId, event) => { - console.log(roomId, event); +client.on("room.event", async (roomId, event) => { + if (event.type === "m.room.member" && event.content?.membership === "leave") { + await eraseUser(roomId); + await eraseUserLikes(roomId); + await eraseUserMedia(roomId); + logInfo(`Bot has left a room with ID ${roomId}`) + client.leaveRoom(roomId); + } }) client.on("room.invite", async (roomId, event) => {