mirror of
https://github.com/LamGC/ScalaBot.git
synced 2025-04-30 06:37:29 +00:00
fix(config): 修正 BotConfigSerializer 中使用的错误默认值.
由于默认值未及时变更, 导致出现默认值与预期不符的情况; 目前已调整了新的默认值获取方式, 以便于后续调整默认值.
This commit is contained in:
parent
128e33e545
commit
b8a99a4491
@ -9,7 +9,6 @@ import org.eclipse.aether.artifact.DefaultArtifact
|
|||||||
import org.eclipse.aether.repository.Authentication
|
import org.eclipse.aether.repository.Authentication
|
||||||
import org.eclipse.aether.repository.Proxy
|
import org.eclipse.aether.repository.Proxy
|
||||||
import org.eclipse.aether.util.repository.AuthenticationBuilder
|
import org.eclipse.aether.util.repository.AuthenticationBuilder
|
||||||
import org.telegram.telegrambots.meta.ApiConstants
|
|
||||||
import java.lang.reflect.Type
|
import java.lang.reflect.Type
|
||||||
import java.net.MalformedURLException
|
import java.net.MalformedURLException
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
@ -222,6 +221,8 @@ object ProxyConfigSerializer : JsonSerializer<ProxyConfig>, JsonDeserializer<Pro
|
|||||||
|
|
||||||
object BotConfigSerializer : JsonSerializer<BotConfig>, JsonDeserializer<BotConfig> {
|
object BotConfigSerializer : JsonSerializer<BotConfig>, JsonDeserializer<BotConfig> {
|
||||||
|
|
||||||
|
private val defaultConfig = BotConfig(account = BotAccount("__Default__", "__Default__", 0))
|
||||||
|
|
||||||
override fun serialize(src: BotConfig, typeOfSrc: Type, context: JsonSerializationContext): JsonElement {
|
override fun serialize(src: BotConfig, typeOfSrc: Type, context: JsonSerializationContext): JsonElement {
|
||||||
return JsonObject().apply {
|
return JsonObject().apply {
|
||||||
addProperty("enabled", src.enabled)
|
addProperty("enabled", src.enabled)
|
||||||
@ -247,14 +248,14 @@ object BotConfigSerializer : JsonSerializer<BotConfig>, JsonDeserializer<BotConf
|
|||||||
|
|
||||||
// 从 json 反序列化 BotConfig(使用构造函数)
|
// 从 json 反序列化 BotConfig(使用构造函数)
|
||||||
return BotConfig(
|
return BotConfig(
|
||||||
enabled = json.get("enabled")?.asBoolean ?: true,
|
enabled = json.get("enabled")?.asBoolean ?: defaultConfig.enabled,
|
||||||
account = context.deserialize(json.get("account"), BotAccount::class.java)!!,
|
account = context.deserialize(json.get("account"), BotAccount::class.java)!!,
|
||||||
disableBuiltInAbility = json.get("disableBuiltInAbility")?.asBoolean ?: false,
|
disableBuiltInAbility = json.get("disableBuiltInAbility")?.asBoolean ?: defaultConfig.disableBuiltInAbility,
|
||||||
autoUpdateCommandList = json.get("autoUpdateCommandList")?.asBoolean ?: false,
|
autoUpdateCommandList = json.get("autoUpdateCommandList")?.asBoolean ?: defaultConfig.autoUpdateCommandList,
|
||||||
extensions = context.deserialize(json.get("extensions"), object : TypeToken<Set<Artifact>>() {}.type)
|
extensions = context.deserialize(json.get("extensions"), object : TypeToken<Set<Artifact>>() {}.type)
|
||||||
?: emptySet(),
|
?: defaultConfig.extensions,
|
||||||
proxy = context.deserialize(json.get("proxy"), ProxyConfig::class.java) ?: ProxyConfig(),
|
proxy = context.deserialize(json.get("proxy"), ProxyConfig::class.java) ?: defaultConfig.proxy,
|
||||||
baseApiUrl = json.get("baseApiUrl")?.asString ?: ApiConstants.BASE_URL
|
baseApiUrl = json.get("baseApiUrl")?.asString ?: defaultConfig.baseApiUrl
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user