Skip to content

Commit

Permalink
Log improvements (#75)
Browse files Browse the repository at this point in the history
* Make mods aware of their location

* Add processor to request crash reports

* Add fabric apis on quilt processor

* Add the two new processors

* Fix some names

* Update regexes
This allows parsing crash report mod tables, it wasn't working before. The change doesn't break anything
  • Loading branch information
Jamalam360 committed Aug 1, 2023
1 parent 84fd490 commit 4a1d098
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 19 deletions.
1 change: 1 addition & 0 deletions module-log-parser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ yourself.
- Detection for mods that make use of internal Fabric types
- Detection for mods that are marked incompatible on [Quilt's forum](https://forum.quiltmc.org/t/mod-incompatibility-megathread/261)
- Detection for out-of-date installations of Quilt Loader and QSL/QFAPI
- Detection for the presence of Fabric API or Fabric Language Kotlin
- **Piracy launcher detection (optional):** Bails when authentication fails or TLauncher is detected
- **Player IP warning:** Warns users when they upload a log containing player IP addresses
- **Problematic launcher detection (optional):** Bails when PolyMC is detected and explains why it shouldn't be used
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,8 @@ import org.quiltmc.community.cozy.modules.logs.parsers.launchers.ATLauncherParse
import org.quiltmc.community.cozy.modules.logs.parsers.launchers.MMCLikeParser
import org.quiltmc.community.cozy.modules.logs.parsers.launchers.TechnicParser
import org.quiltmc.community.cozy.modules.logs.parsers.quilt.QuiltModsParser
import org.quiltmc.community.cozy.modules.logs.processors.JavaClassFileVersionProcessor
import org.quiltmc.community.cozy.modules.logs.processors.MixinErrorProcessor
import org.quiltmc.community.cozy.modules.logs.processors.PlayerIPProcessor
import org.quiltmc.community.cozy.modules.logs.processors.UnknownModProcessor
import org.quiltmc.community.cozy.modules.logs.processors.quilt.FabricImplProcessor
import org.quiltmc.community.cozy.modules.logs.processors.quilt.IncompatibleModProcessor
import org.quiltmc.community.cozy.modules.logs.processors.quilt.QuiltLibrariesVersionProcessor
import org.quiltmc.community.cozy.modules.logs.processors.quilt.QuiltLoaderVersionProcessor
import org.quiltmc.community.cozy.modules.logs.processors.*
import org.quiltmc.community.cozy.modules.logs.processors.quilt.*
import org.quiltmc.community.cozy.modules.logs.retrievers.AttachmentLogRetriever
import org.quiltmc.community.cozy.modules.logs.retrievers.PastebinLogRetriever
import org.quiltmc.community.cozy.modules.logs.types.LogParser
Expand Down Expand Up @@ -54,8 +48,10 @@ public class SimpleLogParserConfig(private val builder: Builder) : LogParserConf
)

public var processors: MutableList<LogProcessor> = mutableListOf(
FabricApisProcessor(),
FabricImplProcessor(),
IncompatibleModProcessor(),
CrashReportProcessor(),
JavaClassFileVersionProcessor(),
MixinErrorProcessor(),
PlayerIPProcessor(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ import org.quiltmc.community.cozy.modules.logs.Version

public data class Mod(
val id: String,
val version: Version
val version: Version,
// Only present on Quilt Loader
val path: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.quiltmc.community.cozy.modules.logs.data.Order
import org.quiltmc.community.cozy.modules.logs.types.LogParser

private val PATTERNS = mapOf(
"\n\\|[\\s\\d]+\\| Quilt Loader\\s+\\| quilt_loader\\s+\\| (\\S+).+\n"
"\\| Quilt Loader\\s+\\| quilt_loader\\s+\\| (\\S+).+"
.toRegex(RegexOption.IGNORE_CASE) to LoaderType.Quilt, // Quilt mods table

": Loading .+ with Quilt Loader (\\S+)".toRegex(RegexOption.IGNORE_CASE) to LoaderType.Quilt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.quiltmc.community.cozy.modules.logs.types.LogParser
private val PATTERNS = listOf(
// Impossible to do this for vanilla; the logs don't contain the MC version for some reason

"\n\\|[\\s\\d]+\\| Minecraft\\s+\\| minecraft\\s+\\| (\\S+).+\n"
"\\| Minecraft\\s+\\| minecraft\\s+\\| (\\S+).+"
.toRegex(RegexOption.IGNORE_CASE), // Quilt mods table

": Loading Minecraft (\\S+)".toRegex(RegexOption.IGNORE_CASE), // Fabric, Quilt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public class FabricModsParser : LogParser() {
log.addMod(
Mod(
split.first(),
Version(split.last())
Version(split.last()),
null
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.quiltmc.community.cozy.modules.logs.types.LogParser
private val OPENING_LINES = arrayOf(
"Loading \\d+ mods:\n".toRegex(RegexOption.IGNORE_CASE),
"-- Mods --\n".toRegex(RegexOption.IGNORE_CASE),
"-- Mod Table --\n".toRegex(RegexOption.IGNORE_CASE),
"\tQuilt Mods: \n".toRegex(RegexOption.IGNORE_CASE),
)

Expand All @@ -27,8 +28,7 @@ public class QuiltModsParser : LogParser() {
override val identifier: String = "mods-quilt"
override val order: Order = Order.Default

override suspend fun predicate(log: Log, event: Event): Boolean =
log.getLoaderVersion(LoaderType.Quilt) != null
override suspend fun predicate(log: Log, event: Event): Boolean = log.getLoaderVersion(LoaderType.Quilt) != null

override suspend fun process(log: Log) {
val openingLine = OPENING_LINES.first { it in log.content }
Expand Down Expand Up @@ -72,7 +72,8 @@ public class QuiltModsParser : LogParser() {
log.addMod(
Mod(
mod["id"]!!,
Version(mod["version"]!!)
Version(mod["version"]!!),
mod["file(s)"]
)
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

package org.quiltmc.community.cozy.modules.logs.processors

import dev.kord.core.event.Event
import org.quiltmc.community.cozy.modules.logs.data.Log
import org.quiltmc.community.cozy.modules.logs.data.Order
import org.quiltmc.community.cozy.modules.logs.types.LogProcessor

private val CRASH_REPORT_REGEX = "Crashed! The full crash report has been saved to (\\S+)"
.toRegex(RegexOption.IGNORE_CASE)

public class CrashReportProcessor : LogProcessor() {
override val identifier: String = "crash-reports"
override val order: Order = Order.Default

override suspend fun predicate(log: Log, event: Event): Boolean =
CRASH_REPORT_REGEX.find(log.content) != null

override suspend fun process(log: Log) {
val match = CRASH_REPORT_REGEX.find(log.content) ?: return
log.addMessage("Please also provide the crash report at `${match.groups[1]!!.value}`")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private val VERSION_MAP = mutableMapOf(
)

public class JavaClassFileVersionProcessor : LogProcessor() {
override val identifier: String = "piracy"
override val identifier: String = "java-class-file-version"
override val order: Order = Order.Earlier

override suspend fun predicate(log: Log, event: Event): Boolean =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private val MIXIN_ERROR_REGEXES = arrayOf(
)

public class MixinErrorProcessor : LogProcessor() {
override val identifier: String = "piracy"
override val identifier: String = "mixin-error"
override val order: Order = Order.Earlier

override suspend fun process(log: Log) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.quiltmc.community.cozy.modules.logs.types.LogProcessor
private val UNKNOWN_MOD_REGEX = "Unknown file in mods folder: <mods>[\\\\/]([^\n]+)\n".toRegex(RegexOption.IGNORE_CASE)

public class UnknownModProcessor : LogProcessor() {
override val identifier: String = "piracy"
override val identifier: String = "unknown-mod"
override val order: Order = Order.Earlier

override suspend fun predicate(log: Log, event: Event): Boolean =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

package org.quiltmc.community.cozy.modules.logs.processors.quilt

import dev.kord.core.event.Event
import org.quiltmc.community.cozy.modules.logs.data.LoaderType
import org.quiltmc.community.cozy.modules.logs.data.Log
import org.quiltmc.community.cozy.modules.logs.data.Order
import org.quiltmc.community.cozy.modules.logs.types.LogProcessor

public class FabricApisProcessor : LogProcessor() {
override val identifier: String = "quilt-fabric-apis"
override val order: Order = Order.Default

override suspend fun predicate(log: Log, event: Event): Boolean =
log.getLoaderVersion(LoaderType.Quilt) != null

override suspend fun process(log: Log) {
val fabricApi = log.getMod("fabric")
val fabricLanguageKotlin = log.getMod("fabric-language-kotlin")

if (fabricApi != null) {
log.hasProblems = true

log.addMessage(
"Fabric API is present at `${fabricApi.path}`, and should be replaced by [QSL](https://modrinth.com/mod/qsl)"
)
}

if (fabricLanguageKotlin != null) {
log.hasProblems = true

log.addMessage(
"Fabric Language Kotlin is present at `${fabricLanguageKotlin.path}`, " +
"and should be replaced by [QKL](https://modrinth.com/mod/qkl)"
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import org.quiltmc.community.cozy.modules.logs.data.Order
import org.quiltmc.community.cozy.modules.logs.types.LogProcessor

public class QuiltLoaderVersionProcessor : LogProcessor() {
override val identifier: String = "fabric-loader-version"
override val identifier: String = "quilt-loader-version"
override val order: Order = Order.Default

private val metaClient = QuiltMetaClient()
Expand Down

0 comments on commit 4a1d098

Please sign in to comment.