Skip to content

Commit

Permalink
Update deps, improve MC news format (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
gdude2002 committed Mar 22, 2024
1 parent ae9d300 commit fc4cbd7
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ allprojects {
}

dependencies {
implementation("io.ktor:ktor-client-encoding:2.2.4")
detektPlugins(libs.detekt)
detektPlugins(libs.detekt.libraries)

Expand All @@ -64,6 +63,8 @@ dependencies {
implementation(libs.kmongo)
implementation(libs.rgxgen)

implementation(libs.ktor.client.encoding)

implementation(libs.kordex.annotations)
implementation(libs.kordex.core)
implementation(libs.kordex.mappings)
Expand Down
6 changes: 3 additions & 3 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ dependencies {
implementation(gradleApi())
implementation(localGroovy())

implementation(kotlin("gradle-plugin", version = "1.9.22"))
implementation(kotlin("serialization", version = "1.9.22"))
implementation(kotlin("gradle-plugin", version = "1.9.23"))
implementation(kotlin("serialization", version = "1.9.23"))

implementation("gradle.plugin.org.cadixdev.gradle", "licenser", "0.6.1")
implementation("com.github.jakemarsden", "git-hooks-gradle-plugin", "0.0.2")
implementation("com.google.devtools.ksp", "com.google.devtools.ksp.gradle.plugin", "1.9.22-1.0.17")
implementation("com.google.devtools.ksp", "com.google.devtools.ksp.gradle.plugin", "1.9.23-1.0.19")
implementation("io.gitlab.arturbosch.detekt", "detekt-gradle-plugin", "1.23.5")
// implementation("org.ec4j.editorconfig", "org.ec4j.editorconfig.gradle.plugin", "0.0.3")

Expand Down
14 changes: 8 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
[versions]
detekt = "1.23.5"
kotlin = "1.9.22"
kotlin = "1.9.23"
graphql = "7.0.2"

autolink = "0.11.0"
commons-text = "1.11.0"
excelkt = "1.0.2"
flexver = "1.1.1"
groovy = "3.0.20"
groovy = "3.0.21"
homoglyph = "1.2.1"
jansi = "2.4.1"
jsoup = "1.17.2"
kaml = "0.57.0"
kaml = "0.58.0"
kmongo = "4.11.0"
kordex = "1.8.0-SNAPSHOT"
kotlintest = "3.4.2"
ktor = "2.3.8"
ktor = "2.3.9"
kx-ser = "1.6.3"
logback = "1.5.1"
logback = "1.5.3"
logback-groovy = "1.14.5"
logging = "6.0.3"
moshi = "1.15.0"
moshi = "1.15.1"
rgxgen = "2.0"
semver = "1.4.2"

Expand Down Expand Up @@ -52,6 +52,8 @@ kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref =
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8" }
kotlintest = { module = "io.kotlintest:kotlintest-runner-junit5", version.ref = "kotlintest" }
ktor-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
ktor-client-encoding = { module = "io.ktor:ktor-client-encoding", version.ref = "ktor" }
ktor-content-negotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" }
kx-ser = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "kx-ser" }
logback = { module = "ch.qos.logback:logback-classic", version.ref = "logback" }
Expand Down
2 changes: 2 additions & 0 deletions module-log-parser/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ dependencies {

ksp(libs.kordex.annotationProcessor)

implementation(libs.ktor.client.cio)

implementation(libs.kordex.annotations)
implementation(libs.kordex.core)
implementation(libs.kordex.unsafe)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import org.quiltmc.community.cozy.modules.logs.events.DefaultEventHandler
import org.quiltmc.community.cozy.modules.logs.events.EventHandler
import org.quiltmc.community.cozy.modules.logs.events.PKEventHandler
import org.quiltmc.community.cozy.modules.logs.types.BaseLogHandler
import java.net.URI
import java.net.URL
import kotlin.time.Duration.Companion.minutes

Expand Down Expand Up @@ -96,7 +97,7 @@ public class LogParserExtension : Extension() {
}

val logs = (parseLinks(message.content) + message.attachments.map { it.url })
.map { URL(it) }
.map { URI(it).toURL() }
.map { handleLink(it, event) }
.flatten()
.filter {
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/org/quiltmc/community/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ suspend fun setupQuilt() = ExtensibleBot(DISCORD_TOKEN) {
}

extPhishing {
appName = "QuiltMC's Cozy Bot"
detectionAction = DetectionAction.Kick
logChannelName = "cozy-logs"
requiredCommandPermission = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ import com.kotlindiscord.kord.extensions.extensions.ephemeralSlashCommand
import com.kotlindiscord.kord.extensions.pagination.pages.Page
import com.kotlindiscord.kord.extensions.utils.scheduling.Scheduler
import com.kotlindiscord.kord.extensions.utils.scheduling.Task
import com.kotlindiscord.kord.extensions.utils.toReaction
import dev.kord.common.annotation.KordPreview
import dev.kord.common.entity.Permission
import dev.kord.common.entity.Snowflake
import dev.kord.core.behavior.channel.createMessage
import dev.kord.core.builder.components.emoji
import dev.kord.core.entity.ReactionEmoji
import dev.kord.core.entity.channel.NewsChannel
import dev.kord.core.entity.channel.TextChannel
import dev.kord.core.entity.channel.TopGuildMessageChannel
import dev.kord.rest.builder.message.EmbedBuilder
import dev.kord.rest.builder.message.MessageBuilder
import dev.kord.rest.builder.message.actionRow
import dev.kord.rest.builder.message.embed
import io.github.oshai.kotlinlogging.KotlinLogging
import io.ktor.client.*
Expand All @@ -49,7 +53,7 @@ private val LINK_REGEX = "<a href=\"(?<url>[^\"]+)\"[^>]*>(?<text>[^<]+)</a>".to

@Suppress("MagicNumber", "UnderscoresInNumericLiterals")
private val CHANNELS: List<Snowflake> = listOf(
// Snowflake(828218532671389736L), // Testing
// Snowflake(1220660330191917056L), // Testing
Snowflake(838805249271267398L), // Community
// Snowflake(834195264629243904L), // Toolchain
)
Expand Down Expand Up @@ -95,7 +99,7 @@ class MinecraftExtension : Extension() {
ephemeralSubCommand(::CheckArguments) {
name = "get"
description = "Retrieve the patch notes for a given Minecraft version, or the latest if not " +
"supplied."
"supplied."

action {
if (!::currentEntries.isInitialized) {
Expand All @@ -115,9 +119,7 @@ class MinecraftExtension : Extension() {
}

respond {
embed {
patchNotes(patch.get())
}
patchNotes(patch.get())
}
}
}
Expand Down Expand Up @@ -262,14 +264,17 @@ class MinecraftExtension : Extension() {
result = result.replace("<code>", "`")
result = result.replace("</code>", "`")

result = result.replace("[\n]*<h\\d+>[\n]*".toRegex(), "\n\n__**")
result = result.replace("[\n]*</h\\d+>[\n]*".toRegex(), "**__\n")
@Suppress("MagicNumber")
for (i in 1..6) {
result = result.replace("[\n]*<h$i>[\n]*".toRegex(), "\n\n${"#".repeat(i)} ")
result = result.replace("[\n]*</h$i>[\n]*".toRegex(), "\n")
}

result = result.replace("[\n]*<[ou]l>[\n]*".toRegex(), "\n\n")
result = result.replace("[\n]*</[ou]l>[\n]*".toRegex(), "\n\n")

result = result.replace("[\n]*</li>\n+<li>[\n]*".toRegex(), "\n**»** ")
result = result.replace("([\n]{2,})?<li>[\n]*".toRegex(), "\n**»** ")
result = result.replace("[\n]*</li>\n+<li>[\n]*".toRegex(), "\n- ")
result = result.replace("([\n]{2,})?<li>[\n]*".toRegex(), "\n- ")
result = result.replace("[\n]*</li>[\n]*".toRegex(), "\n\n")

val links = LINK_REGEX.findAll(result)
Expand Down Expand Up @@ -299,25 +304,34 @@ class MinecraftExtension : Extension() {
return result to 0
}

private fun EmbedBuilder.patchNotes(patchNote: PatchNote, maxLength: Int = 1000) {
private fun MessageBuilder.patchNotes(patchNote: PatchNote, maxLength: Int = 4000) {
val (truncated, remaining) = patchNote.body.formatHTML().truncateMarkdown(maxLength)

title = patchNote.title
color = DISCORD_GREEN

description = "[Full patch notes](https://quiltmc.org/mc-patchnotes/#${patchNote.version})\n\n"
description += truncated
actionRow {
linkButton("https://quiltmc.org/mc-patchnotes/#${patchNote.version}") {
label = "Read more..."

if (remaining > 0) {
description += "\n\n[... $remaining more lines]"
emoji("🔗".toReaction() as ReactionEmoji.Unicode)
}
}

thumbnail {
url = "$BASE_URL${patchNote.image.url}"
}
embed {
title = patchNote.title
color = DISCORD_GREEN

description = truncated

footer {
text = "URL: https://quiltmc.org/mc-patchnotes/#${patchNote.version}"
if (remaining > 0) {
description += "\n\n[... $remaining more lines]"
}

thumbnail {
url = "$BASE_URL${patchNote.image.url}"
}

footer {
text = "URL: https://quiltmc.org/mc-patchnotes/#${patchNote.version}"
}
}
}

Expand All @@ -327,7 +341,8 @@ class MinecraftExtension : Extension() {
if (guildId == COMMUNITY_GUILD) {
content = "<@&$MINECRAFT_UPDATE_PING_ROLE>"
}
embed { patchNotes(patchNote, maxLength) }

patchNotes(patchNote, maxLength)
}

val title = if (patchNote.title.startsWith("minecraft ", true)) {
Expand Down

0 comments on commit fc4cbd7

Please sign in to comment.