mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 18:40:15 +08:00
Check Command.owner, #216
This commit is contained in:
parent
4803a21488
commit
595c9480a6
@ -37,6 +37,8 @@ public abstract class AbstractCommand
|
||||
|
||||
init {
|
||||
Command.checkCommandName(primaryName)
|
||||
@Suppress("LeakingThis")
|
||||
Command.checkCommandOwner(this)
|
||||
secondaryNames.forEach(Command.Companion::checkCommandName)
|
||||
}
|
||||
|
||||
|
@ -117,5 +117,19 @@ public interface Command {
|
||||
name.contains('.') -> throw IllegalArgumentException("'.' is forbidden in command name.")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查指令 [owner] 的合法性, 在非法时抛出 [IllegalArgumentException]
|
||||
*/
|
||||
@JvmStatic
|
||||
@Throws(IllegalArgumentException::class)
|
||||
public fun checkCommandOwner(command: Command) {
|
||||
val owner = command.owner
|
||||
if (owner is ConsoleCommandOwner) {
|
||||
if (command.javaClass.enclosingClass != BuiltInCommands::class.java) {
|
||||
throw IllegalArgumentException("ConsoleCommandOwner is not allowed")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user