Skip to content

Commit a62973e

Browse files
committed
feat: issue #46
1 parent 4014143 commit a62973e

File tree

8 files changed

+45
-19
lines changed

8 files changed

+45
-19
lines changed

bukkit/src/main/resources/plugin.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: AQQBot
22
main: top.alazeprt.aqqbot.AQQBotBukkit
3-
version: 2.0-beta.6
3+
version: 2.0-alpha.7
44
api-version: 1.13
55
author: alazeprt
66
commands:

common/src/main/kotlin/top/alazeprt/aqqbot/AQQBot.kt

+32-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
package top.alazeprt.aqqbot
22

3-
import com.alessiodp.libby.Library
43
import com.alessiodp.libby.LibraryManager
54
import top.alazeprt.aconfiguration.file.FileConfiguration
65
import top.alazeprt.aonebot.action.SendGroupMessage
76
import top.alazeprt.aqqbot.adapter.AQQBotAdapter
8-
import top.alazeprt.aqqbot.bot.BotProvider
7+
import top.alazeprt.aqqbot.bot.BotProvider.getBot
98
import top.alazeprt.aqqbot.bot.BotProvider.loadBot
109
import top.alazeprt.aqqbot.bot.BotProvider.unloadBot
1110
import top.alazeprt.aqqbot.command.CommandProvider
1211
import top.alazeprt.aqqbot.config.ConfigProvider
1312
import top.alazeprt.aqqbot.config.MessageManager
1413
import top.alazeprt.aqqbot.data.*
1514
import top.alazeprt.aqqbot.debug.ADebug
16-
import top.alazeprt.aqqbot.event.AEvent
1715
import top.alazeprt.aqqbot.hook.HookProvider
1816
import top.alazeprt.aqqbot.profile.AOfflinePlayer
1917
import top.alazeprt.aqqbot.task.TaskProvider
@@ -55,6 +53,25 @@ interface AQQBot: ConfigProvider, CommandProvider, DataProvider, HookProvider, T
5553
botConfig.getString("access_token")
5654
)
5755
}
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+
}
5875
loadHook(this)
5976
if (generalConfig.getString("whitelist.verify_method")?.uppercase() == "VERIFY_CODE") {
6077
submitAsync {
@@ -69,23 +86,27 @@ interface AQQBot: ConfigProvider, CommandProvider, DataProvider, HookProvider, T
6986
}
7087
}
7188
}
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()) {
7491
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] 服务器已启动!"))
7796
}
7897
}
7998
}
8099

81100
fun loadDependencies()
82101

83102
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) {
86105
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] 服务器已关闭!"))
89110
}
90111
}
91112
unloadBot()

common/src/main/kotlin/top/alazeprt/aqqbot/config/MessageManager.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ class MessageManager(plugin: AQQBot) {
66
private val messageConfig = plugin.messageConfig
77

88
fun get(key: String): String {
9-
return messageConfig.getStringList(key).random()?: ""
9+
return if (messageConfig.getStringList(key).isEmpty()) messageConfig.getString(key)?: "" else
10+
messageConfig.getStringList(key).random()?: ""
1011
}
1112

1213
fun get(key: String, map: Map<String, String>): String {
13-
var content = messageConfig.getStringList(key).random()?: ""
14+
var content = if (messageConfig.getStringList(key).isEmpty()) messageConfig.getString(key)?: "" else
15+
messageConfig.getStringList(key).random()?: ""
1416
for ((k, v) in map) {
1517
content = content.replace("\${$k}", v)
1618
}

common/src/main/kotlin/top/alazeprt/aqqbot/event/AEventUtil.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ object AEventUtil {
3131
val qq: Long = plugin.getQQByPlayer(plugin.adapter!!.getOfflinePlayer(playerName))?: -1L
3232
plugin.submitAsync {
3333
plugin.enableGroups.forEach {
34+
val messagePath = "notify.player_status.${if (isJoin) "join" else "leave"}"
3435
BotProvider.getBot()?.action(
35-
SendGroupMessage(it.toLong(), plugin.generalConfig
36-
.getStringList("notify.player_status.${if (isJoin) "join" else "leave"}").random()!!
36+
SendGroupMessage(it.toLong(), if (plugin.generalConfig.getStringList(messagePath).isEmpty())
37+
plugin.generalConfig.getString(messagePath)?: "" else plugin.generalConfig
38+
.getStringList(messagePath).random()
3739
.replace("\${playerName}", playerName)
3840
.replace("\${userId}", qq.toString()), true)
3941
)

common/src/main/kotlin/top/alazeprt/aqqbot/task/TaskProvider.kt

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import java.util.concurrent.CompletableFuture
55
import java.util.concurrent.Future
66

77
interface TaskProvider {
8+
// TODO: add cancel() method for every task submitted
89
fun submit(task: Runnable): Future<*>
910

1011
fun submitAsync(task: Runnable): Future<*>

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group=top.alazeprt.aqqbot
2-
version=2.0-beta.6
2+
version=2.0-alpha.7
33
kotlin.incremental=true
44
kotlin.incremental.java=true
55
kotlin.caching.enabled=true

velocity/src/main/kotlin/top/alazeprt/aqqbot/AQQBotVelocity.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import java.util.concurrent.Executors
3737
import java.util.concurrent.Future
3838

3939

40-
@Plugin(id = "aqqbot", name = "AQQBot", version = "2.0-beta.6", url = "https://aqqbot.alazeprt.top", authors = ["alazeprt"])
40+
@Plugin(id = "aqqbot", name = "AQQBot", version = "2.0-alpha.7", url = "https://aqqbot.alazeprt.top", authors = ["alazeprt"])
4141
class AQQBotVelocity : AQQBot {
4242
override var debugModule: ADebug? = null
4343

velocity/src/main/resources/velocity-plugin.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "aqqbot",
33
"name": "AQQBot",
44
"main": "top.alazeprt.aqqbot.AQQBotVelocity",
5-
"version": "2.0-beta.6",
5+
"version": "2.0-alpha.7",
66
"authors": ["alazeprt"],
77
"url": "https://aqqbot.alazeprt.top"
88
}

0 commit comments

Comments
 (0)