2020-06-28 02:08:44 +08:00
|
|
|
/*
|
2020-08-16 23:36:24 +08:00
|
|
|
* Copyright 2019-2020 Mamoe Technologies and contributors.
|
2020-06-28 02:08:44 +08:00
|
|
|
*
|
2020-08-23 17:46:51 +08:00
|
|
|
* 此源代码的使用受 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 via the following link.
|
2020-06-28 02:08:44 +08:00
|
|
|
*
|
|
|
|
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
package net.mamoe.mirai.console.command
|
|
|
|
|
2020-08-16 23:21:11 +08:00
|
|
|
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.register
|
2020-10-24 21:19:50 +08:00
|
|
|
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.unregisterCommand
|
2020-08-16 23:21:11 +08:00
|
|
|
|
2020-06-28 02:08:44 +08:00
|
|
|
inline fun <T : Command, R> T.withRegistration(block: T.() -> R): R {
|
|
|
|
this.register()
|
|
|
|
try {
|
|
|
|
return block()
|
|
|
|
} finally {
|
2020-10-24 21:19:50 +08:00
|
|
|
unregisterCommand(this)
|
2020-06-28 02:08:44 +08:00
|
|
|
}
|
|
|
|
}
|