diff --git a/README.md b/README.md index 528e0f7..5cd4fc8 100644 --- a/README.md +++ b/README.md @@ -29,12 +29,13 @@ ## 权限列表 *有关权限部分的说明,参见[mirai-console的权限文档](https://github.com/mamoe/mirai-console/blob/master/docs/Permissions.md )* 根权限: `org.zrnq.mcmotd:*` -获取MC服务器信息: `org.zrnq.mcmotd:command.mcp` -绑定服务器到群聊: `org.zrnq.mcmotd:command.mcadd` -删除群聊绑定的服务器: `org.zrnq.mcmotd:command.mcdel` -启动/停止服务器的在线人数记录功能: `org.zrnq.mcmotd:command.mcrec` -获取http API访问计数: `org.zrnq.mcmotd:command.mcapi` -重载插件配置: `org.zrnq.mcmotd:command.mcreload` ++ 获取MC服务器信息: `org.zrnq.mcmotd:command.mcp` + + 仅允许获取本群绑定的服务器信息: `org.zrnq.mcmotd:command.mcp.strict` ++ 绑定服务器到群聊: `org.zrnq.mcmotd:command.mcadd` ++ 删除群聊绑定的服务器: `org.zrnq.mcmotd:command.mcdel` ++ 启动/停止服务器的在线人数记录功能: `org.zrnq.mcmotd:command.mcrec` ++ 获取http API访问计数: `org.zrnq.mcmotd:command.mcapi` ++ 重载插件配置: `org.zrnq.mcmotd:command.mcreload` ## 插件命令 > /mcp (服务器地址/服务器名称) : 查询指定地址或绑定到指定名称上的服务器信息,当本群仅绑定了一个服务器时可省略参数。 > diff --git a/build.gradle.kts b/build.gradle.kts index 39a0944..1709ff0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ plugins { } group = "org.zrnq" -version = "1.2.1" +version = "1.2.2" val ktor_version = "2.3.12" repositories { diff --git a/src/main/kotlin/org/zrnq/mcmotd/McMotd.kt b/src/main/kotlin/org/zrnq/mcmotd/McMotd.kt index 1dddd3b..a2ad386 100644 --- a/src/main/kotlin/org/zrnq/mcmotd/McMotd.kt +++ b/src/main/kotlin/org/zrnq/mcmotd/McMotd.kt @@ -34,6 +34,8 @@ object McMotd : KotlinPlugin( dataStorage = McMotdPluginData configStorage.checkConfig() + QueryCommand.preparePermissions() + commandList = listOf(QueryCommand, BindCommand, DelCommand, RecordCommand, HttpServerCommand, ConfigReloadCommand) commandList.forEach { it.register() } diff --git a/src/main/kotlin/org/zrnq/mcmotd/MiraiCommandHandlers.kt b/src/main/kotlin/org/zrnq/mcmotd/MiraiCommandHandlers.kt index 5be968d..1431642 100644 --- a/src/main/kotlin/org/zrnq/mcmotd/MiraiCommandHandlers.kt +++ b/src/main/kotlin/org/zrnq/mcmotd/MiraiCommandHandlers.kt @@ -6,11 +6,15 @@ import kotlinx.coroutines.withContext import net.mamoe.mirai.console.command.CommandSender import net.mamoe.mirai.console.command.MemberCommandSender import net.mamoe.mirai.console.command.SimpleCommand +import net.mamoe.mirai.console.permission.Permission +import net.mamoe.mirai.console.permission.PermissionService +import net.mamoe.mirai.console.permission.PermissionService.Companion.testPermission import net.mamoe.mirai.console.util.sendAnsiMessage import net.mamoe.mirai.message.data.At import net.mamoe.mirai.utils.ExternalResource.Companion.toExternalResource import org.zrnq.mcmotd.output.APIOutputHandler import org.zrnq.mcmotd.ImageUtil.appendPlayerHistory +import org.zrnq.mcmotd.McMotd.permissionId import org.zrnq.mcmotd.McMotd.reload import org.zrnq.mcmotd.data.McMotdPluginData import org.zrnq.mcmotd.data.McMotdPluginConfig @@ -26,6 +30,25 @@ import javax.imageio.ImageIO @Suppress("unused") object QueryCommand : SimpleCommand(McMotd, "mcp", description = "获取指定MC服务器的信息") { + + override val permission: Permission + get() = strictPermission + + private lateinit var strictPermission: Permission + private lateinit var relaxedPermission: Permission + + fun preparePermissions() { + relaxedPermission = PermissionService.INSTANCE.register( + permissionId("command.mcp"), + "获取任意MC服务器的信息", + McMotd.parentPermission + ) + strictPermission = PermissionService.INSTANCE.register( + permissionId("command.mcp.strict"), + "获取指定MC服务器的信息(仅限本群绑定的服务器)", + relaxedPermission) + } + @Handler suspend fun MemberCommandSender.handle() { val serverList = McMotdPluginData.getBoundServer(this.group.id) @@ -46,6 +69,7 @@ object QueryCommand : SimpleCommand(McMotd, "mcp", description = "获取指定M ?.firstOrNull { it.first == target } ?.let { doPing(it.second); return } } + if(!relaxedPermission.testPermission(this)) return doPing(target) }