Skip to content

Commit

Permalink
Add dupeignore/dupeunignore
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPowerGamerBR committed Oct 23, 2024
1 parent f12b35c commit 99ccd70
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -123,7 +120,8 @@ class LorittaHelper(val config: LorittaHelperConfig, val fanArtsConfig: FanArtsC
SelectedResponsesLog,
StaffProcessedReports,
StartedSupportSolicitations,
TicketMessagesActivity
TicketMessagesActivity,
LorittaAutoModIgnoredClientIds
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 99ccd70

Please sign in to comment.