Skip to content

Commit fefe30d

Browse files
committed
Update messages system
1 parent b71d59f commit fefe30d

File tree

8 files changed

+199
-53
lines changed

8 files changed

+199
-53
lines changed

gradle.properties

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

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

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ object AQQBot : Plugin() {
2020

2121
lateinit var config: Configuration
2222

23+
lateinit var messageConfig: Configuration
24+
2325
lateinit var oneBotClient: BotClient
2426

2527
private var alsoNoticed = false
@@ -44,6 +46,8 @@ object AQQBot : Plugin() {
4446
dataConfig = Configuration.loadFromFile(dataFile)
4547
val botFile = releaseResourceFile("bot.yml", replace = false)
4648
botConfig = Configuration.loadFromFile(botFile)
49+
val messageFile = releaseResourceFile("messages.yml", replace = false)
50+
messageConfig = Configuration.loadFromFile(messageFile)
4751
dataConfig.getKeys(false).forEach {
4852
dataMap[it] = (dataConfig.getString(it)?: return@forEach)
4953
}

src/main/kotlin/top/alazeprt/aqqbot/handler/InformationHandler.kt

+25-10
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import top.alazeprt.aonebot.event.message.GroupMessageEvent
77
import top.alazeprt.aqqbot.AQQBot
88
import top.alazeprt.aqqbot.AQQBot.isBukkit
99
import top.alazeprt.aqqbot.DependencyImpl.Companion.spark
10+
import top.alazeprt.aqqbot.util.AI18n.get
1011

1112
class InformationHandler {
1213
companion object {
1314
private fun getTPS(groupId: Long) {
1415
if (spark == null) {
1516
AQQBot.oneBotClient.action(SendGroupMessage(groupId,
16-
"服务器尚未安装spark插件, 无法获取TPS! 请联系服务器管理员!", true))
17+
get("qq.information.tps.not_installed_dependency"), true))
1718
return
1819
} else {
1920
val tps = spark?.tps()
@@ -22,23 +23,31 @@ class InformationHandler {
2223
val tps1Min = roundTPS(tps?.poll(StatisticWindow.TicksPerSecond.MINUTES_1)?: -1.0)
2324
val tps5Min = roundTPS(tps?.poll(StatisticWindow.TicksPerSecond.MINUTES_5)?: -1.0)
2425
val tps15Min = roundTPS(tps?.poll(StatisticWindow.TicksPerSecond.MINUTES_15)?: -1.0)
25-
AQQBot.oneBotClient.action(SendGroupMessage(groupId,
26-
"服务器TPS: $tps5Secs, $tps10Secs, $tps1Min, $tps5Min, $tps15Min", true))
26+
AQQBot.oneBotClient.action(SendGroupMessage(groupId, get("qq.information.tps.result", mutableMapOf(
27+
Pair("tps_5_seconds", tps5Secs),
28+
Pair("tps_10_seconds", tps10Secs),
29+
Pair("tps_1_minute", tps1Min),
30+
Pair("tps_5_minutes", tps5Min),
31+
Pair("tps_15_minutes", tps15Min)
32+
)), true))
2733
}
2834
}
2935

3036
private fun getMSPT(groupId: Long) {
3137
if (spark == null) {
3238
AQQBot.oneBotClient.action(SendGroupMessage(groupId,
33-
"服务器尚未安装spark插件, 无法获取MSPT! 请联系服务器管理员!", true))
39+
get("qq.information.mspt.not_installed_dependency"), true))
3440
return
3541
} else {
3642
val mspt = spark?.mspt()
3743
val mspt10Secs = roundMSPT(mspt?.poll(StatisticWindow.MillisPerTick.SECONDS_10)?.median()?: -1.0)
3844
val mspt1Min = roundMSPT(mspt?.poll(StatisticWindow.MillisPerTick.MINUTES_1)?.median()?: -1.0)
3945
val mspt5Min = roundMSPT(mspt?.poll(StatisticWindow.MillisPerTick.MINUTES_5)?.median()?: -1.0)
40-
AQQBot.oneBotClient.action(SendGroupMessage(groupId,
41-
"服务器MSPT: $mspt10Secs, $mspt1Min, $mspt5Min", true))
46+
AQQBot.oneBotClient.action(SendGroupMessage(groupId, get("qq.information.mspt.result", mutableMapOf(
47+
Pair("mspt_10_seconds", mspt10Secs),
48+
Pair("mspt_1_minute", mspt1Min),
49+
Pair("mspt_5_minutes", mspt5Min)
50+
)), true))
4251
}
4352
}
4453

@@ -61,21 +70,27 @@ class InformationHandler {
6170
private fun getPlayerList(groupId: Long) {
6271
val playerList = Bukkit.getOnlinePlayers()
6372
AQQBot.oneBotClient.action(
64-
SendGroupMessage(groupId, "服务器在线玩家(${playerList.size}): " +
65-
playerList.map{ it.name }.joinToString(", "), true))
73+
SendGroupMessage(groupId, get("qq.information.player_list.result", mutableMapOf(
74+
Pair("count", playerList.size.toString()),
75+
Pair("player_list", playerList.joinToString { it.name })
76+
)), true))
6677
}
6778

6879
private fun getCPUInfo(groupId: Long) {
6980
if (spark == null) {
7081
AQQBot.oneBotClient.action(SendGroupMessage(groupId,
71-
"服务器尚未安装spark插件, 无法获取CPU信息! 请联系服务器管理员!", true))
82+
get("qq.information.cpu.not_installed_dependency"), true))
7283
return
7384
} else {
7485
val cpu = spark?.cpuSystem()
7586
val cpu10Secs = roundCPU(cpu?.poll(StatisticWindow.CpuUsage.SECONDS_10)?: -1.0)
7687
val cpu1Min = roundCPU(cpu?.poll(StatisticWindow.CpuUsage.MINUTES_1)?: -1.0)
7788
val cpu15Min = roundCPU(cpu?.poll(StatisticWindow.CpuUsage.MINUTES_15)?: -1.0)
78-
AQQBot.oneBotClient.action(SendGroupMessage(groupId, "服务器CPU占用率: $cpu10Secs%, $cpu1Min%, $cpu15Min%", true))
89+
AQQBot.oneBotClient.action(SendGroupMessage(groupId, get("qq.information.cpu.result", mutableMapOf(
90+
Pair("cpu_10_seconds", cpu10Secs),
91+
Pair("cpu_1_minute", cpu1Min),
92+
Pair("cpu_15_minutes", cpu15Min)
93+
)), true))
7994
}
8095
}
8196

src/main/kotlin/top/alazeprt/aqqbot/handler/StatsHandler.kt

+42-23
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ import org.bukkit.Bukkit
77
import org.bukkit.Material
88
import org.bukkit.Statistic
99
import org.bukkit.ban.ProfileBanList
10+
import taboolib.common5.util.replace
1011
import top.alazeprt.aonebot.action.SendGroupMessage
1112
import top.alazeprt.aonebot.event.message.GroupMessageEvent
1213
import top.alazeprt.aqqbot.AQQBot
1314
import top.alazeprt.aqqbot.AQQBot.config
1415
import top.alazeprt.aqqbot.DependencyImpl.Companion.playerStats
1516
import top.alazeprt.aqqbot.DependencyImpl.Companion.withPAPI
17+
import top.alazeprt.aqqbot.util.AI18n.get
18+
import top.alazeprt.aqqbot.util.AI18n.getList
19+
import top.alazeprt.aqqbot.util.AI18n.getOriginList
1620
import java.text.SimpleDateFormat
1721

1822
class StatsHandler {
@@ -41,25 +45,30 @@ class StatsHandler {
4145
private fun getStats(groupId: Long, userId: Long) {
4246
if (playerStats == null) {
4347
AQQBot.oneBotClient.action(SendGroupMessage(groupId,
44-
"服务器尚未安装PlayerStats插件, 无法获取玩家统计信息! 请联系服务器管理员!", true))
48+
get("qq.stats.not_installed_dependency"), true))
4549
return
4650
}
4751
if (!AQQBot.dataMap.containsKey(userId.toString())) {
48-
AQQBot.oneBotClient.action(SendGroupMessage(groupId, "你尚未绑定账号! 无法获取玩家统计信息!", true))
52+
AQQBot.oneBotClient.action(SendGroupMessage(groupId, get("qq.stats.not_bind"), true))
4953
return
5054
}
5155
val name = AQQBot.dataMap[userId.toString()]!!
5256
val banEntry = Bukkit.getBanList<ProfileBanList>(BanList.Type.PROFILE).getBanEntry(name)
57+
val uuid = Bukkit.getOfflinePlayer(name).uniqueId
58+
val lastLogin = Bukkit.getOfflinePlayer(uuid).lastPlayed
5359
if (banEntry != null) {
5460
val banTime = banEntry.created
5561
val expireTime = banEntry.expiration
5662
val reason = banEntry.reason
57-
AQQBot.oneBotClient.action(SendGroupMessage(groupId, "QQ号: ${userId}\n" +
58-
"游戏名: ${name}\n" +
59-
"在线状态: 封禁\n" +
60-
"封禁原因: ${reason}\n" +
61-
"封禁时间: ${format.format(banTime)}\n" +
62-
"解封时间: ${if (expireTime == null) "永久封禁" else format.format(expireTime)}"))
63+
AQQBot.oneBotClient.action(SendGroupMessage(groupId, getList("qq.stats.result.ban", mutableMapOf(
64+
Pair("userId", userId.toString()),
65+
Pair("name", name),
66+
Pair("reason", reason ?: get("qq.stats.result.dont_have_reason")),
67+
Pair("ban_time", format.format(banTime)),
68+
Pair("unban_time", if (expireTime == null) "永久封禁" else format.format(expireTime)),
69+
Pair("last_login_time", if (lastLogin == 0L) get("qq.stats.result.did_not_login") else format.format(lastLogin)),
70+
Pair("uuid", uuid.toString())
71+
))))
6372
return
6473
}
6574
val mob_killed = playerStats!!.statManager.executePlayerStatRequest(PlayerStatRequest(name)
@@ -72,29 +81,39 @@ class StatsHandler {
7281
.untyped(Statistic.SPRINT_ONE_CM)).value
7382
val mine_ancient_debris = playerStats!!.statManager.executePlayerStatRequest(PlayerStatRequest(name)
7483
.blockOrItemType(Statistic.MINE_BLOCK, Material.ANCIENT_DEBRIS)).value
75-
val uuid = Bukkit.getOfflinePlayer(name).uniqueId
76-
val lastLogin = Bukkit.getOfflinePlayer(uuid).lastPlayed
77-
var message = "QQ号: ${userId}\n" +
78-
"游戏名: ${name}\n" +
79-
"在线状态: ${if (Bukkit.getOfflinePlayer(name).isOnline) "在线" else "离线"}\n" +
80-
"上次登录时间: ${if (lastLogin == 0L) "你还没有有玩过捏" else format.format(lastLogin)}\n" +
81-
"UUID: ${uuid}\n" +
82-
"击杀怪物数: ${mob_killed ?: 0}\n" +
83-
"在线时长: ${if (online_time == null) 0 else formatDuration(online_time/20)}\n" +
84-
"行走距离: ${if (walk_distance == null && run_distance == null) 0 else if (walk_distance == null) run_distance/100.0
85-
else if (run_distance == null) walk_distance/100.0 else (run_distance+walk_distance)/100}m\n" +
86-
"挖掘残骸数: ${mine_ancient_debris ?: 0}"
84+
var messageList = getOriginList("qq.stats.result.normal", mutableMapOf(
85+
Pair("userId", userId.toString()),
86+
Pair("name", name),
87+
Pair("online", if (Bukkit.getOfflinePlayer(name).isOnline) "在线" else "离线"),
88+
Pair("last_login_time", if (lastLogin == 0L) "你还没有有玩过捏" else format.format(lastLogin)),
89+
Pair("uuid", uuid.toString()),
90+
Pair("kill_mobs_count", mob_killed?.toString() ?: "0"),
91+
Pair("online_time", if (online_time == null) "0" else formatDuration(online_time/20)),
92+
Pair("walk_distance", if (walk_distance == null && run_distance == null) "0" else if (walk_distance == null) (run_distance/100.0).toString()
93+
else if (run_distance == null) (walk_distance/100.0).toString() else ((run_distance+walk_distance)/100).toString()),
94+
Pair("break_ancient_debris_count", mine_ancient_debris?.toString() ?: "0")
95+
))
8796
if (config.getBoolean("stats.party.enable") && withPAPI && Bukkit.getOfflinePlayer(name).isOnline) {
8897
var party = PlaceholderAPI.setPlaceholders(Bukkit.getOfflinePlayer(name), config.getString("stats.party.placeholder")!!)
8998
if (config.getBoolean("stats.party.format")) party = formatString(party)
90-
message += "\n组织: ${party.ifEmpty { "你还没有加入组织捏" }}"
99+
messageList = messageList.replace(Pair("\${organization}", party.ifEmpty { get("qq.stats.result.dont_have_organization") }))
100+
.toMutableList()
101+
} else {
102+
messageList.removeIf {
103+
it.contains("\${organization}")
104+
}
91105
}
92106
if (config.getBoolean("stats.prefix.enable") && withPAPI && Bukkit.getOfflinePlayer(name).isOnline) {
93107
var prefix = PlaceholderAPI.setPlaceholders(Bukkit.getOfflinePlayer(name), config.getString("stats.prefix.placeholder")!!)
94108
if (config.getBoolean("stats.prefix.format")) prefix = formatString(prefix)
95-
message += "\n称号: ${prefix.ifEmpty { "你还没有称号捏" }}"
109+
messageList =
110+
messageList.replace(Pair("\${prefix}", prefix.ifEmpty { get("qq.stats.result.dont_have_prefix") })).toMutableList()
111+
} else {
112+
messageList.removeIf {
113+
it.contains("\${prefix}")
114+
}
96115
}
97-
AQQBot.oneBotClient.action(SendGroupMessage(groupId, message, true))
116+
AQQBot.oneBotClient.action(SendGroupMessage(groupId, messageList.joinToString("\n"), true))
98117
}
99118

100119

src/main/kotlin/top/alazeprt/aqqbot/handler/WhitelistAdminHandler.kt

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,32 @@ import top.alazeprt.aonebot.action.GetGroupMemberList
44
import top.alazeprt.aonebot.action.SendGroupMessage
55
import top.alazeprt.aonebot.event.message.GroupMessageEvent
66
import top.alazeprt.aqqbot.AQQBot
7+
import top.alazeprt.aqqbot.util.AI18n.get
78

89
class WhitelistAdminHandler {
910
companion object {
1011
private fun bind(userId: String, groupId: Long, playerName: String) {
1112
if (AQQBot.dataMap.containsKey(userId)) {
12-
AQQBot.oneBotClient.action(SendGroupMessage(groupId, "他(${userId})已经绑定过了!"))
13+
AQQBot.oneBotClient.action(SendGroupMessage(groupId, get("qq.whitelist.admin.already_bind", mutableMapOf(Pair("userId", userId)))))
1314
return
1415
}
1516
if (!validateName(playerName)) {
16-
AQQBot.oneBotClient.action(SendGroupMessage(groupId, "名称不合法! (名称只能由字母、数字、下划线组成)", true))
17+
AQQBot.oneBotClient.action(SendGroupMessage(groupId, get("qq.whitelist.invalid_name"), true))
1718
return
1819
}
1920
AQQBot.dataMap.values.forEach {
2021
if (it == playerName) {
21-
AQQBot.oneBotClient.action(SendGroupMessage(groupId, "该名称已被他人占用!", true))
22+
AQQBot.oneBotClient.action(SendGroupMessage(groupId, get("qq.whitelist.already_exist"), true))
2223
return
2324
}
2425
}
2526
AQQBot.dataMap[userId] = playerName
26-
AQQBot.oneBotClient.action(SendGroupMessage(groupId, "绑定成功!", true))
27+
AQQBot.oneBotClient.action(SendGroupMessage(groupId, get("qq.whitelist.bind_successful"), true))
2728
}
2829

2930
private fun unbind(userId: String, groupId: Long, playerName: String) {
3031
if (!AQQBot.dataMap.containsKey(userId)) {
31-
AQQBot.oneBotClient.action(SendGroupMessage(groupId, "他(${userId})还没有绑定过!", true))
32+
AQQBot.oneBotClient.action(SendGroupMessage(groupId, get("qq.whitelist.admin.not_bind", mutableMapOf(Pair("userId", userId))), true))
3233
return
3334
}
3435
AQQBot.dataMap.forEach { (k, v) ->
@@ -37,12 +38,11 @@ class WhitelistAdminHandler {
3738
AQQBot.oneBotClient.action(SendGroupMessage(groupId, "解绑成功!", true))
3839
return
3940
} else if (k == userId) {
40-
AQQBot.oneBotClient.action(SendGroupMessage(groupId, "该名称不是他(${userId})绑定的! " +
41-
"你绑定的名称为: $v", true))
41+
AQQBot.oneBotClient.action(SendGroupMessage(groupId, get("qq.whitelist.admin.bind_by_other", mutableMapOf(Pair("name", v))), true))
4242
return
4343
}
4444
}
45-
AQQBot.oneBotClient.action(SendGroupMessage(groupId, "该名称尚未绑定过/不是他(${userId})绑定的!", true))
45+
AQQBot.oneBotClient.action(SendGroupMessage(groupId, get("qq.whitelist.admin.invalid_bind", mutableMapOf(Pair("userId", userId))), true))
4646
}
4747

4848
private fun validateName(name: String): Boolean {
@@ -56,7 +56,7 @@ class WhitelistAdminHandler {
5656
}
5757
val userId = message.split(" ")[1].toLongOrNull()
5858
if (userId == null) {
59-
AQQBot.oneBotClient.action(SendGroupMessage(event.groupId, "请输入正确的QQ号!", true))
59+
AQQBot.oneBotClient.action(SendGroupMessage(event.groupId, get("qq.whitelist.admin.invalid_user_id"), true))
6060
return
6161
}
6262
val playerName = message.split(" ")[2]
@@ -69,7 +69,7 @@ class WhitelistAdminHandler {
6969
}
7070
}
7171
if (!has) {
72-
AQQBot.oneBotClient.action(SendGroupMessage(event.groupId, "该用户不在本群!", true))
72+
AQQBot.oneBotClient.action(SendGroupMessage(event.groupId, get("qq.whitelist.admin.user_not_in_group"), true))
7373
return@action
7474
} else {
7575
if (action == "bind") {

src/main/kotlin/top/alazeprt/aqqbot/handler/WhitelistHandler.kt

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,51 @@
11
package top.alazeprt.aqqbot.handler
22

3+
import taboolib.common.platform.function.info
34
import top.alazeprt.aonebot.action.GetGroupMemberInfo
45
import top.alazeprt.aonebot.action.SendGroupMessage
56
import top.alazeprt.aonebot.event.message.GroupMessageEvent
67
import top.alazeprt.aonebot.util.GroupRole
78
import top.alazeprt.aqqbot.AQQBot
9+
import top.alazeprt.aqqbot.util.AI18n.get
810

911
class WhitelistHandler {
1012
companion object {
1113
private fun bind(userId: String, groupId: Long, playerName: String) {
1214
if (AQQBot.dataMap.containsKey(userId)) {
1315
AQQBot.oneBotClient.action(
14-
SendGroupMessage(groupId, "你已经绑定过了!", true))
16+
SendGroupMessage(groupId, get("qq.whitelist.already_bind"), true))
1517
return
1618
}
1719
if (!validateName(playerName)) {
18-
AQQBot.oneBotClient.action(SendGroupMessage(groupId, "名称不合法! (名称只能由字母、数字、下划线组成)", true))
20+
AQQBot.oneBotClient.action(SendGroupMessage(groupId, get("qq.whitelist.invalid_name"), true))
1921
return
2022
}
2123
AQQBot.dataMap.values.forEach {
2224
if (it == playerName) {
23-
AQQBot.oneBotClient.action(SendGroupMessage(groupId, "该名称已被他人占用!", true))
25+
AQQBot.oneBotClient.action(SendGroupMessage(groupId, get("qq.whitelist.already_exist"), true))
2426
return
2527
}
2628
}
2729
AQQBot.dataMap[userId] = playerName
28-
AQQBot.oneBotClient.action(SendGroupMessage(groupId, "绑定成功!", true))
30+
AQQBot.oneBotClient.action(SendGroupMessage(groupId, get("qq.whitelist.bind_successful"), true))
2931
}
3032

3133
private fun unbind(userId: String, groupId: Long, playerName: String) {
3234
if (!AQQBot.dataMap.containsKey(userId)) {
33-
AQQBot.oneBotClient.action(SendGroupMessage(groupId, "你还没有绑定过!", true))
35+
AQQBot.oneBotClient.action(SendGroupMessage(groupId, get("qq.whitelist.not_bind"), true))
3436
return
3537
}
3638
AQQBot.dataMap.forEach { (k, v) ->
3739
if (v == playerName && k == userId) {
3840
AQQBot.dataMap.remove(k)
39-
AQQBot.oneBotClient.action(SendGroupMessage(groupId, "解绑成功!", true))
41+
AQQBot.oneBotClient.action(SendGroupMessage(groupId, get("unbind_successful"), true))
4042
return
4143
} else if (k == userId) {
42-
AQQBot.oneBotClient.action(SendGroupMessage(groupId, "该名称不是你绑定的! " +
43-
"你绑定的名称为: $v", true))
44+
AQQBot.oneBotClient.action(SendGroupMessage(groupId, get("qq.whitelist.bind_by_other", mutableMapOf(Pair("name", v))), true))
4445
return
4546
}
4647
}
47-
AQQBot.oneBotClient.action(SendGroupMessage(groupId, "该名称尚未绑定过/不是你绑定的!", true))
48+
AQQBot.oneBotClient.action(SendGroupMessage(groupId, get("qq.whitelist.invalid_bind"), true))
4849
}
4950

5051
private fun validateName(name: String): Boolean {

0 commit comments

Comments
 (0)