-
Notifications
You must be signed in to change notification settings - Fork 16
/
FixProtocolVersionPlugin.kt
60 lines (56 loc) · 1.87 KB
/
FixProtocolVersionPlugin.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package xyz.cssxsh.mirai.tool
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.register
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.unregister
import net.mamoe.mirai.console.extension.*
import net.mamoe.mirai.console.plugin.jvm.*
import net.mamoe.mirai.utils.*
import java.io.File
public object FixProtocolVersionPlugin : KotlinPlugin(
JvmPluginDescription(
id = "xyz.cssxsh.mirai.fix-protocol-version",
name = "fix-protocol-version",
version = "1.7.0",
) {
author("cssxsh")
}
) {
override fun PluginComponentStorage.onLoad() {
logger.info("协议版本检查更新...")
try {
FixProtocolVersion.update()
for (protocol in BotConfiguration.MiraiProtocol.values()) {
val file = File("${protocol.name.lowercase()}.json")
if (file.exists()) FixProtocolVersion.sync(protocol)
}
} catch (cause: Throwable) {
logger.error("协议版本升级失败", cause)
}
logger.info("注册服务...")
try {
TLV544Provider
Services.register(
"net.mamoe.mirai.internal.spi.EncryptService",
"xyz.cssxsh.mirai.tool.TLV544Provider",
::TLV544Provider
)
} catch (_: NoClassDefFoundError) {
// ...
} catch (cause: Throwable) {
logger.warning("注册服务失败", cause)
}
}
override fun onEnable() {
logger.info {
buildString {
appendLine("当前各协议版本日期: ")
for ((_, info) in FixProtocolVersion.info()) {
appendLine(info)
}
}
}
FixProtocolVersionCommand.register()
}
override fun onDisable() {
FixProtocolVersionCommand.unregister()
}
}