Don't show not permitted commands in /help

This commit is contained in:
Karlatemp 2021-02-20 19:51:23 +08:00
parent 0fa67b7699
commit 2e286a3a79
No known key found for this signature in database
GPG Key ID: 21FBDDF664FF06F8

View File

@ -37,6 +37,7 @@ import net.mamoe.mirai.console.permission.PermissionService
import net.mamoe.mirai.console.permission.PermissionService.Companion.cancel import net.mamoe.mirai.console.permission.PermissionService.Companion.cancel
import net.mamoe.mirai.console.permission.PermissionService.Companion.findCorrespondingPermissionOrFail import net.mamoe.mirai.console.permission.PermissionService.Companion.findCorrespondingPermissionOrFail
import net.mamoe.mirai.console.permission.PermissionService.Companion.getPermittedPermissions import net.mamoe.mirai.console.permission.PermissionService.Companion.getPermittedPermissions
import net.mamoe.mirai.console.permission.PermissionService.Companion.hasPermission
import net.mamoe.mirai.console.permission.PermissionService.Companion.permit import net.mamoe.mirai.console.permission.PermissionService.Companion.permit
import net.mamoe.mirai.console.permission.PermitteeId import net.mamoe.mirai.console.permission.PermitteeId
import net.mamoe.mirai.console.plugin.name import net.mamoe.mirai.console.plugin.name
@ -98,6 +99,7 @@ public object BuiltInCommands {
public suspend fun CommandSender.handle() { public suspend fun CommandSender.handle() {
sendMessage( sendMessage(
allRegisteredCommands allRegisteredCommands
.filter { hasPermission(it.permission) }
.joinToString("\n\n") { command -> .joinToString("\n\n") { command ->
val lines = command.usage.lines() val lines = command.usage.lines()
if (lines.isEmpty()) "/${command.primaryName} ${command.description}" if (lines.isEmpty()) "/${command.primaryName} ${command.description}"