-
-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c86964c
commit bb82cb9
Showing
4 changed files
with
530 additions
and
0 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
...rator/src/main/kotlin/net/perfectdreams/loritta/loricoolcards/generator/DailyCheckTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package net.perfectdreams.loritta.loricoolcards.generator | ||
|
||
import io.ktor.client.* | ||
import net.perfectdreams.loritta.cinnamon.pudding.Pudding | ||
import net.perfectdreams.loritta.cinnamon.pudding.services.UsersService.Companion.validBannedUsersList | ||
import net.perfectdreams.loritta.cinnamon.pudding.tables.BannedUsers | ||
import net.perfectdreams.loritta.cinnamon.pudding.tables.BrowserFingerprints | ||
import net.perfectdreams.loritta.cinnamon.pudding.tables.Dailies | ||
import net.perfectdreams.loritta.cinnamon.pudding.tables.Profiles | ||
import net.perfectdreams.loritta.loricoolcards.generator.utils.config.LoriCoolCardsGeneratorProductionStickersConfig | ||
import net.perfectdreams.loritta.morenitta.utils.readConfigurationFromFile | ||
import org.jetbrains.exposed.sql.and | ||
import org.jetbrains.exposed.sql.innerJoin | ||
import org.jetbrains.exposed.sql.selectAll | ||
import java.io.File | ||
import java.sql.Connection | ||
import java.time.Instant | ||
|
||
suspend fun main() { | ||
val http = HttpClient {} | ||
|
||
val configurationFile = File(System.getProperty("conf") ?: "./loricoolcards-production-stickers-generator.conf") | ||
|
||
if (!configurationFile.exists()) { | ||
println("Missing configuration file!") | ||
System.exit(1) | ||
return | ||
} | ||
|
||
val config = readConfigurationFromFile<LoriCoolCardsGeneratorProductionStickersConfig>(configurationFile) | ||
|
||
val pudding = Pudding.createPostgreSQLPudding( | ||
config.pudding.address, | ||
config.pudding.database, | ||
config.pudding.username, | ||
config.pudding.password | ||
) | ||
|
||
|
||
|
||
pudding.transaction(transactionIsolation = Connection.TRANSACTION_READ_UNCOMMITTED) { | ||
val now = Instant.now() | ||
.minusSeconds(604_800) // 7 days | ||
|
||
val dailiesRecentlyRetrievedHours = Dailies | ||
.innerJoin(BrowserFingerprints) | ||
.innerJoin(Profiles, { Profiles.id }, { Dailies.receivedById }) | ||
.selectAll() | ||
.where { | ||
Dailies.receivedAt greaterEq now.toEpochMilli() and (Dailies.receivedById notInSubQuery validBannedUsersList(now.toEpochMilli())) | ||
} | ||
.toList() | ||
|
||
val allClientIds = dailiesRecentlyRetrievedHours.map { it[BrowserFingerprints.clientId] } | ||
val alreadyChecked = mutableSetOf<Long>() | ||
|
||
allClientIds.chunked(10_000).forEach { clientIds -> | ||
val clientIdsThatAreBanned = Dailies | ||
.innerJoin(BrowserFingerprints) | ||
.innerJoin(BannedUsers, { Dailies.receivedById }, { BannedUsers.userId }) | ||
.selectAll() | ||
.where { | ||
BrowserFingerprints.clientId inList clientIds and (BannedUsers.userId inSubQuery validBannedUsersList(now.toEpochMilli())) | ||
} | ||
.toList() | ||
|
||
for (user in dailiesRecentlyRetrievedHours) { | ||
if (user[Dailies.receivedById] in alreadyChecked) | ||
continue | ||
|
||
val bannedUsersAssociatedWithThisUser = clientIdsThatAreBanned.filter { it[BrowserFingerprints.clientId] == user[BrowserFingerprints.clientId] } | ||
|
||
if (bannedUsersAssociatedWithThisUser.isNotEmpty()) { | ||
println("ban ${user[Dailies.receivedById]}") | ||
alreadyChecked.add(user[Dailies.receivedById]) | ||
} | ||
} | ||
} | ||
|
||
println("Finished! $alreadyChecked") | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...generator/src/main/kotlin/net/perfectdreams/loritta/loricoolcards/generator/GrepSorter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package net.perfectdreams.loritta.loricoolcards.generator | ||
|
||
import java.io.File | ||
import java.time.LocalDateTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
data class LogEntry(val timestamp: LocalDateTime, val content: String) | ||
|
||
fun parseTimestamp(logEntry: String): LocalDateTime { | ||
// Extract the timestamp part from the log entry using regex or string manipulation | ||
val timestampRegex = Regex("""\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3}""") | ||
val timestampString = timestampRegex.find(logEntry)?.value | ||
?: throw IllegalArgumentException("No valid timestamp found in the log entry.") | ||
|
||
// Define the formatter to match the log's timestamp format | ||
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss,SSS") | ||
|
||
// Parse the timestamp string to LocalDateTime | ||
return LocalDateTime.parse(timestampString, formatter) | ||
} | ||
|
||
fun processLogFile(file: File): List<LogEntry> { | ||
// Read the entire file content | ||
val content = file.readText() | ||
|
||
// Split log entries by "--" | ||
val logEntries = content.split("--").filter { it.isNotBlank() } | ||
|
||
// Map log entries to LogEntry objects, parsing the timestamp | ||
return logEntries.map { logEntry -> | ||
LogEntry(timestamp = parseTimestamp(logEntry), content = logEntry.trim()) | ||
}.sortedBy { it.timestamp } | ||
} | ||
|
||
fun main() { | ||
// List of files to process | ||
val logFiles = listOf( | ||
File("C:\\Users\\leona\\Documents\\LorittaInteractionIssues\\webhooks-1.log"), | ||
File("C:\\Users\\leona\\Documents\\LorittaInteractionIssues\\webhooks-2.log"), | ||
File("C:\\Users\\leona\\Documents\\LorittaInteractionIssues\\webhooks-3.log"), | ||
File("C:\\Users\\leona\\Documents\\LorittaInteractionIssues\\webhooks-4.log"), | ||
File("C:\\Users\\leona\\Documents\\LorittaInteractionIssues\\webhooks-5.log"), | ||
File("C:\\Users\\leona\\Documents\\LorittaInteractionIssues\\webhooks-6.log"), | ||
File("C:\\Users\\leona\\Documents\\LorittaInteractionIssues\\webhooks-7.log"), | ||
File("C:\\Users\\leona\\Documents\\LorittaInteractionIssues\\webhooks-8.log"), | ||
File("C:\\Users\\leona\\Documents\\LorittaInteractionIssues\\webhooks-9.log"), | ||
File("C:\\Users\\leona\\Documents\\LorittaInteractionIssues\\webhooks-10.log"), | ||
File("C:\\Users\\leona\\Documents\\LorittaInteractionIssues\\webhooks-11.log"), | ||
File("C:\\Users\\leona\\Documents\\LorittaInteractionIssues\\webhooks-12.log"), | ||
File("C:\\Users\\leona\\Documents\\LorittaInteractionIssues\\webhooks-13.log"), | ||
File("C:\\Users\\leona\\Documents\\LorittaInteractionIssues\\webhooks-14.log"), | ||
File("C:\\Users\\leona\\Documents\\LorittaInteractionIssues\\webhooks-15.log"), | ||
File("C:\\Users\\leona\\Documents\\LorittaInteractionIssues\\webhooks-16.log"), | ||
) | ||
|
||
// Process each file and sort the entries by timestamp | ||
val outputLogFile = File("C:\\Users\\leona\\Documents\\LorittaInteractionIssues\\output.log") | ||
val sortedEntries = mutableListOf<LogEntry>() | ||
for (logFile in logFiles) { | ||
println("Processing file: ${logFile.name}") | ||
|
||
// Get sorted log entries | ||
try { | ||
sortedEntries.addAll(processLogFile(logFile)) | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} | ||
} | ||
|
||
sortedEntries.groupBy { it.timestamp.hour.toString().padStart(2, '0') + ":" + it.timestamp.minute.toString().padStart(2, '0') } | ||
.toList() | ||
.sortedBy { it.first } | ||
.forEach { (t, u) -> | ||
println("$t: ${u.size}") | ||
} | ||
|
||
|
||
/* sortedEntries.filter { it.content.contains("COMBO") }.groupBy { it.timestamp.hour.toString().padStart(2, '0') + ":" + it.timestamp.minute.toString().padStart(2, '0') } | ||
.toList() | ||
.sortedBy { it.first } | ||
.forEach { (t, u) -> | ||
println("$t: ${u.size}") | ||
} */ | ||
|
||
// Print sorted log entries | ||
for (entry in sortedEntries.sortedBy { it.timestamp }) { | ||
// outputLogFile.appendText("--\n${entry.content}\n--") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.