@@ -6,6 +6,9 @@ import me.regadpole.plumbot.bot.QQBot
6
6
import me.regadpole.plumbot.config.ConfigLoader
7
7
import me.regadpole.plumbot.config.ConfigResolver
8
8
import me.regadpole.plumbot.config.LangConfig
9
+ import me.regadpole.plumbot.database.Database
10
+ import me.regadpole.plumbot.database.MySQL
11
+ import me.regadpole.plumbot.database.SQLite
9
12
import taboolib.common.platform.Plugin
10
13
import taboolib.common.platform.function.disablePlugin
11
14
import taboolib.common.platform.function.info
@@ -21,6 +24,8 @@ object PlumBot : Plugin() {
21
24
22
25
private lateinit var lang: LangConfig
23
26
27
+ private lateinit var database: Database
28
+
24
29
override fun onLoad () {
25
30
ConfigResolver .loadConfig()
26
31
config = ConfigResolver .getConfigLoader()
@@ -30,6 +35,13 @@ object PlumBot : Plugin() {
30
35
31
36
// 项目使用TabooLib Start Jar 创建!
32
37
override fun onEnable () {
38
+ database = when (config.getConfig().database.type?.lowercase()) {
39
+ " sqlite" -> SQLite ()
40
+ " mysql" -> MySQL ()
41
+ else -> error(" Unknown database type." )
42
+ }
43
+ database.initialize()
44
+ info(" Loaded database" )
33
45
info(" Successfully running PlumBot!" )
34
46
}
35
47
@@ -54,15 +66,8 @@ object PlumBot : Plugin() {
54
66
}
55
67
56
68
override fun onDisable () {
57
- when (config.getConfig().bot.mode) {
58
- " go-cqhttp" , " kook" -> {
59
- bot.shutdown()
60
- }
61
- else -> {
62
- warning(" 无法正常关闭服务,将在服务器关闭后强制关闭" )
63
- disablePlugin()
64
- }
65
- }
69
+ bot.shutdown()
70
+ database.close()
66
71
}
67
72
68
73
fun reloadConfig () {
@@ -81,5 +86,7 @@ object PlumBot : Plugin() {
81
86
fun getLangConfig (): LangConfig {
82
87
return lang
83
88
}
84
-
89
+ fun getDatabase (): Database {
90
+ return database
91
+ }
85
92
}
0 commit comments