diff --git a/src/main/kotlin/net/perfectdreams/loritta/helper/LorittaHelper.kt b/src/main/kotlin/net/perfectdreams/loritta/helper/LorittaHelper.kt index e0093fb..cec14e8 100644 --- a/src/main/kotlin/net/perfectdreams/loritta/helper/LorittaHelper.kt +++ b/src/main/kotlin/net/perfectdreams/loritta/helper/LorittaHelper.kt @@ -20,10 +20,7 @@ import net.perfectdreams.loritta.helper.interactions.commands.vanilla.* import net.perfectdreams.loritta.helper.interactions.commands.vanilla.ButtonRoleSenderCommand import net.perfectdreams.loritta.helper.listeners.* import net.perfectdreams.loritta.helper.network.Databases -import net.perfectdreams.loritta.helper.tables.SelectedResponsesLog -import net.perfectdreams.loritta.helper.tables.StaffProcessedReports -import net.perfectdreams.loritta.helper.tables.StartedSupportSolicitations -import net.perfectdreams.loritta.helper.tables.TicketMessagesActivity +import net.perfectdreams.loritta.helper.tables.* import net.perfectdreams.loritta.helper.utils.LanguageManager import net.perfectdreams.loritta.helper.utils.LorittaLandRoleSynchronizationTask import net.perfectdreams.loritta.helper.utils.StaffProcessedReportResult @@ -123,7 +120,8 @@ class LorittaHelper(val config: LorittaHelperConfig, val fanArtsConfig: FanArtsC SelectedResponsesLog, StaffProcessedReports, StartedSupportSolicitations, - TicketMessagesActivity + TicketMessagesActivity, + LorittaAutoModIgnoredClientIds ) } diff --git a/src/main/kotlin/net/perfectdreams/loritta/helper/interactions/commands/vanilla/LoriToolsCommand.kt b/src/main/kotlin/net/perfectdreams/loritta/helper/interactions/commands/vanilla/LoriToolsCommand.kt index a86bf00..921b391 100644 --- a/src/main/kotlin/net/perfectdreams/loritta/helper/interactions/commands/vanilla/LoriToolsCommand.kt +++ b/src/main/kotlin/net/perfectdreams/loritta/helper/interactions/commands/vanilla/LoriToolsCommand.kt @@ -17,6 +17,7 @@ import net.dv8tion.jda.api.entities.UserSnowflake import net.perfectdreams.loritta.cinnamon.pudding.tables.BannedUsers import net.perfectdreams.loritta.helper.LorittaHelper import net.perfectdreams.loritta.helper.tables.EconomyState +import net.perfectdreams.loritta.helper.tables.LorittaAutoModIgnoredClientIds import net.perfectdreams.loritta.helper.utils.TimeUtils import net.perfectdreams.loritta.helper.utils.extensions.await import net.perfectdreams.loritta.helper.utils.slash.LoriToolsUtils @@ -39,6 +40,7 @@ import org.jetbrains.exposed.sql.SqlExpressionBuilder.isNull import org.jetbrains.exposed.sql.transactions.transaction import java.awt.Color import java.time.Duration +import java.time.Instant import java.time.LocalDateTime import java.time.ZoneId import java.time.format.DateTimeFormatter @@ -75,6 +77,14 @@ class LoriToolsCommand(val helper: LorittaHelper) : SlashCommandDeclarationWrapp subcommand("checkdupes", "Verifica pessoas evadindo ban") { executor = LoriCheckDupesExecutor(helper) } + + subcommand("dupeignore", "Adiciona um ID da whitelist") { + executor = LoriAddClientIdToIgnoredDupeListExecutor(helper) + } + + subcommand("dupeunignore", "Remove um ID da whitelist") { + executor = LoriRemoveClientIdFromIgnoredDupeListExecutor(helper) + } } companion object { @@ -689,6 +699,59 @@ class LoriToolsCommand(val helper: LorittaHelper) : SlashCommandDeclarationWrapp } } + class LoriAddClientIdToIgnoredDupeListExecutor(helper: LorittaHelper) : HelperExecutor(helper, PermissionLevel.ADMIN) { + inner class Options : ApplicationCommandOptions() { + val clientId = string("client_id", "Client ID") + val reason = string("reason", "O motivo de adicionar na lista de ignorar") + } + + override val options = Options() + + override suspend fun executeHelper(context: ApplicationCommandContext, args: SlashCommandArguments) { + val clientId = UUID.fromString(args[options.clientId]) + + transaction(helper.databases.helperDatabase) { + LorittaAutoModIgnoredClientIds.insert { + it[LorittaAutoModIgnoredClientIds.clientId] = clientId + it[LorittaAutoModIgnoredClientIds.addedBy] = context.user.idLong + it[LorittaAutoModIgnoredClientIds.addedAt] = Instant.now() + it[LorittaAutoModIgnoredClientIds.reason] = args[options.reason] + } + } + + context.reply(false) { + styled( + "Adicionado Client ID na lista de ignorar" + ) + } + } + } + + class LoriRemoveClientIdFromIgnoredDupeListExecutor(helper: LorittaHelper) : HelperExecutor(helper, PermissionLevel.ADMIN) { + inner class Options : ApplicationCommandOptions() { + val clientId = string("client_id", "Client ID") + val reason = string("reason", "O motivo de adicionar na lista de ignorar") + } + + override val options = Options() + + override suspend fun executeHelper(context: ApplicationCommandContext, args: SlashCommandArguments) { + val clientId = UUID.fromString(args[options.clientId]) + + transaction(helper.databases.helperDatabase) { + LorittaAutoModIgnoredClientIds.deleteWhere { + LorittaAutoModIgnoredClientIds.clientId eq clientId + } + } + + context.reply(false) { + styled( + "Removido Client ID da lista de ignorar" + ) + } + } + } + enum class PredefinedBanReason(val fancyName: String, val banReason: String, val duration: Duration) { ASKING_TO_BE_BANNED( "Pedir para ser banido", diff --git a/src/main/kotlin/net/perfectdreams/loritta/helper/tables/LorittaAutoModIgnoredClientIds.kt b/src/main/kotlin/net/perfectdreams/loritta/helper/tables/LorittaAutoModIgnoredClientIds.kt new file mode 100644 index 0000000..88750da --- /dev/null +++ b/src/main/kotlin/net/perfectdreams/loritta/helper/tables/LorittaAutoModIgnoredClientIds.kt @@ -0,0 +1,14 @@ +package net.perfectdreams.loritta.helper.tables + +import net.perfectdreams.exposedpowerutils.sql.javatime.timestampWithTimeZone +import net.perfectdreams.exposedpowerutils.sql.postgresEnumeration +import net.perfectdreams.loritta.helper.utils.StaffProcessedReportResult +import org.jetbrains.exposed.dao.id.LongIdTable +import org.jetbrains.exposed.dao.id.UUIDTable + +object LorittaAutoModIgnoredClientIds : LongIdTable() { + val clientId = uuid("client_id").index() + val addedAt = timestampWithTimeZone("added_at") + val addedBy = long("added_by") + val reason = text("reason") +} \ No newline at end of file diff --git a/src/main/kotlin/net/perfectdreams/loritta/helper/utils/lorittaautomods/CheckDupeClientIds.kt b/src/main/kotlin/net/perfectdreams/loritta/helper/utils/lorittaautomods/CheckDupeClientIds.kt index c9a8cd5..c9a7184 100644 --- a/src/main/kotlin/net/perfectdreams/loritta/helper/utils/lorittaautomods/CheckDupeClientIds.kt +++ b/src/main/kotlin/net/perfectdreams/loritta/helper/utils/lorittaautomods/CheckDupeClientIds.kt @@ -11,6 +11,7 @@ import net.perfectdreams.loritta.cinnamon.pudding.tablesrefactorlater.BrowserFin import net.perfectdreams.loritta.cinnamon.pudding.tablesrefactorlater.Dailies import net.perfectdreams.loritta.helper.LorittaHelper import net.perfectdreams.loritta.helper.interactions.commands.vanilla.LoriToolsCommand +import net.perfectdreams.loritta.helper.tables.LorittaAutoModIgnoredClientIds import net.perfectdreams.loritta.helper.utils.Emotes import net.perfectdreams.loritta.helper.utils.RunnableCoroutine import net.perfectdreams.loritta.helper.utils.extensions.await @@ -56,6 +57,14 @@ class CheckDupeClientIds(val helper: LorittaHelper) : RunnableCoroutine { channel.sendMessage("# ${Emotes.SUPER_VIEIRINHA} VERIFICAÇÃO DE MELIANTES - ${TimeFormat.DATE_TIME_SHORT.format(Instant.now())}\n${Emotes.LORI_COFFEE} Verificando meliantes que estão evadindo ban... *Verificação automática* - Ensaio? $dryRun").await() } + val whitelistedClientIds = transaction(helper.databases.helperDatabase) { + LorittaAutoModIgnoredClientIds.selectAll() + .map { + it[LorittaAutoModIgnoredClientIds.clientId] + } + .toSet() + } + val usersToBeBanned = transaction(helper.databases.lorittaDatabase) { val now = Instant.now() .minusSeconds(604_800) // 7 days @@ -88,6 +97,9 @@ class CheckDupeClientIds(val helper: LorittaHelper) : RunnableCoroutine { } for (user in dailiesRecentlyRetrievedHours) { + if (user[BrowserFingerprints.clientId] in whitelistedClientIds) + continue + if (user[Dailies.receivedById] in alreadyChecked) continue