From 64f3960a1def7263ab47d7fbbc4ba1ae5195d31f Mon Sep 17 00:00:00 2001 From: "nise.moe" Date: Wed, 12 Jun 2024 12:55:06 +0200 Subject: [PATCH] Improved ban detection --- .../com/nisemoe/nise/scheduler/ImportUsers.kt | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/nise-backend/src/main/kotlin/com/nisemoe/nise/scheduler/ImportUsers.kt b/nise-backend/src/main/kotlin/com/nisemoe/nise/scheduler/ImportUsers.kt index cce0f02..deb23a7 100644 --- a/nise-backend/src/main/kotlin/com/nisemoe/nise/scheduler/ImportUsers.kt +++ b/nise-backend/src/main/kotlin/com/nisemoe/nise/scheduler/ImportUsers.kt @@ -103,7 +103,18 @@ class ImportUsers( val isUserBanned = this.osuApi.checkIfUserBanned(missingId) Thread.sleep(SLEEP_AFTER_API_CALL) - if (isUserBanned == true) { + + if(isUserBanned == null) { + this.logger.error("Failed to check if user $missingId is banned") + continue + } + + // If the user IS indeed banned, we update the user's status in the database if needed. + val isUserAlreadyBanned = dslContext.selectFrom(USERS) + .where(USERS.USER_ID.eq(missingId)) + .fetchOne(USERS.IS_BANNED) ?: false + + if(isUserBanned && !isUserAlreadyBanned) { this.logger.warn("User $missingId is banned") this.messagingTemplate.convertAndSend("/topic/banlist", missingId) dslContext.update(SCORES) @@ -116,6 +127,20 @@ class ImportUsers( .where(USERS.USER_ID.eq(missingId)) .execute() } + + if(!isUserBanned) { + this.logger.info("User $missingId is not banned") + + dslContext.update(USERS) + .set(USERS.IS_BANNED, false) + .where(USERS.USER_ID.eq(missingId)) + .execute() + + dslContext.update(SCORES) + .set(SCORES.IS_BANNED, false) + .where(SCORES.USER_ID.eq(missingId)) + .execute() + } } // Update the rest of the users