1
1
package top.alazeprt.aqqbot
2
2
3
- import com.alessiodp.libby.Library
4
3
import com.alessiodp.libby.LibraryManager
5
4
import top.alazeprt.aconfiguration.file.FileConfiguration
6
5
import top.alazeprt.aonebot.action.SendGroupMessage
7
6
import top.alazeprt.aqqbot.adapter.AQQBotAdapter
8
- import top.alazeprt.aqqbot.bot.BotProvider
7
+ import top.alazeprt.aqqbot.bot.BotProvider.getBot
9
8
import top.alazeprt.aqqbot.bot.BotProvider.loadBot
10
9
import top.alazeprt.aqqbot.bot.BotProvider.unloadBot
11
10
import top.alazeprt.aqqbot.command.CommandProvider
12
11
import top.alazeprt.aqqbot.config.ConfigProvider
13
12
import top.alazeprt.aqqbot.config.MessageManager
14
13
import top.alazeprt.aqqbot.data.*
15
14
import top.alazeprt.aqqbot.debug.ADebug
16
- import top.alazeprt.aqqbot.event.AEvent
17
15
import top.alazeprt.aqqbot.hook.HookProvider
18
16
import top.alazeprt.aqqbot.profile.AOfflinePlayer
19
17
import top.alazeprt.aqqbot.task.TaskProvider
@@ -55,6 +53,25 @@ interface AQQBot: ConfigProvider, CommandProvider, DataProvider, HookProvider, T
55
53
botConfig.getString(" access_token" )
56
54
)
57
55
}
56
+ submitAsync {
57
+ while (true ) {
58
+ if (getBot()?.isConnected != true ) {
59
+ if (botConfig.getString(" access_token" ).isNullOrBlank()) {
60
+ loadBot(
61
+ this ,
62
+ URI .create(" ws://" + botConfig.getString(" ws.host" ) + " :" + botConfig.getInt(" ws.port" ))
63
+ )
64
+ } else {
65
+ loadBot(
66
+ this ,
67
+ URI .create(" ws://" + botConfig.getString(" ws.host" ) + " :" + botConfig.getInt(" ws.port" )),
68
+ botConfig.getString(" access_token" )
69
+ )
70
+ }
71
+ }
72
+ Thread .sleep(botConfig.getLong(" check_interval" ) * 1000 )
73
+ }
74
+ }
58
75
loadHook(this )
59
76
if (generalConfig.getString(" whitelist.verify_method" )?.uppercase() == " VERIFY_CODE" ) {
60
77
submitAsync {
@@ -69,23 +86,27 @@ interface AQQBot: ConfigProvider, CommandProvider, DataProvider, HookProvider, T
69
86
}
70
87
}
71
88
}
72
- if (generalConfig.getBoolean(" notify.server_status.enable" ) && BotProvider . getBot() != null &&
73
- BotProvider . getBot()!! .isConnected()) {
89
+ if (generalConfig.getBoolean(" notify.server_status.enable" ) && getBot() != null &&
90
+ getBot()!! .isConnected()) {
74
91
enableGroups.forEach {
75
- BotProvider .getBot()!! .action(SendGroupMessage (it.toLong(),
76
- generalConfig.getStringList(" notify.server_status.start" ).random()? : " [AQQBot] 服务器已启动!" ))
92
+ getBot()!! .action(SendGroupMessage (it.toLong(),
93
+ if (generalConfig.getStringList(" notify.server_status.start" ).isEmpty())
94
+ generalConfig.getString(" notify.server_status.start" )? : " [AQQBot] 服务器已启动!"
95
+ else generalConfig.getStringList(" notify.server_status.start" ).random()? : " [AQQBot] 服务器已启动!" ))
77
96
}
78
97
}
79
98
}
80
99
81
100
fun loadDependencies ()
82
101
83
102
fun disable () {
84
- if (generalConfig.getBoolean(" notify.server_status.enable" ) && BotProvider . getBot() != null &&
85
- BotProvider . getBot()!! .isConnected) {
103
+ if (generalConfig.getBoolean(" notify.server_status.enable" ) && getBot() != null &&
104
+ getBot()!! .isConnected) {
86
105
enableGroups.forEach {
87
- BotProvider .getBot()!! .action(SendGroupMessage (it.toLong(),
88
- generalConfig.getStringList(" notify.server_status.stop" ).random()? : " [AQQBot] 服务器已关闭!" ))
106
+ getBot()!! .action(SendGroupMessage (it.toLong(),
107
+ if (generalConfig.getStringList(" notify.server_status.stop" ).isEmpty())
108
+ generalConfig.getString(" notify.server_status.stop" )? : " [AQQBot] 服务器已关闭!"
109
+ else generalConfig.getStringList(" notify.server_status.stop" ).random()? : " [AQQBot] 服务器已关闭!" ))
89
110
}
90
111
}
91
112
unloadBot()
0 commit comments