Skip to content

Commit

Permalink
增加 支持协议json目录前缀 (#83)
Browse files Browse the repository at this point in the history
* Update FixProtocolVersion.kt

支持协议文件前缀

* Update FixProtocolVersion.kt

* Update FixProtocolVersion.kt

* fix: CONFIG_PATH handle

---------

Co-authored-by: cssxsh <cssxsh@gmail.com>
  • Loading branch information
Alceatraz and cssxsh committed Sep 25, 2023
1 parent 85bde21 commit 27875d2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/main/kotlin/xyz/cssxsh/mirai/tool/FixProtocolVersion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,28 @@ public object FixProtocolVersion {
store(protocol, json)
}

@JvmStatic
public val CONFIG_PATH_PROPERTY: String = "xyz.cssxsh.mirai.tool.FixProtocolVersion.folder"

/**
* 从本地加载协议
*
* @since 1.8.0
*/
@JvmStatic
public fun load(protocol: BotConfiguration.MiraiProtocol) {
val file = File("${protocol.name.lowercase()}.json")
val prefix = System.getProperty(CONFIG_PATH_PROPERTY, ".")
val file = File(prefix, "${protocol.name.lowercase()}.json")
load(protocol = protocol, file = file)
}

/**
* 从自定义文件加载协议
*
* @since 1.12.0
*/
@JvmStatic
public fun load(protocol: BotConfiguration.MiraiProtocol, file: File) {
val json: JsonObject = Json.parseToJsonElement(file.readText()).jsonObject

store(protocol, json)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal object FixProtocolVersionPlugin : KotlinPlugin(
val file = File("${protocol.name.lowercase()}.json")
if (file.exists()) {
logger.info("$protocol load from \n ${file.toPath().toUri()}")
FixProtocolVersion.load(protocol)
FixProtocolVersion.load(protocol, file)
}
}
} catch (cause: Throwable) {
Expand Down

0 comments on commit 27875d2

Please sign in to comment.