From 9ce2ba6c204c071206827a8d040dc6e9e96145bb Mon Sep 17 00:00:00 2001 From: Tanish Khare Date: Sun, 25 Aug 2024 19:48:46 +0530 Subject: [PATCH] feat: remove htm from db if user doesn't have htm at time of leaving (#533) --- crates/robbb/src/events/guild_member_removal.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/robbb/src/events/guild_member_removal.rs b/crates/robbb/src/events/guild_member_removal.rs index c82b565b..a4c6beb1 100644 --- a/crates/robbb/src/events/guild_member_removal.rs +++ b/crates/robbb/src/events/guild_member_removal.rs @@ -24,8 +24,14 @@ pub async fn guild_member_removal( if let Some(member) = member { let roles = member.roles(&ctx).unwrap_or_default(); - if roles.iter().any(|x| x.id == config.role_htm) { + let is_htm = db.check_user_htm(member.user.id).await?; // check if already htm is added to DB + + if roles.iter().any(|x| x.id == config.role_htm) && !is_htm { + // add htm if not in db already log_error!(db.add_htm(member.user.id).await); + } else { + // remove htm from db if user doesn't have htm anymore + log_error!(db.remove_htm(member.user.id).await); } }