Skip to content

Commit

Permalink
Check temporarily banned users and renamed the function to a more des…
Browse files Browse the repository at this point in the history
…criptive one.
  • Loading branch information
PeterStark000 committed Jul 22, 2024
1 parent e204d67 commit 17f7928
Showing 1 changed file with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ import net.perfectdreams.loritta.helper.utils.ComponentDataUtils
import net.perfectdreams.loritta.helper.utils.Constants
import net.perfectdreams.loritta.helper.utils.GoogleDriveUtils
import net.perfectdreams.loritta.helper.utils.extensions.await
import net.perfectdreams.loritta.helper.utils.extensions.getBannedState
import org.jetbrains.exposed.sql.SortOrder
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.SqlExpressionBuilder.greaterEq
import org.jetbrains.exposed.sql.SqlExpressionBuilder.isNotNull
import org.jetbrains.exposed.sql.SqlExpressionBuilder.isNull
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.or
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.transaction
import java.awt.Color
import java.net.HttpURLConnection
Expand Down Expand Up @@ -273,13 +282,23 @@ class GenerateServerReport(val m: LorittaHelper) {
}
}

private fun checkIfUserIsLorittaBanned(
private fun getFancyUserId(
userId: Long
): String {
val userBanned = transaction(m.databases.lorittaDatabase) {
BannedUsers.selectFirstOrNull {
BannedUsers.userId eq userId
}
BannedUsers.select {
BannedUsers.userId eq userId and
(BannedUsers.valid eq true) and
(
BannedUsers.expiresAt.isNull()
or
(
BannedUsers.expiresAt.isNotNull() and
(BannedUsers.expiresAt greaterEq System.currentTimeMillis()))
)
}
.orderBy(BannedUsers.bannedAt, SortOrder.DESC)
.firstOrNull()
}

if (userBanned !== null) {
Expand Down Expand Up @@ -409,7 +428,7 @@ class GenerateServerReport(val m: LorittaHelper) {

embed.addField(
"ID do Usuário",
checkIfUserIsLorittaBanned(userId!!),
getFancyUserId(userId!!),
false
)

Expand Down Expand Up @@ -531,7 +550,7 @@ class GenerateServerReport(val m: LorittaHelper) {
embed.apply {
addField(
"ID do Usuário",
checkIfUserIsLorittaBanned(userId!!),
getFancyUserId(userId!!),
false
)

Expand Down Expand Up @@ -595,15 +614,15 @@ class GenerateServerReport(val m: LorittaHelper) {

embed.addField(
"ID do Usuário",
checkIfUserIsLorittaBanned(userId!!),
getFancyUserId(userId!!),
false
)

embed.addField(
"IDs das Contas Alternativas",
accountIds
.mapNotNull { it.toLongOrNull() }
.map { checkIfUserIsLorittaBanned(it) }
.map { getFancyUserId(it) }
.joinToString(", "),
false
)
Expand Down Expand Up @@ -661,15 +680,15 @@ class GenerateServerReport(val m: LorittaHelper) {

embed.addField(
"ID do Usuário",
checkIfUserIsLorittaBanned(userId!!),
getFancyUserId(userId!!),
false
)

embed.addField(
"IDs das Contas Alternativas",
accountIds
.mapNotNull { it.toLongOrNull() }
.map { checkIfUserIsLorittaBanned(it) }
.map { getFancyUserId(it) }
.joinToString(", "),
false
)
Expand Down

0 comments on commit 17f7928

Please sign in to comment.