mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-08 01:00:13 +08:00
Console Command.kt
This commit is contained in:
parent
ddab66f165
commit
5ff9bfa272
@ -0,0 +1,33 @@
|
||||
package net.mamoe.mirai.plugin
|
||||
|
||||
object CommandManager {
|
||||
private val registeredCommand: MutableMap<String, Command> = mutableMapOf()
|
||||
|
||||
|
||||
fun register(command: Command) {
|
||||
val allNames = mutableListOf<String>(command.name).also { it.addAll(command.alias) }
|
||||
allNames.forEach {
|
||||
if (registeredCommand.containsKey(it)) {
|
||||
error("Command Name(or Alias) $it is already registered, consider if same function plugin was installed")
|
||||
}
|
||||
}
|
||||
allNames.forEach {
|
||||
registeredCommand[it] = command
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
abstract class Command(
|
||||
val name: String,
|
||||
val alias: List<String> = listOf()
|
||||
) {
|
||||
/**
|
||||
* 最高优先级监听器
|
||||
* 如果return [false] 这次指令不会被[PluginBase]的全局onCommand监听器监听
|
||||
* */
|
||||
fun onCommand(args: List<String>): Boolean {
|
||||
return true
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user