Skip to content

Commit

Permalink
Check and sync up the versions in translation commands
Browse files Browse the repository at this point in the history
Signed-off-by: shedaniel <[email protected]>
  • Loading branch information
shedaniel committed Jun 13, 2021
1 parent 4afa94d commit a7f0017
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ repositories {
}

dependencies {
implementation("me.shedaniel:linkie-core:1.0.76") {
implementation("me.shedaniel:linkie-core:1.0.80") {
exclude module: "korio"
}
implementation("com.discord4j:discord4j-core:3.1.3") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package me.shedaniel.linkie.discord.commands
import discord4j.core.`object`.entity.User
import discord4j.core.`object`.entity.channel.MessageChannel
import discord4j.core.event.domain.message.MessageCreateEvent
import kotlinx.coroutines.runBlocking
import me.shedaniel.linkie.MappingsContainer
import me.shedaniel.linkie.MappingsEntryType
import me.shedaniel.linkie.MappingsProvider
Expand Down Expand Up @@ -126,7 +127,16 @@ open class QueryMappingsCommand(
else availableVersions.joinToString(", ")
)
}
mappingsProvider.injectDefaultVersion(namespace.getDefaultProvider())
mappingsProvider.injectDefaultVersion {
runBlocking {
val defaultProvider = namespace.getDefaultProvider()
if (availableVersions.contains(defaultProvider.version)) {
defaultProvider
} else {
namespace.getProvider(availableVersions.firstOrNull() ?: throw IllegalStateException("No available versions found!"))
}
}
}
mappingsProvider.validateDefaultVersionNotEmpty()
return mappingsProvider
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ import me.shedaniel.linkie.MappingsMetadata
import me.shedaniel.linkie.MappingsProvider
import me.shedaniel.linkie.Method
import me.shedaniel.linkie.Namespace
import me.shedaniel.linkie.discord.*
import me.shedaniel.linkie.discord.utils.*
import me.shedaniel.linkie.discord.MessageCreator
import me.shedaniel.linkie.discord.ValueKeeper
import me.shedaniel.linkie.discord.basicEmbed
import me.shedaniel.linkie.discord.sendPages
import me.shedaniel.linkie.discord.utils.buildSafeDescription
import me.shedaniel.linkie.discord.utils.buildString
import me.shedaniel.linkie.discord.utils.mapIfNotNullOrNotEquals
import me.shedaniel.linkie.discord.utils.optimumName
import me.shedaniel.linkie.getClassByObfName
import me.shedaniel.linkie.getObfMergedDesc
import me.shedaniel.linkie.obfMergedName
Expand All @@ -54,6 +60,10 @@ class QueryTranslateMappingsCommand(
val sourceMappingsVersion = getMappingsProvider(sourceNamespace, providedVersion, allVersions).version!!
val targetMappingsVersion = getMappingsProvider(targetNamespace, providedVersion, allVersions).version!!

require(sourceMappingsVersion == targetMappingsVersion) {
"Unmatched versions: $sourceMappingsVersion, $targetMappingsVersion! Please report this!"
}

val searchTerm = args.first().replace('.', '/')
val maxPage = AtomicInteger(-1)
val query = ValueKeeper(Duration.ofMinutes(2)) {
Expand Down

0 comments on commit a7f0017

Please sign in to comment.