Skip to content

Commit b79c129

Browse files
committed
feat: optimize market & scripts feature
1 parent b2a1aaf commit b79c129

7 files changed

Lines changed: 57 additions & 40 deletions

File tree

common/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ repositories {
2020

2121
dependencies {
2222
implementation("com.alessiodp.libby:libby-core:2.0.0-SNAPSHOT")
23-
compileOnly("com.github.alazeprt:AOneBot:1.0.19-beta")
23+
compileOnly("com.github.alazeprt:AOneBot:1.0.20-beta")
2424
compileOnly("com.google.code.gson:gson:2.11.0")
2525
compileOnly("net.kyori:adventure-api:4.18.0")
2626
compileOnly("net.kyori:adventure-text-serializer-legacy:4.24.0")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ interface AQQBot: ConfigProvider, CommandProvider, DataProvider, HookProvider, T
193193
val aonebotLib = Library.builder()
194194
.groupId("com{}github{}alazeprt")
195195
.artifactId("AOneBot")
196-
.version("1.0.19-beta")
196+
.version("1.0.20-beta")
197197
.relocate("com{}google{}code{}gson", "top{}alazeprt{}aonebot{}lib{}com{}google")
198198
.resolveTransitiveDependencies(true)
199199
.build()

common/src/main/kotlin/top/alazeprt/aqqbot/command/sub/SubMarket.kt

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,24 @@ class SubMarket(val plugin: AQQBot) : ACommand {
1212
sender.sendMessage(Component.text("你没有权限使用此命令!", NamedTextColor.RED))
1313
return
1414
}
15-
when (args[1]) {
16-
"list" -> plugin.scriptLoader.marketManager.list(sender)
17-
"info" -> if (args.size == 3) {
18-
plugin.scriptLoader.marketManager.info(sender, args[2], null)
19-
} else if (args.size == 4) {
20-
plugin.scriptLoader.marketManager.info(sender, args[2], args[3])
21-
} else SubHelp(plugin).onCommand(command, sender, args)
22-
"install" -> if (args.size == 3) {
23-
plugin.scriptLoader.marketManager.install(sender, args[2], null)
24-
} else if (args.size == 4) {
25-
plugin.scriptLoader.marketManager.install(sender, args[2], args[3])
26-
} else SubHelp(plugin).onCommand(command, sender, args)
27-
"update" -> if (args.size == 3) {
28-
plugin.scriptLoader.marketManager.update(sender, args[2])
29-
} else SubHelp(plugin).onCommand(command, sender, args)
15+
plugin.submitAsync {
16+
when (args[1]) {
17+
"list" -> plugin.scriptLoader.marketManager.list(sender)
18+
"info" -> if (args.size == 3) {
19+
plugin.scriptLoader.marketManager.info(sender, args[2], null)
20+
} else if (args.size == 4) {
21+
plugin.scriptLoader.marketManager.info(sender, args[2], args[3])
22+
} else SubHelp(plugin).onCommand(command, sender, args)
23+
"install" -> if (args.size == 3) {
24+
plugin.scriptLoader.marketManager.install(sender, args[2], null)
25+
} else if (args.size == 4) {
26+
plugin.scriptLoader.marketManager.install(sender, args[2], args[3])
27+
} else SubHelp(plugin).onCommand(command, sender, args)
28+
"update" -> if (args.size == 3) {
29+
plugin.scriptLoader.marketManager.update(sender, args[2])
30+
} else SubHelp(plugin).onCommand(command, sender, args)
31+
else -> SubHelp(plugin).onCommand(command, sender, args)
32+
}
3033
}
3134
}
3235

common/src/main/kotlin/top/alazeprt/aqqbot/command/sub/SubScripts.kt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@ class SubScripts(val plugin: AQQBot): ACommand {
1212
sender.sendMessage(Component.text("你没有权限使用此命令!", NamedTextColor.RED))
1313
return
1414
}
15-
when (args[1]) {
16-
"list" -> plugin.scriptLoader.scriptManager.list(sender)
17-
"download" -> if (args.size == 3) {
18-
plugin.scriptLoader.scriptManager.download(sender, args[2])
19-
} else SubHelp(plugin).onCommand(command, sender, args)
20-
"info" -> if (args.size == 3) {
21-
plugin.scriptLoader.scriptManager.info(sender, args[2])
22-
} else SubHelp(plugin).onCommand(command, sender, args)
23-
"reload" -> plugin.scriptLoader.scriptManager.reload(sender)
24-
"load" -> if (args.size == 3) {
25-
plugin.scriptLoader.scriptManager.load(sender, args[2])
26-
} else SubHelp(plugin).onCommand(command, sender, args)
15+
plugin.submitAsync {
16+
when (args[1]) {
17+
"list" -> plugin.scriptLoader.scriptManager.list(sender)
18+
"download" -> if (args.size == 3) {
19+
plugin.scriptLoader.scriptManager.download(sender, args[2])
20+
} else SubHelp(plugin).onCommand(command, sender, args)
21+
"info" -> if (args.size == 3) {
22+
plugin.scriptLoader.scriptManager.info(sender, args[2])
23+
} else SubHelp(plugin).onCommand(command, sender, args)
24+
"reload" -> plugin.scriptLoader.scriptManager.reload(sender)
25+
"load" -> if (args.size == 3) {
26+
plugin.scriptLoader.scriptManager.load(sender, args[2])
27+
} else SubHelp(plugin).onCommand(command, sender, args)
28+
}
2729
}
2830
}
2931
}

common/src/main/kotlin/top/alazeprt/aqqbot/scripts/ScriptManager.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,10 @@ class ScriptManager(val plugin: AQQBot) {
8383
sender.sendMessage(Component.text("[AQQBot] 尝试从 $url 下载脚本 ...").color(NamedTextColor.GREEN))
8484
val scriptFolder = plugin.getDataFolder().resolve("plugins")
8585
val tmpFile = scriptFolder.resolve(UUID.randomUUID().toString() + ".zip")
86+
plugin.log(LogLevel.DEBUG, "Downloading plugin from $url to $tmpFile")
8687
ARemoteUtil.downloadToFile(url, tmpFile)
8788
sender.sendMessage(Component.text("[AQQBot] 解压文件中 ...").color(NamedTextColor.GREEN))
89+
plugin.log(LogLevel.DEBUG, "Decompressing plugin $tmpFile")
8890
ACompressUtil.unzip(tmpFile, scriptFolder)
8991
sender.sendMessage(Component.text("[AQQBot] 尝试加载所有 plugins 文件夹内未加载的插件 ...").color(NamedTextColor.GREEN))
9092
val originList = plugin.scriptLoader.pluginList.map { it.directory }

common/src/main/kotlin/top/alazeprt/aqqbot/util/ACompressUtil.kt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package top.alazeprt.aqqbot.util
33
import java.io.File
44
import java.io.FileOutputStream
55
import java.nio.file.Files
6+
import java.nio.file.StandardCopyOption
67
import java.util.zip.ZipFile
78

89
object ACompressUtil {
@@ -11,22 +12,22 @@ object ACompressUtil {
1112
Files.createDirectories(outputDir.toPath())
1213
require(outputDir.isDirectory) { "Failed to create directory: ${outputDir.absolutePath}" }
1314

15+
val outputPath = outputDir.toPath().normalize()
1416
ZipFile(file).use { zip ->
15-
for (entry in zip.entries()) {
16-
val targetFile = outputDir.resolve(entry.name).normalize().absoluteFile
17-
require(targetFile.toPath().startsWith(outputDir.toPath().normalize())) {
18-
"Invalid entry name: ${entry.name}"
19-
}
17+
zip.entries().asSequence().forEach { entry ->
18+
// 处理条目名称:移除开头的斜杠并替换分隔符
19+
val entryName = entry.name.replace(Regex("^/"), "").replace('/', File.separatorChar)
20+
val targetPath = outputPath.resolve(entryName).normalize()
21+
22+
// 安全检查:确保目标路径在输出目录内
23+
require(targetPath.startsWith(outputPath)) { "Invalid entry name: ${entry.name}" }
2024

2125
if (entry.isDirectory) {
22-
targetFile.mkdirs()
26+
Files.createDirectories(targetPath)
2327
} else {
24-
targetFile.parentFile?.mkdirs()
25-
28+
Files.createDirectories(targetPath.parent)
2629
zip.getInputStream(entry).use { input ->
27-
FileOutputStream(targetFile).use { output ->
28-
input.copyTo(output)
29-
}
30+
Files.copy(input, targetPath, StandardCopyOption.REPLACE_EXISTING)
3031
}
3132
}
3233
}

common/src/main/resources/messages.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ game:
6969
- "&b/aqqbot whitelist unbind <qq|player> <数据> &e给玩家解除绑定(qq: QQ号, player: 游戏名, 根据数据选择其一)"
7070
- "&b/aqqbot whitelist reset <qq|player> <数据> &e清除玩家绑定的信息 (若为 player 则清除对应 QQ 号的所有绑定数据)"
7171
- "&b/aqqbot whitelist query/info <qq|player> <数据> &e根据QQ号或游戏名查询对应的游戏名或QQ号"
72+
- "&b/aqqbot market install <名称> <版本> &e从市场安装指定名称的脚本插件"
73+
- "&b/aqqbot market update <名称> &e从市场更新指定名称的脚本插件"
74+
- "&b/aqqbot market list &e列出市场中所有可用的脚本插件"
75+
- "&b/aqqbot market info <名称> [版本] &e查看指定名称的脚本插件信息"
76+
- "&b/aqqbot scripts download <URL地址> &e从指定 URL 下载脚本插件"
77+
- "&b/aqqbot scripts reload &e重载所有脚本插件"
78+
- "&b/aqqbot scripts info <名称> &e查看指定名称的脚本插件信息"
79+
- "&b/aqqbot scripts load <名称> &e加载指定名称的脚本插件"
80+
- "&b/aqqbot scripts info <名称> &e查看指定名称的脚本插件信息"
7281
- "&b/aqqbot status &e查看 AQQBot 插件状态"
7382
- "&b/aqqbot send <群号> <消息> &e以机器人账号身份发送消息到 QQ 群"
7483
- "&b/aqqbot reload &e重载配置文件"

0 commit comments

Comments
 (0)