mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 18:40:15 +08:00
parent
7bdeacf62a
commit
dfc9957c24
@ -37,8 +37,6 @@ public abstract class AbstractCommand
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
Command.checkCommandName(primaryName)
|
Command.checkCommandName(primaryName)
|
||||||
@Suppress("LeakingThis")
|
|
||||||
Command.checkCommandOwner(this)
|
|
||||||
secondaryNames.forEach(Command.Companion::checkCommandName)
|
secondaryNames.forEach(Command.Companion::checkCommandName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,19 +117,5 @@ public interface Command {
|
|||||||
name.contains('.') -> throw IllegalArgumentException("'.' is forbidden in command name.")
|
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