Skip to content

Commit 529b241

Browse files
committed
Add custom command features
1 parent 36a6b6d commit 529b241

File tree

8 files changed

+103
-181
lines changed

8 files changed

+103
-181
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.5
2+
version=1.0.6
33
kotlin.incremental=true
44
kotlin.incremental.java=true
55
kotlin.caching.enabled=true

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

+14
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import taboolib.module.metrics.Metrics
1212
import top.alazeprt.aonebot.BotClient
1313
import top.alazeprt.aonebot.action.SendGroupMessage
1414
import top.alazeprt.aqqbot.qq.BotListener
15+
import top.alazeprt.aqqbot.util.ACustom
1516
import java.io.File
1617
import java.net.URI
1718
import javax.sql.DataSource
@@ -36,6 +37,8 @@ object AQQBot : Plugin() {
3637

3738
val dataMap: MutableMap<String, String> = mutableMapOf()
3839

40+
val customCommands: MutableList<ACustom> = mutableListOf()
41+
3942
lateinit var table: Table<*, *>
4043

4144
lateinit var dataSource: DataSource
@@ -95,6 +98,17 @@ object AQQBot : Plugin() {
9598
botConfig = Configuration.loadFromFile(botFile)
9699
val messageFile = releaseResourceFile("messages.yml", replace = false)
97100
messageConfig = Configuration.loadFromFile(messageFile)
101+
val customFile = releaseResourceFile("custom.yml", replace = false)
102+
val customConfig = Configuration.loadFromFile(customFile)
103+
customConfig.getKeys(false).forEach {
104+
if (customConfig.getBoolean("$it.enable")) {
105+
val command = customConfig.getStringList("$it.command")
106+
val output = customConfig.getStringList("$it.output")
107+
val unbind_output = customConfig.getStringList("$it.unbind_output")
108+
val format = customConfig.getBoolean("$it.format")
109+
customCommands.add(ACustom(command, output, unbind_output, format))
110+
}
111+
}
98112
dataConfig.getKeys(false).forEach {
99113
dataMap[it] = (dataConfig.getString(it)?: return@forEach)
100114
}

src/main/kotlin/top/alazeprt/aqqbot/command/ABotCommand.kt

+14
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ import taboolib.module.configuration.Configuration
1111
import top.alazeprt.aonebot.BotClient
1212
import top.alazeprt.aqqbot.AQQBot.botConfig
1313
import top.alazeprt.aqqbot.AQQBot.config
14+
import top.alazeprt.aqqbot.AQQBot.customCommands
1415
import top.alazeprt.aqqbot.AQQBot.enableGroups
1516
import top.alazeprt.aqqbot.AQQBot.isBukkit
1617
import top.alazeprt.aqqbot.AQQBot.messageConfig
1718
import top.alazeprt.aqqbot.AQQBot.oneBotClient
1819
import top.alazeprt.aqqbot.DependencyImpl
1920
import top.alazeprt.aqqbot.qq.BotListener
21+
import top.alazeprt.aqqbot.util.ACustom
2022
import top.alazeprt.aqqbot.util.AI18n.get
2123
import java.net.URI
2224

@@ -38,6 +40,18 @@ object ABotCommand {
3840
botConfig = Configuration.loadFromFile(botFile)
3941
val messageFile = releaseResourceFile("messages.yml", replace = false)
4042
messageConfig = Configuration.loadFromFile(messageFile)
43+
customCommands.clear()
44+
val customFile = releaseResourceFile("custom.yml", replace = false)
45+
val customConfig = Configuration.loadFromFile(customFile)
46+
customConfig.getKeys(false).forEach {
47+
if (customConfig.getBoolean("$it.enable")) {
48+
val command = customConfig.getStringList("$it.command")
49+
val output = customConfig.getStringList("$it.output")
50+
val unbind_output = customConfig.getStringList("$it.unbind_output")
51+
val format = customConfig.getBoolean("$it.format")
52+
customCommands.add(ACustom(command, output, unbind_output, format))
53+
}
54+
}
4155
botConfig.getStringList("groups").forEach {
4256
enableGroups.add(it)
4357
}

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

-136
This file was deleted.

src/main/kotlin/top/alazeprt/aqqbot/qq/BotListener.kt

+8-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import top.alazeprt.aonebot.event.Listener
55
import top.alazeprt.aonebot.event.SubscribeBotEvent
66
import top.alazeprt.aonebot.event.message.GroupMessageEvent
77
import top.alazeprt.aqqbot.AQQBot
8+
import top.alazeprt.aqqbot.AQQBot.customCommands
89
import top.alazeprt.aqqbot.AQQBot.isBukkit
910
import top.alazeprt.aqqbot.handler.InformationHandler
10-
import top.alazeprt.aqqbot.handler.StatsHandler
1111
import top.alazeprt.aqqbot.handler.WhitelistHandler
1212
import top.alazeprt.aqqbot.util.AI18n.get
1313

@@ -20,11 +20,14 @@ class BotListener : Listener {
2020
val message = event.message
2121
val handleInfo = InformationHandler.handle(message, event)
2222
val handleWl = WhitelistHandler.handle(message, event)
23-
var handleStats = false
24-
if (isBukkit) {
25-
handleStats = StatsHandler.handle(message, event)
23+
var handleCustom = false
24+
customCommands.forEach {
25+
if (it.handle(message?: return@forEach, event.senderId.toString(), event.groupId.toString())) {
26+
handleCustom = true
27+
return@forEach
28+
}
2629
}
27-
if(AQQBot.config.getBoolean("chat.group_to_server") && !(handleInfo || handleWl || handleStats) && isBukkit) {
30+
if(AQQBot.config.getBoolean("chat.group_to_server") && !(handleInfo || handleWl || handleCustom) && isBukkit) {
2831
Bukkit.broadcastMessage(formatString(get("game.chat_from_qq", mutableMapOf("groupId" to event.groupId.toString(),
2932
"userName" to event.senderNickName,
3033
"message" to message))))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package top.alazeprt.aqqbot.util
2+
3+
import me.clip.placeholderapi.PlaceholderAPI
4+
import org.bukkit.Bukkit
5+
import top.alazeprt.aonebot.action.SendGroupMessage
6+
import top.alazeprt.aqqbot.AQQBot.dataMap
7+
import top.alazeprt.aqqbot.AQQBot.isFileStorage
8+
import top.alazeprt.aqqbot.AQQBot.oneBotClient
9+
import top.alazeprt.aqqbot.DependencyImpl.Companion.withPAPI
10+
11+
class ACustom(val command: List<String>, val output: List<String>, val unbind_output: List<String>, val format: Boolean) {
12+
companion object {
13+
private fun formatString(input: String): String {
14+
return input.replace(Regex("&([0-9a-fklmnor])"), "")
15+
}
16+
}
17+
18+
fun handle(input: String, userId: String, groupId: String): Boolean {
19+
if (!command.contains(input)) return false
20+
var player: String?
21+
if (isFileStorage) {
22+
player = dataMap.getOrDefault(userId, null)
23+
} else {
24+
player = DBQuery.qqInDatabase(userId.toLong())
25+
}
26+
if (player == null) {
27+
oneBotClient.action(SendGroupMessage(groupId.toLong(), unbind_output.joinToString("\n")))
28+
return true
29+
}
30+
var outputString: String = output.joinToString("\n")
31+
if (withPAPI) {
32+
outputString = PlaceholderAPI.setPlaceholders(Bukkit.getOfflinePlayer(player), outputString)
33+
}
34+
if (format) {
35+
outputString = formatString(outputString)
36+
}
37+
oneBotClient.action(SendGroupMessage(groupId.toLong(), outputString))
38+
return true
39+
}
40+
}

src/main/resources/config.yml

-39
Original file line numberDiff line numberDiff line change
@@ -112,45 +112,6 @@ chat:
112112
# [服务器] ${sender}: ${message}
113113
server_to_group: true
114114

115-
# 玩家统计信息
116-
# * 该功能仅支持Bukkit类服务端
117-
# 大部分信息需要安装PlayerStats插件作为前置
118-
# 权限 & 组织 信息需要安装PlaceholderAPI插件作为前置
119-
stats:
120-
# 是否开启该功能
121-
enable: true
122-
123-
# 获取指令
124-
command:
125-
- "/stats"
126-
- "stats"
127-
- "统计信息"
128-
- "/统计信息"
129-
- "玩家统计信息"
130-
- "/玩家统计信息"
131-
132-
# 组织信息来源
133-
party:
134-
# 是否启用该功能
135-
enable: false
136-
137-
# 获取的PlaceholderAPI变量
138-
placeholder: "%parties_name%"
139-
140-
# 将颜色符号格式化
141-
format: false
142-
143-
# 称号信息来源
144-
prefix:
145-
# 是否启用该功能
146-
enable: true
147-
148-
# 获取的PlaceholderAPI变量
149-
placeholder: "%luckperms_prefix%"
150-
151-
# 将颜色符号格式化
152-
format: true
153-
154115
# 服务器开启/关闭通知
155116
notify:
156117
# 是否开启该功能

src/main/resources/custom.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# 自定义命令配置文件
2+
# 在QQ中执行该命令时返回指定结果
3+
# 支持掺杂 PlaceholderAPI 所提供的变量
4+
5+
# 例 1
6+
# 输入 /prefix 或 /称号 时返回玩家的称号 (对应PAPI变量 %vault_prefix%)
7+
prefix:
8+
# 是否开启该命令
9+
enable: true
10+
11+
# 获取命令
12+
command:
13+
- "/prefix"
14+
- "/称号"
15+
16+
# 输出结果
17+
output:
18+
- "你的称号是: %vault_prefix%"
19+
20+
# 未绑定账号的玩家输出 (不支持 PAPI)
21+
unbind_output:
22+
- "你还没有绑定账号!"
23+
24+
# 是否格式化颜色符号 (如: &7普通&a玩家 -> 普通玩家)
25+
format: true
26+

0 commit comments

Comments
 (0)