Skip to content

Commit

Permalink
优化protocol插件结构、去除无用模块
Browse files Browse the repository at this point in the history
(cherry picked from commit 0f54cf79e674b687868a7400b67b5b3885267f55)
  • Loading branch information
FlapyPan committed Aug 20, 2023
1 parent b5c0097 commit 206091f
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 251 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import xyz.cssxsh.mirai.tool.Cola;
import xyz.cssxsh.mirai.tool.FixProtocolVersion;
import xyz.cssxsh.mirai.tool.KFCFactory;
import xyz.cssxsh.mirai.tool.sign.service.SignServiceConfig;
import xyz.cssxsh.mirai.tool.ProtocolVersionFixer;
import xyz.cssxsh.mirai.tool.sign.service.SignServiceFactory;

import java.io.File;

Expand Down Expand Up @@ -87,15 +87,15 @@ public Bot createBotByQrcode() {

private void fixProtocolVersion(String path){
RobotProperties.SignerConfig signer = properties.getSigner();
KFCFactory.initConfiguration(path, new Cola(
SignServiceFactory.initConfiguration(path, new SignServiceConfig(
signer.getUrl(),
signer.getType().toName(),
signer.getKey(),
signer.getServerIdentityKey(),
signer.getAuthorizationKey()
));
KFCFactory.install();
FixProtocolVersion.fetch(properties.getProtocol(), signer.getVersion());
SignServiceFactory.install();
ProtocolVersionFixer.fetch(properties.getProtocol(), signer.getVersion());
}

private void configureRobot(BotConfiguration configuration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@ package xyz.cssxsh.mirai.tool

import kotlinx.serialization.json.*
import net.mamoe.mirai.internal.utils.*
import net.mamoe.mirai.utils.*
import java.io.*
import java.net.*
import java.time.*
import net.mamoe.mirai.utils.BotConfiguration
import net.mamoe.mirai.utils.cast
import net.mamoe.mirai.utils.hexToBytes
import net.mamoe.mirai.utils.toUHexString
import xyz.cssxsh.mirai.tool.sign.service.SignServiceFactory
import java.io.File
import java.net.URL
import java.time.Instant
import java.time.OffsetDateTime
import java.time.ZoneId

/**
* 原名: FixProtocolVersion.
*/
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
object FixProtocolVersion {
object ProtocolVersionFixer {

private val clazz = MiraiProtocolInternal::class.java

Expand Down Expand Up @@ -245,21 +254,6 @@ object FixProtocolVersion {
}
}

/**
* 从 [RomiChan/protocol-versions](https://github.com/RomiChan/protocol-versions) 同步最新协议
*
* @since 1.6.0
*/
@Deprecated(
message = "sync 作用不明确,故废弃",
ReplaceWith(
"""fetch(protocol = protocol, version = "latest")""",
"xyz.cssxsh.mirai.tool.FixProtocolVersion.fetch"
)
)
@JvmStatic
fun sync(protocol: BotConfiguration.MiraiProtocol): Unit = fetch(protocol = protocol, version = "latest")

/**
* 从 [RomiChan/protocol-versions](https://github.com/RomiChan/protocol-versions) 获取指定版本协议
*
Expand All @@ -272,14 +266,14 @@ object FixProtocolVersion {
} else {
val (file, url) = when (protocol) {
BotConfiguration.MiraiProtocol.ANDROID_PHONE -> {
File(KFCFactory.workDir + "android_phone.json") to
File(SignServiceFactory.workDir + "android_phone.json") to
when (version) {
"", "latest" -> URL("https://raw.githubusercontent.com/RomiChan/protocol-versions/master/android_phone.json")
else -> URL("https://raw.githubusercontent.com/RomiChan/protocol-versions/master/android_phone/${version}.json")
}
}
BotConfiguration.MiraiProtocol.ANDROID_PAD -> {
File(KFCFactory.workDir + "android_pad.json") to
File(SignServiceFactory.workDir + "android_pad.json") to
when (version) {
"", "latest" -> URL("https://raw.githubusercontent.com/RomiChan/protocol-versions/master/android_pad.json")
else -> URL("https://raw.githubusercontent.com/RomiChan/protocol-versions/master/android_pad/${version}.json")
Expand Down Expand Up @@ -332,7 +326,7 @@ object FixProtocolVersion {
*/
@JvmStatic
private fun existsLocalFile(protocol: BotConfiguration.MiraiProtocol) : Boolean{
return File(KFCFactory.workDir + "${protocol.name.lowercase()}.json").exists()
return File(SignServiceFactory.workDir + "${protocol.name.lowercase()}.json").exists()
}

/**
Expand All @@ -342,7 +336,7 @@ object FixProtocolVersion {
*/
@JvmStatic
private fun load(protocol: BotConfiguration.MiraiProtocol) {
val file = File(KFCFactory.workDir + "${protocol.name.lowercase()}.json")
val file = File(SignServiceFactory.workDir + "${protocol.name.lowercase()}.json")
val json: JsonObject = Json.parseToJsonElement(file.readText()).jsonObject
store(protocol, json)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package xyz.cssxsh.mirai.tool
package xyz.cssxsh.mirai.tool.sign.service

import kotlinx.serialization.*
import kotlinx.serialization.json.*
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonNames

@Serializable
@OptIn(ExperimentalSerializationApi::class)
data class Cola(
data class SignServiceConfig(
@SerialName("base_url")
val base: String,
@SerialName("type")
Expand Down
Loading

0 comments on commit 206091f

Please sign in to comment.