Skip to content

Commit b22833c

Browse files
committed
Add command /aqqbot
1 parent d25004b commit b22833c

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package top.alazeprt.aqqbot.command
2+
3+
import org.bukkit.command.CommandSender
4+
import taboolib.common.platform.command.CommandBody
5+
import taboolib.common.platform.command.CommandHeader
6+
import taboolib.common.platform.command.subCommand
7+
import taboolib.common.platform.function.info
8+
import taboolib.common.platform.function.releaseResourceFile
9+
import taboolib.common.platform.function.submit
10+
import taboolib.module.configuration.Configuration
11+
import top.alazeprt.aonebot.BotClient
12+
import top.alazeprt.aqqbot.AQQBot.botConfig
13+
import top.alazeprt.aqqbot.AQQBot.config
14+
import top.alazeprt.aqqbot.AQQBot.enableGroups
15+
import top.alazeprt.aqqbot.AQQBot.isBukkit
16+
import top.alazeprt.aqqbot.AQQBot.messageConfig
17+
import top.alazeprt.aqqbot.AQQBot.oneBotClient
18+
import top.alazeprt.aqqbot.DependencyImpl
19+
import top.alazeprt.aqqbot.qq.BotListener
20+
import java.net.URI
21+
22+
@CommandHeader("aqqbot", ["abot", "qqbot"], permission = "aqqbot.command")
23+
object ABotCommand {
24+
@CommandBody
25+
val reload = subCommand {
26+
execute<CommandSender> { sender, _, _ ->
27+
sender.sendMessage("§a正在重载插件配置文件...")
28+
val s = System.currentTimeMillis()
29+
submit(async = true) {
30+
info("Reloading AQQBot ...")
31+
if (oneBotClient.isConnected) {
32+
oneBotClient.disconnect()
33+
}
34+
enableGroups.clear()
35+
val configFile = releaseResourceFile("config.yml", replace = false)
36+
config = Configuration.loadFromFile(configFile)
37+
val botFile = releaseResourceFile("bot.yml", replace = false)
38+
botConfig = Configuration.loadFromFile(botFile)
39+
val messageFile = releaseResourceFile("messages.yml", replace = false)
40+
messageConfig = Configuration.loadFromFile(messageFile)
41+
botConfig.getStringList("groups").forEach {
42+
enableGroups.add(it)
43+
}
44+
DependencyImpl.loadSpark()
45+
if (isBukkit) {
46+
DependencyImpl.loadPlayerStats()
47+
DependencyImpl.loadPAPI()
48+
}
49+
val url = "ws://" + botConfig.getString("ws.host") + ":" + botConfig.getInt("ws.port")
50+
oneBotClient = BotClient(URI.create(url))
51+
oneBotClient.connect()
52+
oneBotClient.registerEvent(BotListener())
53+
sender.sendMessage("§a重载完成!耗时 §e${System.currentTimeMillis() - s} ms")
54+
info("Reloaded AQQBot in ${System.currentTimeMillis() - s} ms")
55+
}
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)