Fix default config issue (remove / prefix)

Fix public command not handling aliases
This commit is contained in:
2022-09-13 21:16:15 +08:00
parent 137bf7d4f5
commit 78a3c09b43
3 changed files with 31 additions and 33 deletions

View File

@ -113,19 +113,20 @@ bindCommand: 绑定
commandPrefix: ! commandPrefix: !
# 命令别名 # 命令别名
commandAlias: commandAlias:
无敌: '/prop god on' 无敌: 'prop god on'
关闭无敌: '/prop god off' 关闭无敌: 'prop god off'
无限体力: '/prop ns on' 无限体力: 'prop ns on'
关闭无限体力: '/prop ns off' 关闭无限体力: 'prop ns off'
无限能量: '/prop ue on' 无限能量: 'prop ue on'
关闭无限能量: '/prop ue off' 关闭无限能量: 'prop ue off'
点亮地图: '/prop unlockmap 1' 点亮地图: 'prop unlockmap 1'
解锁地图: '/prop unlockmap 1' 解锁地图: 'prop unlockmap 1'
位置: '/pos' 位置: 'pos'
坐标: '/pos' 坐标: 'pos'
# 公开命令,无需绑定账号也可以执行(可用别名)(必须绑定了控制台令牌才可使用)
publicCommands: publicCommands:
- '/list' - 'list'
- '/list uid' - 'list uid'
``` ```
# 指令列表 # 指令列表

View File

@ -105,16 +105,7 @@ object JGrasscutterCommand : KotlinPlugin(
// 处理执行游戏命令 // 处理执行游戏命令
else if (message.startsWith(PluginConfig.commandPrefix)) { else if (message.startsWith(PluginConfig.commandPrefix)) {
var command = message.removePrefix(PluginConfig.commandPrefix).trim() var command = message.removePrefix(PluginConfig.commandPrefix).trim()
if (command.isEmpty()) { if (command.isEmpty() || (command[0] == '/' && command.length == 1)) {
return@subscribeAlways
}
// 检查是否使用别名
val t = PluginConfig.commandAlias[command]
if (!t.isNullOrEmpty()) command = t
// 如果是斜杠开头,则移除斜杠,在控制台执行不需要斜杠
if (command[0] == '/') {
command = command.substring(1)
if (command.isEmpty())
return@subscribeAlways return@subscribeAlways
} }
@ -142,6 +133,12 @@ object JGrasscutterCommand : KotlinPlugin(
user.token user.token
} }
} }
// 检查是否使用别名
val t = PluginConfig.commandAlias[command]
if (!t.isNullOrEmpty()) command = t
// 如果是斜杠开头,则移除斜杠,在控制台执行不需要斜杠
if (command[0] == '/') command = command.substring(1)
try { try {
// 调用接口执行命令 // 调用接口执行命令
val response = OpenCommandApi.runCommand(server.address, token, command) val response = OpenCommandApi.runCommand(server.address, token, command)

View File

@ -36,22 +36,22 @@ object PluginConfig : AutoSavePluginConfig("config") {
@ValueDescription("命令别名") @ValueDescription("命令别名")
val commandAlias: MutableMap<String, String> by value(mutableMapOf( val commandAlias: MutableMap<String, String> by value(mutableMapOf(
"无敌" to "/prop god on", "无敌" to "prop god on",
"关闭无敌" to "/prop god off", "关闭无敌" to "prop god off",
"无限体力" to "/prop ns on", "无限体力" to "prop ns on",
"关闭无限体力" to "/prop ns off", "关闭无限体力" to "prop ns off",
"无限能量" to "/prop ue on", "无限能量" to "prop ue on",
"关闭无限能量" to "/prop ue off", "关闭无限能量" to "prop ue off",
"点亮地图" to "/prop unlockmap 1", "点亮地图" to "prop unlockmap 1",
"解锁地图" to "/prop unlockmap 1", "解锁地图" to "prop unlockmap 1",
"位置" to "/pos", "位置" to "pos",
"坐标" to "/pos", "坐标" to "pos",
// TODO ... // TODO ...
)) ))
@ValueDescription("公开命令,无需绑定账号也可以执行(可用别名)(必须绑定了控制台令牌才可使用)") @ValueDescription("公开命令,无需绑定账号也可以执行(可用别名)(必须绑定了控制台令牌才可使用)")
val publicCommands: MutableSet<String> by value(mutableSetOf( val publicCommands: MutableSet<String> by value(mutableSetOf(
"/list", "/list uid" "list", "list uid"
)) ))
} }