Skip to content

Commit

Permalink
Only reply with 1 version
Browse files Browse the repository at this point in the history
Signed-off-by: shedaniel <[email protected]>
  • Loading branch information
shedaniel committed Mar 20, 2021
1 parent c2a49aa commit 489560e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ open class MavenPomVersionListener : ChannelListener<MavenPomVersionListener.Pom
runBlocking {
mavenListeners.forEach { (id, listener) ->
launch {
val newVersions = mutableSetOf<Version>()
val newVersions = mutableSetOf<Pair<Version, String>>()
val containsKey = newData.mavens.containsKey(id)
val mavenData = newData.mavens.getOrPut(id, ::mutableSetOf)
val rootElement = SAXReader().read(listener.mavenPomURL.readText().byteInputStream()).rootElement
Expand All @@ -69,13 +69,13 @@ open class MavenPomVersionListener : ChannelListener<MavenPomVersionListener.Pom
if (version.tryToVersion() == null) {
listener.messageSender(version, message)
} else {
newVersions.add(version.toVersion())
newVersions.add(version.toVersion() to version)
}
}
}

if (newVersions.isNotEmpty()) {
val latest = newVersions.maxOrNull()!!.toString()
val latest = newVersions.maxByOrNull { it.first }!!.second
listener.messageSender(latest, message)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,30 @@ object MinecraftVersionListener : ChannelListener<MinecraftVersionListener.Minec
runBlocking {
launch {
val versions = json.parseToJsonElement(URL("https://launchermeta.mojang.com/mc/game/version_manifest.json").readText()).jsonObject["versions"]!!.jsonArray
val reportVersion = mutableListOf<Pair<String, Boolean>>()
versions.forEach { versionElement ->
val id = versionElement.jsonObject["id"]!!.jsonPrimitive.content
val type = versionElement.jsonObject["type"]!!.jsonPrimitive.content
val url = versionElement.jsonObject["url"]!!.jsonPrimitive.content
val isUnstable = type != "release" || id.tryToVersion() == null || id.toVersion().snapshot != null

if (newData.versions.put(id, url) != url && data != null) {
message.reply {
setTitle("Minecraft Update")
setDescription("New Minecraft ${if (isUnstable) "snapshot" else "release"} has been released: $id")

setColor(Color.GREEN)
}.subscribe()
reportVersion.add(id to isUnstable)
}
}
reportVersion.mapNotNull { it.first.tryToVersion()?.to(it) }.maxByOrNull { it.first }?.second?.also { (version, isUnstable) ->
message.reply {
setTitle("Minecraft Update")
setDescription("New Minecraft ${if (isUnstable) "snapshot" else "release"} has been released: $version")

setColor(Color.GREEN)
}.subscribe()
}
}

launch {
val versions = json.parseToJsonElement(URL("https://bugs.mojang.com/rest/api/latest/project/MC/versions").readText()).jsonArray
val reportVersion = mutableListOf<Pair<String, Pair<String, Boolean>>>()
versions.forEach { versionElement ->
if (!versionElement.jsonObject["released"]!!.jsonPrimitive.boolean) return@forEach
val name = versionElement.jsonObject["name"]!!.jsonPrimitive.content.removePrefix("Minecraft ")
Expand All @@ -69,14 +74,17 @@ object MinecraftVersionListener : ChannelListener<MinecraftVersionListener.Minec
val isUnstable = name.tryToVersion() == null || name.toVersion().snapshot != null

if (newData.issueTrackerVersions.put(name, id) != id && data != null) {
message.reply {
setTitle("Minecraft Update")
setDescription("New Minecraft ${if (isUnstable) "snapshot" else "release"} has been added to the issue tracker: $id")

setColor(Color.GREEN)
}.subscribe()
reportVersion.add(id to (name to isUnstable))
}
}
reportVersion.mapNotNull { it.first.toIntOrNull()?.to(it) }.maxByOrNull { it.first }?.second?.second?.also { (version, isUnstable) ->
message.reply {
setTitle("Minecraft Update")
setDescription("New Minecraft ${if (isUnstable) "snapshot" else "release"} has been added to the issue tracker: $version")

setColor(Color.GREEN)
}.subscribe()
}
}
}

Expand Down

0 comments on commit 489560e

Please sign in to comment.