Skip to content

Commit

Permalink
check if connected again
Browse files Browse the repository at this point in the history
  • Loading branch information
MrXiaoM committed Dec 4, 2023
1 parent 7039b75 commit c43b151
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
10 changes: 5 additions & 5 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ java -cp "$CLASSPATH:./libs/*" net.mamoe.mirai.console.terminal.MiraiConsoleTerm

# JVM 参数

| 参数 | 说明 |
|---------------------------|-------------------------------------------|
| `-Doverflow.config=路径` | 修改配置文件(overflow.json)的路径 |
| `-Doverflow.not-exit` | 设置无法连接到 Onebot 时不结束进程 |
| `-Doverflow.timeout=超时时间` | 设置主动发送 action 的请求超时时间(毫秒),默认为10000毫秒(10秒) |
| 参数 | 说明 |
|----------------------------|-------------------------------------------|
| `-Doverflow.config=路径` | 修改配置文件(overflow.json)的路径 |
| `-Doverflow.not-exit=true` | 设置无法连接到 Onebot 时不结束进程 |
| `-Doverflow.timeout=超时时间` | 设置主动发送 action 的请求超时时间(毫秒),默认为10000毫秒(10秒) |

# 长期支持

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ class Overflow : IMirai, CoroutineScope, LowLevelApiAccessor, OverflowAPI {

@JvmStatic
val version = "${BuildConstants.VERSION}-${BuildConstants.COMMIT_HASH.chunked(6)[0]}"

private val isNotExit by lazy {
!System.getProperty("overflow.not-exit").isNullOrBlank()
}
}

init {
Expand Down Expand Up @@ -150,9 +154,7 @@ class Overflow : IMirai, CoroutineScope, LowLevelApiAccessor, OverflowAPI {
if (ws == null) {
if (printInfo) {
logger.error("未连接到 Onebot")
if (System.getProperty("overflow.not-exit").isNullOrBlank()) {
exitProcess(1)
}
if (!isNotExit) exitProcess(1)
}
return false
}
Expand All @@ -163,17 +165,23 @@ class Overflow : IMirai, CoroutineScope, LowLevelApiAccessor, OverflowAPI {
if (ws == null) {
if (printInfo) {
logger.error("未连接到 Onebot")
if (System.getProperty("overflow.not-exit").isNullOrBlank()) {
exitProcess(1)
}
if (!isNotExit) exitProcess(1)

}
return false
}
dispatchers = ws.createEventBus()
botImpl = ws.createBot().also { BotFactoryImpl.internalBot = it }
}
val versionInfo = botImpl.getVersionInfo()
OnebotMessages.appName = versionInfo.optJSONObject("data").get("app_name").asString.trim().lowercase()
OnebotMessages.appName = (versionInfo.optJSONObject("data").get("app_name")?.asString ?: "onebot").trim().lowercase()
if (!botImpl.channel.isOpen) {
if (printInfo) {
logger.error("未连接到 Onebot")
if (!isNotExit) exitProcess(1)
}
return false
}
if (printInfo) {
logger.info("服务端版本信息\n${versionInfo.toPrettyString()}")
}
Expand Down

0 comments on commit c43b151

Please sign in to comment.