mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 18:40:15 +08:00
CommandConfig, support custom commandPrefix, close #131
This commit is contained in:
parent
b75a89ac36
commit
1a5355db89
@ -28,6 +28,7 @@ import net.mamoe.mirai.console.data.PluginDataStorage
|
||||
import net.mamoe.mirai.console.extensions.PermissionServiceProvider
|
||||
import net.mamoe.mirai.console.extensions.PostStartupExtension
|
||||
import net.mamoe.mirai.console.extensions.SingletonExtensionSelector
|
||||
import net.mamoe.mirai.console.internal.command.CommandConfig
|
||||
import net.mamoe.mirai.console.internal.command.CommandManagerImpl
|
||||
import net.mamoe.mirai.console.internal.data.builtins.AutoLoginConfig
|
||||
import net.mamoe.mirai.console.internal.data.builtins.ConsoleDataScope
|
||||
@ -139,6 +140,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI
|
||||
|
||||
phase `load configurations`@{
|
||||
mainLogger.verbose { "Loading configurations..." }
|
||||
ConsoleDataScope.addAndReloadConfig(CommandConfig)
|
||||
ConsoleDataScope.reloadAll()
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ internal object CommandManagerImpl : CommandManager, CoroutineScope by MiraiCons
|
||||
|
||||
override fun getRegisteredCommands(owner: CommandOwner): List<Command> = _registeredCommands.filter { it.owner == owner }
|
||||
override val allRegisteredCommands: List<Command> get() = _registeredCommands.toList() // copy
|
||||
override val commandPrefix: String get() = "/"
|
||||
override val commandPrefix: String get() = CommandConfig.commandPrefix
|
||||
override fun unregisterAllCommands(owner: CommandOwner) {
|
||||
for (registeredCommand in getRegisteredCommands(owner)) {
|
||||
unregisterCommand(registeredCommand)
|
||||
|
30
backend/mirai-console/src/internal/command/CommnadConfig.kt
Normal file
30
backend/mirai-console/src/internal/command/CommnadConfig.kt
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found through the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.console.internal.command
|
||||
|
||||
import net.mamoe.mirai.console.data.AutoSavePluginConfig
|
||||
import net.mamoe.mirai.console.data.ValueDescription
|
||||
import net.mamoe.mirai.console.data.ValueName
|
||||
import net.mamoe.mirai.console.data.value
|
||||
|
||||
@ValueDescription("""
|
||||
内置指令系统配置
|
||||
""")
|
||||
internal object CommandConfig : AutoSavePluginConfig("Command") {
|
||||
override fun shouldPerformAutoSaveWheneverChanged(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
@ValueDescription("""
|
||||
指令前缀, 默认 "/"
|
||||
""")
|
||||
@ValueName("commandPrefix")
|
||||
val commandPrefix: String by value("/")
|
||||
}
|
Loading…
Reference in New Issue
Block a user