diff --git a/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/Codegen.kt b/backend/codegen/src/Codegen.kt similarity index 98% rename from backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/Codegen.kt rename to backend/codegen/src/Codegen.kt index 8857cb0c1..bfc674cc4 100644 --- a/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/Codegen.kt +++ b/backend/codegen/src/Codegen.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/MessageScopeCodegen.kt b/backend/codegen/src/MessageScopeCodegen.kt similarity index 97% rename from backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/MessageScopeCodegen.kt rename to backend/codegen/src/MessageScopeCodegen.kt index 69b39e2e3..e6b1c6b87 100644 --- a/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/MessageScopeCodegen.kt +++ b/backend/codegen/src/MessageScopeCodegen.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/ValuePluginDataCodegen.kt b/backend/codegen/src/ValuePluginDataCodegen.kt similarity index 99% rename from backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/ValuePluginDataCodegen.kt rename to backend/codegen/src/ValuePluginDataCodegen.kt index 8cb0fd3b2..836ff9a1a 100644 --- a/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/ValuePluginDataCodegen.kt +++ b/backend/codegen/src/ValuePluginDataCodegen.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/old/JSettingCodegen.kt b/backend/codegen/src/old/JSettingCodegen.kt similarity index 96% rename from backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/old/JSettingCodegen.kt rename to backend/codegen/src/old/JSettingCodegen.kt index b7cefac84..312703014 100644 --- a/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/old/JSettingCodegen.kt +++ b/backend/codegen/src/old/JSettingCodegen.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/old/SettingValueUseSiteCodegen.kt b/backend/codegen/src/old/SettingValueUseSiteCodegen.kt similarity index 98% rename from backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/old/SettingValueUseSiteCodegen.kt rename to backend/codegen/src/old/SettingValueUseSiteCodegen.kt index e1032cdf1..9d2f20fb8 100644 --- a/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/old/SettingValueUseSiteCodegen.kt +++ b/backend/codegen/src/old/SettingValueUseSiteCodegen.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/old/ValueImplCodegen.kt b/backend/codegen/src/old/ValueImplCodegen.kt similarity index 99% rename from backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/old/ValueImplCodegen.kt rename to backend/codegen/src/old/ValueImplCodegen.kt index d391685fa..47e42a836 100644 --- a/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/old/ValueImplCodegen.kt +++ b/backend/codegen/src/old/ValueImplCodegen.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/old/ValuesCodegen.kt b/backend/codegen/src/old/ValuesCodegen.kt similarity index 98% rename from backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/old/ValuesCodegen.kt rename to backend/codegen/src/old/ValuesCodegen.kt index 90da1619f..7c07d1b73 100644 --- a/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/old/ValuesCodegen.kt +++ b/backend/codegen/src/old/ValuesCodegen.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/util.kt b/backend/codegen/src/util.kt similarity index 97% rename from backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/util.kt rename to backend/codegen/src/util.kt index 0066d071b..735215346 100644 --- a/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/util.kt +++ b/backend/codegen/src/util.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt b/backend/mirai-console/src/MiraiConsole.kt similarity index 97% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt rename to backend/mirai-console/src/MiraiConsole.kt index 42106685e..2211eff30 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt +++ b/backend/mirai-console/src/MiraiConsole.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -17,7 +17,6 @@ import kotlinx.coroutines.Job import net.mamoe.mirai.Bot import net.mamoe.mirai.console.MiraiConsole.INSTANCE import net.mamoe.mirai.console.MiraiConsoleImplementation.Companion.start -import net.mamoe.mirai.console.command.BuiltInCommands import net.mamoe.mirai.console.extensions.BotConfigurationAlterer import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge import net.mamoe.mirai.console.internal.extension.GlobalComponentStorage diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleFrontEndDescription.kt b/backend/mirai-console/src/MiraiConsoleFrontEndDescription.kt similarity index 93% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleFrontEndDescription.kt rename to backend/mirai-console/src/MiraiConsoleFrontEndDescription.kt index f8155a9d1..4c4de4b32 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleFrontEndDescription.kt +++ b/backend/mirai-console/src/MiraiConsoleFrontEndDescription.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt b/backend/mirai-console/src/MiraiConsoleImplementation.kt similarity index 97% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt rename to backend/mirai-console/src/MiraiConsoleImplementation.kt index a6583fa45..418b50536 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt +++ b/backend/mirai-console/src/MiraiConsoleImplementation.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -49,7 +49,7 @@ public annotation class ConsoleFrontEndImplementation /** * 实现 [MiraiConsole] 的接口 * - * **注意**: 随着 Console 的更新, 在版本号 `x.y.z` 的 `y` 修改时此接口可能就会变动. 意味着前端实现着需要跟随 Console 更新. + * **注意**: 随着 Console 的更新, 在版本号 `x.y.z` 的 `y` 修改时此接口可能就会发生 ABI 变动. 意味着前端实现着需要跟随 Console 更新. * * @see MiraiConsoleImplementation.start 启动 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/AbstractCommand.kt b/backend/mirai-console/src/command/AbstractCommand.kt similarity index 70% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/AbstractCommand.kt rename to backend/mirai-console/src/command/AbstractCommand.kt index 7de3bd955..c9048e221 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/AbstractCommand.kt +++ b/backend/mirai-console/src/command/AbstractCommand.kt @@ -2,14 +2,17 @@ * 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 via the following link. + * 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 */ +@file:Suppress("unused") + package net.mamoe.mirai.console.command -import net.mamoe.mirai.console.internal.command.createOrFindCommandPermission +import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors +import net.mamoe.mirai.console.internal.command.findOrCreateCommandPermission import net.mamoe.mirai.console.permission.Permission /** @@ -26,14 +29,17 @@ public abstract class AbstractCommand public final override val secondaryNames: Array, public override val description: String = "", parentPermission: Permission = owner.parentPermission, - /** 为 `true` 时表示 [指令前缀][CommandManager.commandPrefix] 可选 */ - public override val prefixOptional: Boolean = false, ) : Command { + + @ExperimentalCommandDescriptors + override val prefixOptional: Boolean + get() = false + init { Command.checkCommandName(primaryName) secondaryNames.forEach(Command.Companion::checkCommandName) } public override val usage: String get() = description - public override val permission: Permission by lazy { createOrFindCommandPermission(parentPermission) } + public override val permission: Permission by lazy { findOrCreateCommandPermission(parentPermission) } } \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/BuiltInCommands.kt b/backend/mirai-console/src/command/BuiltInCommands.kt similarity index 91% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/BuiltInCommands.kt rename to backend/mirai-console/src/command/BuiltInCommands.kt index fc4c406b6..c24fe9948 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/BuiltInCommands.kt +++ b/backend/mirai-console/src/command/BuiltInCommands.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -71,13 +71,18 @@ public object BuiltInCommands { public object HelpCommand : SimpleCommand( ConsoleCommandOwner, "help", - description = "Command list", + description = "查看指令帮助", ), BuiltInCommandInternal { @Handler public suspend fun CommandSender.handle() { sendMessage( - allRegisteredCommands.joinToString("\n\n") { "◆ ${it.usage}" }.lines().filterNot(String::isBlank) - .joinToString("\n") + allRegisteredCommands + .joinToString("\n\n") { command -> + val lines = command.usage.lines() + if (lines.isEmpty()) "/${command.primaryName} ${command.description}" + else + "◆ " + lines.first() + "\n" + lines.drop(1).joinToString("\n") { " $it" } + }.lines().filterNot(String::isBlank).joinToString("\n") ) } } @@ -90,7 +95,7 @@ public object BuiltInCommands { public object StopCommand : SimpleCommand( ConsoleCommandOwner, "stop", "shutdown", "exit", - description = "Stop the whole world.", + description = "关闭 Mirai Console", ), BuiltInCommandInternal { private val closingLock = Mutex() @@ -125,10 +130,10 @@ public object BuiltInCommands { public object LoginCommand : SimpleCommand( ConsoleCommandOwner, "login", "登录", - description = "Log in a bot account.", + description = "登录一个账号", ), BuiltInCommandInternal { @Handler - public suspend fun CommandSender.handle(id: Long, password: String) { + public suspend fun CommandSender.handle(@Name("qq") id: Long, password: String) { kotlin.runCatching { MiraiConsole.addBot(id, password).alsoLogin() }.fold( diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/Command.kt b/backend/mirai-console/src/command/Command.kt similarity index 94% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/Command.kt rename to backend/mirai-console/src/command/Command.kt index a73e2f842..6ea89734e 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/Command.kt +++ b/backend/mirai-console/src/command/Command.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -77,6 +77,9 @@ public interface Command { * 为 `true` 时表示 [指令前缀][CommandManager.commandPrefix] 可选. * * 会影响聊天语境中的解析. + * + * #### 实验性 API + * 由于指令解析允许被扩展, 此属性可能不适用所有解析器, 因此还未决定是否保留. */ @ExperimentalCommandDescriptors @ConsoleExperimentalApi diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandExecuteResult.kt b/backend/mirai-console/src/command/CommandExecuteResult.kt similarity index 96% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandExecuteResult.kt rename to backend/mirai-console/src/command/CommandExecuteResult.kt index 9697dd4d7..106d1a8b6 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandExecuteResult.kt +++ b/backend/mirai-console/src/command/CommandExecuteResult.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -21,6 +21,8 @@ import kotlin.contracts.contract /** * 指令的执行返回 * + * 注意: 现阶段 + * * @see CommandExecuteStatus */ @ConsoleExperimentalApi("Not yet implemented") @@ -144,12 +146,14 @@ public sealed class CommandExecuteResult { } } +@ExperimentalCommandDescriptors @Suppress("RemoveRedundantQualifierName") public typealias CommandExecuteStatus = CommandExecuteResult.CommandExecuteStatus /** * 当 [this] 为 [CommandExecuteResult.Success] 时返回 `true` */ +@ExperimentalCommandDescriptors @JvmSynthetic public fun CommandExecuteResult.isSuccess(): Boolean { contract { @@ -162,6 +166,7 @@ public fun CommandExecuteResult.isSuccess(): Boolean { /** * 当 [this] 为 [CommandExecuteResult.IllegalArgument] 时返回 `true` */ +@ExperimentalCommandDescriptors @JvmSynthetic public fun CommandExecuteResult.isIllegalArgument(): Boolean { contract { @@ -174,6 +179,7 @@ public fun CommandExecuteResult.isIllegalArgument(): Boolean { /** * 当 [this] 为 [CommandExecuteResult.ExecutionFailed] 时返回 `true` */ +@ExperimentalCommandDescriptors @JvmSynthetic public fun CommandExecuteResult.isExecutionException(): Boolean { contract { @@ -186,6 +192,7 @@ public fun CommandExecuteResult.isExecutionException(): Boolean { /** * 当 [this] 为 [CommandExecuteResult.PermissionDenied] 时返回 `true` */ +@ExperimentalCommandDescriptors @JvmSynthetic public fun CommandExecuteResult.isPermissionDenied(): Boolean { contract { @@ -198,6 +205,7 @@ public fun CommandExecuteResult.isPermissionDenied(): Boolean { /** * 当 [this] 为 [CommandExecuteResult.UnresolvedCall] 时返回 `true` */ +@ExperimentalCommandDescriptors @JvmSynthetic public fun CommandExecuteResult.isCommandNotFound(): Boolean { contract { @@ -210,6 +218,7 @@ public fun CommandExecuteResult.isCommandNotFound(): Boolean { /** * 当 [this] 为 [CommandExecuteResult.ExecutionFailed], [CommandExecuteResult.IllegalArgument] 或 [CommandExecuteResult.UnresolvedCall] 时返回 `true` */ +@ExperimentalCommandDescriptors @JvmSynthetic public fun CommandExecuteResult.isFailure(): Boolean { contract { diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandExecutionException.kt b/backend/mirai-console/src/command/CommandExecutionException.kt similarity index 77% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandExecutionException.kt rename to backend/mirai-console/src/command/CommandExecutionException.kt index 1998b71b0..da35d181e 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandExecutionException.kt +++ b/backend/mirai-console/src/command/CommandExecutionException.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -11,10 +11,8 @@ package net.mamoe.mirai.console.command -import net.mamoe.mirai.console.command.CommandManager.INSTANCE.executeCommand - /** - * 在 [CommandManager.executeCommand] 中, [Command.onCommand] 抛出异常时包装的异常. + * 在 [CommandManager.executeCommand] 中抛出异常时包装的异常. */ public class CommandExecutionException( /** @@ -29,7 +27,7 @@ public class CommandExecutionException( * 匹配到的指令名 */ public val name: String, - cause: Throwable + cause: Throwable, ) : RuntimeException( "Exception while executing command '${command.primaryName}'", cause diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandManager.kt b/backend/mirai-console/src/command/CommandManager.kt similarity index 99% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandManager.kt rename to backend/mirai-console/src/command/CommandManager.kt index f837ed105..ee2871993 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandManager.kt +++ b/backend/mirai-console/src/command/CommandManager.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandOwner.kt b/backend/mirai-console/src/command/CommandOwner.kt similarity index 81% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandOwner.kt rename to backend/mirai-console/src/command/CommandOwner.kt index f59033c95..e60628ce7 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandOwner.kt +++ b/backend/mirai-console/src/command/CommandOwner.kt @@ -2,14 +2,13 @@ * 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 via the following link. + * 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.command -import net.mamoe.mirai.console.command.CommandManager.INSTANCE.unregisterAllCommands import net.mamoe.mirai.console.compiler.common.ResolveContext import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.PERMISSION_NAME import net.mamoe.mirai.console.permission.Permission @@ -34,11 +33,13 @@ public interface CommandOwner : PermissionIdNamespace { /** * 代表控制台所有者. 所有的 mirai-console 内建的指令都属于 [ConsoleCommandOwner]. + * + * 插件注册指令时不应该使用 [ConsoleCommandOwner]. */ -internal object ConsoleCommandOwner : CommandOwner { - override val parentPermission: Permission get() = BuiltInCommands.parentPermission +public object ConsoleCommandOwner : CommandOwner { + public override val parentPermission: Permission get() = BuiltInCommands.parentPermission - override fun permissionId( + public override fun permissionId( @ResolveContext(PERMISSION_NAME) name: String, ): PermissionId = PermissionId("console", name) } \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandPermissionDeniedException.kt b/backend/mirai-console/src/command/CommandPermissionDeniedException.kt similarity index 83% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandPermissionDeniedException.kt rename to backend/mirai-console/src/command/CommandPermissionDeniedException.kt index f966ce96d..5fbb6d95c 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandPermissionDeniedException.kt +++ b/backend/mirai-console/src/command/CommandPermissionDeniedException.kt @@ -2,15 +2,13 @@ * 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 via the following link. + * 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.command -import net.mamoe.mirai.console.command.CommandManager.INSTANCE.executeCommand - /** * 在 [CommandManager.executeCommand] 中, [CommandSender] 未拥有 [Command.permission] 所要求的权限时抛出的异常. * @@ -24,7 +22,7 @@ public class CommandPermissionDeniedException( /** * 执行过程发生异常的指令 */ - public val command: Command + public val command: Command, ) : RuntimeException("Permission denied while executing command '${command.primaryName}'") { public override fun toString(): String = "CommandPermissionDeniedException(command=$command)" diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandSender.kt b/backend/mirai-console/src/command/CommandSender.kt similarity index 99% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandSender.kt rename to backend/mirai-console/src/command/CommandSender.kt index f3f9b55ee..5f1abba24 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandSender.kt +++ b/backend/mirai-console/src/command/CommandSender.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CompositeCommand.kt b/backend/mirai-console/src/command/CompositeCommand.kt similarity index 96% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CompositeCommand.kt rename to backend/mirai-console/src/command/CompositeCommand.kt index efec2b5d1..46be20fdc 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CompositeCommand.kt +++ b/backend/mirai-console/src/command/CompositeCommand.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -87,9 +87,8 @@ public abstract class CompositeCommand( @ResolveContext(COMMAND_NAME) vararg secondaryNames: String, description: String = "no description available", parentPermission: Permission = owner.parentPermission, - prefixOptional: Boolean = false, overrideContext: CommandArgumentContext = EmptyCommandArgumentContext, -) : Command, AbstractCommand(owner, primaryName, secondaryNames = secondaryNames, description, parentPermission, prefixOptional), +) : Command, AbstractCommand(owner, primaryName, secondaryNames = secondaryNames, description, parentPermission), CommandArgumentContextAware { private val reflector by lazy { CommandReflector(this, CompositeCommandSubCommandAnnotationResolver) } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/IllegalCommandArgumentException.kt b/backend/mirai-console/src/command/IllegalCommandArgumentException.kt similarity index 92% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/IllegalCommandArgumentException.kt rename to backend/mirai-console/src/command/IllegalCommandArgumentException.kt index 0e8936524..461f701d8 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/IllegalCommandArgumentException.kt +++ b/backend/mirai-console/src/command/IllegalCommandArgumentException.kt @@ -2,10 +2,9 @@ * 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 via the following link. + * 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 - * */ @file:Suppress("unused") diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/RawCommand.kt b/backend/mirai-console/src/command/RawCommand.kt similarity index 92% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/RawCommand.kt rename to backend/mirai-console/src/command/RawCommand.kt index 4b17e51e2..fda863120 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/RawCommand.kt +++ b/backend/mirai-console/src/command/RawCommand.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -15,7 +15,7 @@ import net.mamoe.mirai.console.command.descriptor.* import net.mamoe.mirai.console.command.java.JRawCommand import net.mamoe.mirai.console.compiler.common.ResolveContext import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.COMMAND_NAME -import net.mamoe.mirai.console.internal.command.createOrFindCommandPermission +import net.mamoe.mirai.console.internal.command.findOrCreateCommandPermission import net.mamoe.mirai.console.internal.data.typeOf0 import net.mamoe.mirai.console.permission.Permission import net.mamoe.mirai.message.data.Message @@ -53,7 +53,7 @@ public abstract class RawCommand( @OptIn(ExperimentalCommandDescriptors::class) public override val prefixOptional: Boolean = false, ) : Command { - public override val permission: Permission by lazy { createOrFindCommandPermission(parentPermission) } + public override val permission: Permission by lazy { findOrCreateCommandPermission(parentPermission) } @ExperimentalCommandDescriptors override val overloads: List = listOf( diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/SimpleCommand.kt b/backend/mirai-console/src/command/SimpleCommand.kt similarity index 95% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/SimpleCommand.kt rename to backend/mirai-console/src/command/SimpleCommand.kt index 48ce42f7c..6f78c8a42 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/SimpleCommand.kt +++ b/backend/mirai-console/src/command/SimpleCommand.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -58,9 +58,8 @@ public abstract class SimpleCommand( @ResolveContext(COMMAND_NAME) vararg secondaryNames: String, description: String = "no description available", parentPermission: Permission = owner.parentPermission, - prefixOptional: Boolean = false, overrideContext: CommandArgumentContext = EmptyCommandArgumentContext, -) : Command, AbstractCommand(owner, primaryName, secondaryNames = secondaryNames, description, parentPermission, prefixOptional), +) : Command, AbstractCommand(owner, primaryName, secondaryNames = secondaryNames, description, parentPermission), CommandArgumentContextAware { private val reflector by lazy { CommandReflector(this, SimpleCommandSubCommandAnnotationResolver) } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandArgumentContext.kt b/backend/mirai-console/src/command/descriptor/CommandArgumentContext.kt similarity index 99% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandArgumentContext.kt rename to backend/mirai-console/src/command/descriptor/CommandArgumentContext.kt index c662a2997..0540532fc 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandArgumentContext.kt +++ b/backend/mirai-console/src/command/descriptor/CommandArgumentContext.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandArgumentParserBuiltins.kt b/backend/mirai-console/src/command/descriptor/CommandArgumentParserBuiltins.kt similarity index 99% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandArgumentParserBuiltins.kt rename to backend/mirai-console/src/command/descriptor/CommandArgumentParserBuiltins.kt index 20d0665b6..4e0946376 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandArgumentParserBuiltins.kt +++ b/backend/mirai-console/src/command/descriptor/CommandArgumentParserBuiltins.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -109,7 +109,7 @@ public object PlainTextValueArgumentParser : InternalCommandValueArgumentParserE } /** - * 当字符串内容为(不区分大小写) "true", "yes", "enabled" + * 当字符串内容为(不区分大小写) "true", "yes", "enabled", "on", "1" */ public object BooleanValueArgumentParser : InternalCommandValueArgumentParserExtensions() { public override fun parse(raw: String, sender: CommandSender): Boolean = raw.trim().let { str -> @@ -117,6 +117,7 @@ public object BooleanValueArgumentParser : InternalCommandValueArgumentParserExt || str.equals("yes", ignoreCase = true) || str.equals("enabled", ignoreCase = true) || str.equals("on", ignoreCase = true) + || str.equals("1", ignoreCase = true) } } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandDescriptor.kt b/backend/mirai-console/src/command/descriptor/CommandParameter.kt similarity index 73% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandDescriptor.kt rename to backend/mirai-console/src/command/descriptor/CommandParameter.kt index 562cc9b40..225615447 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandDescriptor.kt +++ b/backend/mirai-console/src/command/descriptor/CommandParameter.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ @@ -14,93 +14,17 @@ import net.mamoe.mirai.console.command.descriptor.AbstractCommandValueParameter. import net.mamoe.mirai.console.command.descriptor.AbstractCommandValueParameter.UserDefinedType.Companion.createRequired import net.mamoe.mirai.console.command.descriptor.ArgumentAcceptance.Companion.isAcceptable import net.mamoe.mirai.console.command.parse.CommandValueArgument -import net.mamoe.mirai.console.command.resolve.ResolvedCommandCall import net.mamoe.mirai.console.internal.data.classifierAsKClass import net.mamoe.mirai.console.internal.data.classifierAsKClassOrNull import net.mamoe.mirai.console.internal.data.typeOf0 import net.mamoe.mirai.console.util.ConsoleExperimentalApi +import net.mamoe.mirai.message.data.content import kotlin.reflect.KClass -import kotlin.reflect.KFunction import kotlin.reflect.KType import kotlin.reflect.full.isSubclassOf import kotlin.reflect.full.isSubtypeOf import kotlin.reflect.typeOf -/** - * 指令签名. 表示指令定义的需要的参数. - * - * @see AbstractCommandSignature - */ -@ExperimentalCommandDescriptors -public interface CommandSignature { - /** - * 接收者参数, 为 [CommandSender] 子类 - */ - @ConsoleExperimentalApi - public val receiverParameter: CommandReceiverParameter? - - /** - * 形式 值参数. - */ - public val valueParameters: List> - - /** - * 调用这个指令. - */ - public suspend fun call(resolvedCommandCall: ResolvedCommandCall) -} - -/** - * 来自 [KFunction] 反射得到的 [CommandSignature] - * - * @see CommandSignatureFromKFunctionImpl - */ -@ConsoleExperimentalApi -@ExperimentalCommandDescriptors -public interface CommandSignatureFromKFunction : CommandSignature { - public val originFunction: KFunction<*> -} - -/** - * @see CommandSignatureImpl - * @see CommandSignatureFromKFunctionImpl - */ -@ExperimentalCommandDescriptors -public abstract class AbstractCommandSignature : CommandSignature { - override fun toString(): String { - val receiverParameter = receiverParameter - return if (receiverParameter == null) { - "CommandSignatureVariant(${valueParameters.joinToString()})" - } else { - "CommandSignatureVariant($receiverParameter, ${valueParameters.joinToString()})" - } - } -} - -@ExperimentalCommandDescriptors -public open class CommandSignatureImpl( - override val receiverParameter: CommandReceiverParameter?, - override val valueParameters: List>, - private val onCall: suspend CommandSignatureImpl.(resolvedCommandCall: ResolvedCommandCall) -> Unit, -) : CommandSignature, AbstractCommandSignature() { - override suspend fun call(resolvedCommandCall: ResolvedCommandCall) { - return onCall(resolvedCommandCall) - } -} - -@ConsoleExperimentalApi -@ExperimentalCommandDescriptors -public open class CommandSignatureFromKFunctionImpl( - override val receiverParameter: CommandReceiverParameter?, - override val valueParameters: List>, - override val originFunction: KFunction<*>, - private val onCall: suspend CommandSignatureFromKFunctionImpl.(resolvedCommandCall: ResolvedCommandCall) -> Unit, -) : CommandSignatureFromKFunction, AbstractCommandSignature() { - override suspend fun call(resolvedCommandCall: ResolvedCommandCall) { - return onCall(resolvedCommandCall) - } -} - /** * Inherited instances must be [CommandValueParameter] or [CommandReceiverParameter] @@ -181,7 +105,7 @@ public class CommandReceiverParameter( override val isOptional: Boolean, override val type: KType, ) : CommandParameter, AbstractCommandParameter() { - override val name: String get() = PARAMETER_NAME + override val name: String get() = NAME init { val classifier = type.classifier @@ -194,7 +118,7 @@ public class CommandReceiverParameter( } public companion object { - public const val PARAMETER_NAME: String = "" + public const val NAME: String = "" } } @@ -221,7 +145,7 @@ public sealed class AbstractCommandValueParameter : CommandValueParameter, return acceptingImpl(this.type, argument, commandArgumentContext) } - private fun acceptingImpl( + protected open fun acceptingImpl( expectingType: KType, argument: CommandValueArgument, commandArgumentContext: CommandArgumentContext?, @@ -261,6 +185,12 @@ public sealed class AbstractCommandValueParameter : CommandValueParameter, override fun toString(): String = "<$expectingValue>" + override fun acceptingImpl(expectingType: KType, argument: CommandValueArgument, commandArgumentContext: CommandArgumentContext?): ArgumentAcceptance { + return if (argument.value.content == expectingValue) { + ArgumentAcceptance.Direct + } else ArgumentAcceptance.Impossible + } + private companion object { @OptIn(ExperimentalStdlibApi::class) val STRING_TYPE = typeOf() diff --git a/backend/mirai-console/src/command/descriptor/CommandSignature.kt b/backend/mirai-console/src/command/descriptor/CommandSignature.kt new file mode 100644 index 000000000..efeb4618b --- /dev/null +++ b/backend/mirai-console/src/command/descriptor/CommandSignature.kt @@ -0,0 +1,90 @@ +/* + * 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.command.descriptor + +import net.mamoe.mirai.console.command.CommandSender +import net.mamoe.mirai.console.command.resolve.ResolvedCommandCall +import net.mamoe.mirai.console.util.ConsoleExperimentalApi +import kotlin.reflect.KFunction + +/** + * 指令签名. 表示指令定义的需要的参数. + * + * @see AbstractCommandSignature + */ +@ExperimentalCommandDescriptors +public interface CommandSignature { + /** + * 接收者参数, 为 [CommandSender] 子类 + */ + @ConsoleExperimentalApi + public val receiverParameter: CommandReceiverParameter? + + /** + * 形式 值参数. + */ + public val valueParameters: List> + + /** + * 调用这个指令. + */ + public suspend fun call(resolvedCommandCall: ResolvedCommandCall) +} + +/** + * 来自 [KFunction] 反射得到的 [CommandSignature] + * + * @see CommandSignatureFromKFunctionImpl + */ +@ConsoleExperimentalApi +@ExperimentalCommandDescriptors +public interface CommandSignatureFromKFunction : CommandSignature { + public val originFunction: KFunction<*> +} + +/** + * @see CommandSignatureImpl + * @see CommandSignatureFromKFunctionImpl + */ +@ExperimentalCommandDescriptors +public abstract class AbstractCommandSignature : CommandSignature { + override fun toString(): String { + val receiverParameter = receiverParameter + return if (receiverParameter == null) { + "CommandSignatureVariant(${valueParameters.joinToString()})" + } else { + "CommandSignatureVariant($receiverParameter, ${valueParameters.joinToString()})" + } + } +} + +@ExperimentalCommandDescriptors +public open class CommandSignatureImpl( + override val receiverParameter: CommandReceiverParameter?, + override val valueParameters: List>, + private val onCall: suspend CommandSignatureImpl.(resolvedCommandCall: ResolvedCommandCall) -> Unit, +) : CommandSignature, AbstractCommandSignature() { + override suspend fun call(resolvedCommandCall: ResolvedCommandCall) { + return onCall(resolvedCommandCall) + } +} + +@ConsoleExperimentalApi +@ExperimentalCommandDescriptors +public open class CommandSignatureFromKFunctionImpl( + override val receiverParameter: CommandReceiverParameter?, + override val valueParameters: List>, + override val originFunction: KFunction<*>, + private val onCall: suspend CommandSignatureFromKFunctionImpl.(resolvedCommandCall: ResolvedCommandCall) -> Unit, +) : CommandSignatureFromKFunction, AbstractCommandSignature() { + override suspend fun call(resolvedCommandCall: ResolvedCommandCall) { + return onCall(resolvedCommandCall) + } +} \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandValueArgumentParser.kt b/backend/mirai-console/src/command/descriptor/CommandValueArgumentParser.kt similarity index 98% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandValueArgumentParser.kt rename to backend/mirai-console/src/command/descriptor/CommandValueArgumentParser.kt index 75c373519..e8d4e67b3 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandValueArgumentParser.kt +++ b/backend/mirai-console/src/command/descriptor/CommandValueArgumentParser.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/Exceptions.kt b/backend/mirai-console/src/command/descriptor/Exceptions.kt similarity index 92% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/Exceptions.kt rename to backend/mirai-console/src/command/descriptor/Exceptions.kt index 4ce6f7338..434983625 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/Exceptions.kt +++ b/backend/mirai-console/src/command/descriptor/Exceptions.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/ExperimentalCommandDescriptors.kt b/backend/mirai-console/src/command/descriptor/ExperimentalCommandDescriptors.kt similarity index 81% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/ExperimentalCommandDescriptors.kt rename to backend/mirai-console/src/command/descriptor/ExperimentalCommandDescriptors.kt index 31ee99b7c..20b04a79b 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/ExperimentalCommandDescriptors.kt +++ b/backend/mirai-console/src/command/descriptor/ExperimentalCommandDescriptors.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/TypeVariant.kt b/backend/mirai-console/src/command/descriptor/TypeVariant.kt similarity index 92% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/TypeVariant.kt rename to backend/mirai-console/src/command/descriptor/TypeVariant.kt index 4e2792638..2a4d49a82 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/TypeVariant.kt +++ b/backend/mirai-console/src/command/descriptor/TypeVariant.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/java/JCompositeCommand.kt b/backend/mirai-console/src/command/java/JCompositeCommand.kt similarity index 97% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/java/JCompositeCommand.kt rename to backend/mirai-console/src/command/java/JCompositeCommand.kt index b3828418d..aecefc529 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/java/JCompositeCommand.kt +++ b/backend/mirai-console/src/command/java/JCompositeCommand.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/java/JRawCommand.kt b/backend/mirai-console/src/command/java/JRawCommand.kt similarity index 91% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/java/JRawCommand.kt rename to backend/mirai-console/src/command/java/JRawCommand.kt index 70b62e680..e3cf80512 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/java/JRawCommand.kt +++ b/backend/mirai-console/src/command/java/JRawCommand.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -16,7 +16,7 @@ import net.mamoe.mirai.console.command.CommandOwner import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors import net.mamoe.mirai.console.compiler.common.ResolveContext import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.COMMAND_NAME -import net.mamoe.mirai.console.internal.command.createOrFindCommandPermission +import net.mamoe.mirai.console.internal.command.findOrCreateCommandPermission import net.mamoe.mirai.console.permission.Permission /** @@ -65,7 +65,7 @@ public abstract class JRawCommand protected set /** 指令权限 */ - public final override var permission: Permission = createOrFindCommandPermission(parentPermission) + public final override var permission: Permission = findOrCreateCommandPermission(parentPermission) protected set /** 为 `true` 时表示 [指令前缀][CommandManager.commandPrefix] 可选 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/java/JSimpleCommand.kt b/backend/mirai-console/src/command/java/JSimpleCommand.kt similarity index 96% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/java/JSimpleCommand.kt rename to backend/mirai-console/src/command/java/JSimpleCommand.kt index 706a14df4..d5aa6d3ed 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/java/JSimpleCommand.kt +++ b/backend/mirai-console/src/command/java/JSimpleCommand.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/parse/CommandCall.kt b/backend/mirai-console/src/command/parse/CommandCall.kt similarity index 83% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/parse/CommandCall.kt rename to backend/mirai-console/src/command/parse/CommandCall.kt index 4bb43bb9e..a7dabba62 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/parse/CommandCall.kt +++ b/backend/mirai-console/src/command/parse/CommandCall.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/parse/CommandCallParser.kt b/backend/mirai-console/src/command/parse/CommandCallParser.kt similarity index 82% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/parse/CommandCallParser.kt rename to backend/mirai-console/src/command/parse/CommandCallParser.kt index 4d4bc6f59..92baa6184 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/parse/CommandCallParser.kt +++ b/backend/mirai-console/src/command/parse/CommandCallParser.kt @@ -1,3 +1,12 @@ +/* + * 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.command.parse import net.mamoe.mirai.console.command.CommandSender diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/parse/CommandValueArgument.kt b/backend/mirai-console/src/command/parse/CommandValueArgument.kt similarity index 95% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/parse/CommandValueArgument.kt rename to backend/mirai-console/src/command/parse/CommandValueArgument.kt index 30e908e60..03b2771d5 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/parse/CommandValueArgument.kt +++ b/backend/mirai-console/src/command/parse/CommandValueArgument.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/parse/SpaceSeparatedCommandCallParser.kt b/backend/mirai-console/src/command/parse/SpaceSeparatedCommandCallParser.kt similarity index 75% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/parse/SpaceSeparatedCommandCallParser.kt rename to backend/mirai-console/src/command/parse/SpaceSeparatedCommandCallParser.kt index b17cabdaf..45a077dad 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/parse/SpaceSeparatedCommandCallParser.kt +++ b/backend/mirai-console/src/command/parse/SpaceSeparatedCommandCallParser.kt @@ -1,3 +1,12 @@ +/* + * 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.command.parse import net.mamoe.mirai.console.command.CommandSender diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/resolve/BuiltInCommandCallResolver.kt b/backend/mirai-console/src/command/resolve/BuiltInCommandCallResolver.kt similarity index 94% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/resolve/BuiltInCommandCallResolver.kt rename to backend/mirai-console/src/command/resolve/BuiltInCommandCallResolver.kt index 7f43e3d2b..f07b09eca 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/resolve/BuiltInCommandCallResolver.kt +++ b/backend/mirai-console/src/command/resolve/BuiltInCommandCallResolver.kt @@ -1,3 +1,12 @@ +/* + * 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.command.resolve import net.mamoe.mirai.console.command.Command diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/resolve/CommandCallResolver.kt b/backend/mirai-console/src/command/resolve/CommandCallResolver.kt similarity index 87% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/resolve/CommandCallResolver.kt rename to backend/mirai-console/src/command/resolve/CommandCallResolver.kt index 8022f532b..e4a0ff675 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/resolve/CommandCallResolver.kt +++ b/backend/mirai-console/src/command/resolve/CommandCallResolver.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/resolve/ResolvedCommandCall.kt b/backend/mirai-console/src/command/resolve/ResolvedCommandCall.kt similarity index 93% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/resolve/ResolvedCommandCall.kt rename to backend/mirai-console/src/command/resolve/ResolvedCommandCall.kt index 5b48c74b9..8b24788cc 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/resolve/ResolvedCommandCall.kt +++ b/backend/mirai-console/src/command/resolve/ResolvedCommandCall.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/compiler/common/ResolveContext.kt b/backend/mirai-console/src/common/ResolveContext.kt similarity index 92% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/compiler/common/ResolveContext.kt rename to backend/mirai-console/src/common/ResolveContext.kt index 350e20ada..93a5006e3 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/compiler/common/ResolveContext.kt +++ b/backend/mirai-console/src/common/ResolveContext.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/compiler/common/RestrictedScope.kt b/backend/mirai-console/src/common/RestrictedScope.kt similarity index 78% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/compiler/common/RestrictedScope.kt rename to backend/mirai-console/src/common/RestrictedScope.kt index 640016cc7..f4f4f1215 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/compiler/common/RestrictedScope.kt +++ b/backend/mirai-console/src/common/RestrictedScope.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AbstractPluginData.kt b/backend/mirai-console/src/data/AbstractPluginData.kt similarity index 96% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AbstractPluginData.kt rename to backend/mirai-console/src/data/AbstractPluginData.kt index 90b22bd06..6bbc507a4 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AbstractPluginData.kt +++ b/backend/mirai-console/src/data/AbstractPluginData.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -23,6 +23,9 @@ import kotlin.reflect.KProperty /** * [PluginData] 的默认实现. 支持使用 `by value()` 等委托方法创建 [Value] 并跟踪其改动. * + * ### 实现注意 + * 此类型处于实验性阶段. 使用其中定义的属性和函数是安全的, 但将来可能会新增成员抽象函数. + * * @see PluginData */ public abstract class AbstractPluginData : PluginData, PluginDataImpl() { diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AutoSavePluginConfig.kt b/backend/mirai-console/src/data/AutoSavePluginConfig.kt similarity index 53% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AutoSavePluginConfig.kt rename to backend/mirai-console/src/data/AutoSavePluginConfig.kt index 1e3793e5a..da08e4493 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AutoSavePluginConfig.kt +++ b/backend/mirai-console/src/data/AutoSavePluginConfig.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ @@ -23,10 +23,4 @@ import kotlinx.coroutines.Job * @see PluginConfig * @see AutoSavePluginData */ -public open class AutoSavePluginConfig : AutoSavePluginData, PluginConfig { - @Deprecated("请手动指定保存名称. 此构造器将在 1.0.0 删除", level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("AutoSavePluginConfig(\"把我改成保存名称\")")) - @Suppress("DEPRECATION_ERROR") - public constructor() : super() - - public constructor(saveName: String) : super(saveName) -} +public open class AutoSavePluginConfig public constructor(saveName: String) : AutoSavePluginData(saveName), PluginConfig \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AutoSavePluginData.kt b/backend/mirai-console/src/data/AutoSavePluginData.kt similarity index 91% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AutoSavePluginData.kt rename to backend/mirai-console/src/data/AutoSavePluginData.kt index f081af4d2..63bbd64d2 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AutoSavePluginData.kt +++ b/backend/mirai-console/src/data/AutoSavePluginData.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -18,7 +18,6 @@ import net.mamoe.mirai.console.internal.data.qualifiedNameOrTip import net.mamoe.mirai.console.internal.plugin.updateWhen import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.utils.* -import kotlin.reflect.full.findAnnotation /** * 链接自动保存的 [PluginData]. @@ -46,14 +45,6 @@ public open class AutoSavePluginData private constructor( _saveName = saveName } - @Deprecated("请手动指定保存名称. 此构造器将在 1.0.0 删除", level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("AutoSavePluginData(\"把我改成保存名称\")")) - public constructor() : this(null) { - val clazz = this::class - _saveName = clazz.findAnnotation()?.value - ?: clazz.qualifiedName - ?: throw IllegalArgumentException("Cannot find a serial name for ${this::class}") - } - @ConsoleExperimentalApi override fun onInit(owner: PluginDataHolder, storage: PluginDataStorage) { check(owner is AutoSavePluginDataHolder) { "owner must be AutoSavePluginDataHolder for AutoSavePluginData" } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AutoSavePluginDataHolder.kt b/backend/mirai-console/src/data/AutoSavePluginDataHolder.kt similarity index 76% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AutoSavePluginDataHolder.kt rename to backend/mirai-console/src/data/AutoSavePluginDataHolder.kt index 2237e1ec7..bf4e78344 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AutoSavePluginDataHolder.kt +++ b/backend/mirai-console/src/data/AutoSavePluginDataHolder.kt @@ -1,3 +1,12 @@ +/* + * 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.data import kotlinx.coroutines.CoroutineExceptionHandler diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginConfig.kt b/backend/mirai-console/src/data/PluginConfig.kt similarity index 94% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginConfig.kt rename to backend/mirai-console/src/data/PluginConfig.kt index 88f74e033..807c1039e 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginConfig.kt +++ b/backend/mirai-console/src/data/PluginConfig.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginData.kt b/backend/mirai-console/src/data/PluginData.kt similarity index 96% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginData.kt rename to backend/mirai-console/src/data/PluginData.kt index 174170e1b..2da279502 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginData.kt +++ b/backend/mirai-console/src/data/PluginData.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -98,13 +98,16 @@ import kotlin.reflect.KType * ``` * // MyPluginData.nestedMap: MutableMap> by value() * val newList = MyPluginData.map.getOrPut(1, ::mutableListOf) - * newList.add(1) // 不会添加到 MyPluginData.nestedMap 中, 因为 `mutableListOf` 创建的 MutableList 被非引用地添加进了 MyPluginData.nestedMap + * newList.add(1) // 不会添加到 MyPluginData.nestedMap 中, 因为 `mutableListOf` 创建的 MutableList 被非引用 (浅拷贝) 地添加进了 MyPluginData.nestedMap * ``` * * 一个解决方案是对 [SerializerAwareValue] 做映射或相关修改. 如 [PluginDataExtensions]. * * 要查看详细的解释,请查看 [docs/PluginData.md](https://github.com/mamoe/mirai-console/blob/master/docs/PluginData.md) * + * ## 实现注意 + * 此类型处于实验性阶段. 使用其中定义的属性和函数是安全的, 但将来可能会新增成员抽象函数. + * * @see AbstractJvmPlugin.reloadPluginData 通过 [JvmPlugin] 获取指定 [PluginData] 实例. * @see PluginDataStorage [PluginData] 存储仓库 * @see PluginDataExtensions 相关 [SerializerAwareValue] 映射函数 diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataExtensions.kt b/backend/mirai-console/src/data/PluginDataExtensions.kt similarity index 97% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataExtensions.kt rename to backend/mirai-console/src/data/PluginDataExtensions.kt index 654687d49..69af2f6a9 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataExtensions.kt +++ b/backend/mirai-console/src/data/PluginDataExtensions.kt @@ -1,3 +1,12 @@ +/* + * 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 + */ + @file:Suppress("unused", "INAPPLICABLE_JVM_NAME", "INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") package net.mamoe.mirai.console.data diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataHolder.kt b/backend/mirai-console/src/data/PluginDataHolder.kt similarity index 96% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataHolder.kt rename to backend/mirai-console/src/data/PluginDataHolder.kt index af2bae5db..302cc7046 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataHolder.kt +++ b/backend/mirai-console/src/data/PluginDataHolder.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataStorage.kt b/backend/mirai-console/src/data/PluginDataStorage.kt similarity index 98% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataStorage.kt rename to backend/mirai-console/src/data/PluginDataStorage.kt index 8e4e667ac..e10310c51 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataStorage.kt +++ b/backend/mirai-console/src/data/PluginDataStorage.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/Value.kt b/backend/mirai-console/src/data/Value.kt similarity index 96% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/Value.kt rename to backend/mirai-console/src/data/Value.kt index 14bc75e65..5535ad8c9 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/Value.kt +++ b/backend/mirai-console/src/data/Value.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -156,6 +156,7 @@ public interface SerializerAwareValue : Value { * 注意: 目前这些类型都会被装箱, 由于泛型 T. 在将来可能会有优化处理. * *Primitive* 仅表示一个类型是上面 9 种类型之一. */ +@ConsoleExperimentalApi public interface PrimitiveValue : Value @@ -164,46 +165,55 @@ public interface PrimitiveValue : Value /** * 表示一个不可空 [Byte] [Value]. */ +@ConsoleExperimentalApi public interface ByteValue : PrimitiveValue /** * 表示一个不可空 [Short] [Value]. */ +@ConsoleExperimentalApi public interface ShortValue : PrimitiveValue /** * 表示一个不可空 [Int] [Value]. */ +@ConsoleExperimentalApi public interface IntValue : PrimitiveValue /** * 表示一个不可空 [Long] [Value]. */ +@ConsoleExperimentalApi public interface LongValue : PrimitiveValue /** * 表示一个不可空 [Float] [Value]. */ +@ConsoleExperimentalApi public interface FloatValue : PrimitiveValue /** * 表示一个不可空 [Double] [Value]. */ +@ConsoleExperimentalApi public interface DoubleValue : PrimitiveValue /** * 表示一个不可空 [Char] [Value]. */ +@ConsoleExperimentalApi public interface CharValue : PrimitiveValue /** * 表示一个不可空 [Boolean] [Value]. */ +@ConsoleExperimentalApi public interface BooleanValue : PrimitiveValue /** * 表示一个不可空 [String] [Value]. */ +@ConsoleExperimentalApi public interface StringValue : PrimitiveValue //// endregion PrimitiveValues CODEGEN //// diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/ValueDescription.kt b/backend/mirai-console/src/data/ValueDescription.kt similarity index 80% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/ValueDescription.kt rename to backend/mirai-console/src/data/ValueDescription.kt index 907944766..aeeaaf9c8 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/ValueDescription.kt +++ b/backend/mirai-console/src/data/ValueDescription.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -35,4 +35,9 @@ import kotlinx.serialization.SerialInfo @SerialInfo @Target(AnnotationTarget.PROPERTY, AnnotationTarget.CLASS) @Retention(AnnotationRetention.RUNTIME) -public annotation class ValueDescription(val value: String) \ No newline at end of file +public annotation class ValueDescription( + /** + * 将会被 [String.trimIndent] 处理. + */ + val value: String, +) \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/ValueName.kt b/backend/mirai-console/src/data/ValueName.kt similarity index 91% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/ValueName.kt rename to backend/mirai-console/src/data/ValueName.kt index e9de3a500..17f101429 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/ValueName.kt +++ b/backend/mirai-console/src/data/ValueName.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/java/JAutoSavePluginConfig.kt b/backend/mirai-console/src/data/java/JAutoSavePluginConfig.kt similarity index 71% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/java/JAutoSavePluginConfig.kt rename to backend/mirai-console/src/data/java/JAutoSavePluginConfig.kt index 1ca820466..05cee4d5f 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/java/JAutoSavePluginConfig.kt +++ b/backend/mirai-console/src/data/java/JAutoSavePluginConfig.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -37,10 +37,4 @@ import net.mamoe.mirai.console.data.PluginData * @see JAutoSavePluginData * @see PluginConfig */ -public abstract class JAutoSavePluginConfig : AutoSavePluginConfig, PluginConfig { - @Deprecated("请手动指定保存名称. 此构造器将在 1.0.0 删除", level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("JAutoSavePluginConfig(\"把我改成保存名称\")")) - @Suppress("DEPRECATION_ERROR") - public constructor() : super() - - public constructor(saveName: String) : super(saveName) -} +public abstract class JAutoSavePluginConfig public constructor(saveName: String) : AutoSavePluginConfig(saveName), PluginConfig \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/java/JAutoSavePluginData.kt b/backend/mirai-console/src/data/java/JAutoSavePluginData.kt similarity index 92% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/java/JAutoSavePluginData.kt rename to backend/mirai-console/src/data/java/JAutoSavePluginData.kt index 442f19cc9..5118f5ecf 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/java/JAutoSavePluginData.kt +++ b/backend/mirai-console/src/data/java/JAutoSavePluginData.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -66,12 +66,7 @@ import kotlin.reflect.full.createType * * @see PluginData */ -public abstract class JAutoSavePluginData : AutoSavePluginData, PluginConfig { - @Deprecated("请手动指定保存名称. 此构造器将在 1.0.0 删除", level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("JAutoSavePluginData(\"把我改成保存名称\")")) - @Suppress("DEPRECATION_ERROR") - public constructor() : super() - - public constructor(saveName: String) : super(saveName) +public abstract class JAutoSavePluginData public constructor(saveName: String) : AutoSavePluginData(saveName), PluginConfig { //// region JPluginData_value_primitives CODEGEN //// diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/events/CommandExecutionEvent.kt b/backend/mirai-console/src/events/CommandExecutionEvent.kt similarity index 93% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/events/CommandExecutionEvent.kt rename to backend/mirai-console/src/events/CommandExecutionEvent.kt index 4edbcea61..360750b25 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/events/CommandExecutionEvent.kt +++ b/backend/mirai-console/src/events/CommandExecutionEvent.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/events/ConsoleEvent.kt b/backend/mirai-console/src/events/ConsoleEvent.kt similarity index 85% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/events/ConsoleEvent.kt rename to backend/mirai-console/src/events/ConsoleEvent.kt index bc7399958..3616ce54d 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/events/ConsoleEvent.kt +++ b/backend/mirai-console/src/events/ConsoleEvent.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extension/ComponentStorage.kt b/backend/mirai-console/src/extension/ComponentStorage.kt similarity index 80% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extension/ComponentStorage.kt rename to backend/mirai-console/src/extension/ComponentStorage.kt index 62b7b47c2..f70167db5 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extension/ComponentStorage.kt +++ b/backend/mirai-console/src/extension/ComponentStorage.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extension/Extension.kt b/backend/mirai-console/src/extension/Extension.kt similarity index 89% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extension/Extension.kt rename to backend/mirai-console/src/extension/Extension.kt index 744fbd719..584a0dda6 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extension/Extension.kt +++ b/backend/mirai-console/src/extension/Extension.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extension/ExtensionException.kt b/backend/mirai-console/src/extension/ExtensionException.kt similarity index 75% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extension/ExtensionException.kt rename to backend/mirai-console/src/extension/ExtensionException.kt index 3b4025c94..774d0a2af 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extension/ExtensionException.kt +++ b/backend/mirai-console/src/extension/ExtensionException.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extension/ExtensionPoint.kt b/backend/mirai-console/src/extension/ExtensionPoint.kt similarity index 87% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extension/ExtensionPoint.kt rename to backend/mirai-console/src/extension/ExtensionPoint.kt index b5580db83..b2cfa16e7 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extension/ExtensionPoint.kt +++ b/backend/mirai-console/src/extension/ExtensionPoint.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ @@ -50,7 +50,8 @@ public interface InstanceExtensionPoint> : ExtensionPoi public interface FunctionExtensionPoint : ExtensionPoint -public abstract class AbstractInstanceExtensionPoint, T>( +public abstract class AbstractInstanceExtensionPoint, T> +@ConsoleExperimentalApi constructor( extensionType: KClass, /** * 内建的实现列表. @@ -59,7 +60,8 @@ public abstract class AbstractInstanceExtensionPoint, T public vararg val builtinImplementations: E, ) : AbstractExtensionPoint(extensionType) -public abstract class AbstractSingletonExtensionPoint, T>( +public abstract class AbstractSingletonExtensionPoint, T> +@ConsoleExperimentalApi constructor( extensionType: KClass, /** * 内建的实现. diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extension/PluginComponentStorage.kt b/backend/mirai-console/src/extension/PluginComponentStorage.kt similarity index 96% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extension/PluginComponentStorage.kt rename to backend/mirai-console/src/extension/PluginComponentStorage.kt index 2eb1451ad..4cb05874f 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extension/PluginComponentStorage.kt +++ b/backend/mirai-console/src/extension/PluginComponentStorage.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/BotConfigurationAlterer.kt b/backend/mirai-console/src/extensions/BotConfigurationAlterer.kt similarity index 83% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/BotConfigurationAlterer.kt rename to backend/mirai-console/src/extensions/BotConfigurationAlterer.kt index 642d5ea9b..53b278368 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/BotConfigurationAlterer.kt +++ b/backend/mirai-console/src/extensions/BotConfigurationAlterer.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/CommandCallParserProvider.kt b/backend/mirai-console/src/extensions/CommandCallParserProvider.kt similarity index 75% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/CommandCallParserProvider.kt rename to backend/mirai-console/src/extensions/CommandCallParserProvider.kt index 51cc23a9f..9a31864ca 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/CommandCallParserProvider.kt +++ b/backend/mirai-console/src/extensions/CommandCallParserProvider.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ @@ -30,6 +30,6 @@ public interface CommandCallParserProvider : InstanceExtension CommandCallParser) : CommandCallParserProvider { - override val instance: CommandCallParser by lazy(instanceCalculator) +public class CommandCallParserProviderImplLazy(initializer: () -> CommandCallParser) : CommandCallParserProvider { + override val instance: CommandCallParser by lazy(initializer) } \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/CommandCallResolverProvider.kt b/backend/mirai-console/src/extensions/CommandCallResolverProvider.kt similarity index 74% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/CommandCallResolverProvider.kt rename to backend/mirai-console/src/extensions/CommandCallResolverProvider.kt index 43e2a6fca..bf63c771d 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/CommandCallResolverProvider.kt +++ b/backend/mirai-console/src/extensions/CommandCallResolverProvider.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ @@ -26,6 +26,6 @@ public interface CommandCallResolverProvider : InstanceExtension CommandCallResolver) : CommandCallResolverProvider { - override val instance: CommandCallResolver by lazy(instanceCalculator) +public class CommandCallResolverProviderImplLazy(initializer: () -> CommandCallResolver) : CommandCallResolverProvider { + override val instance: CommandCallResolver by lazy(initializer) } \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/PermissionServiceProvider.kt b/backend/mirai-console/src/extensions/PermissionServiceProvider.kt similarity index 86% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/PermissionServiceProvider.kt rename to backend/mirai-console/src/extensions/PermissionServiceProvider.kt index e5c353ae7..d47043993 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/PermissionServiceProvider.kt +++ b/backend/mirai-console/src/extensions/PermissionServiceProvider.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/PluginLoaderProvider.kt b/backend/mirai-console/src/extensions/PluginLoaderProvider.kt similarity index 85% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/PluginLoaderProvider.kt rename to backend/mirai-console/src/extensions/PluginLoaderProvider.kt index 6722e9743..0352ca17e 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/PluginLoaderProvider.kt +++ b/backend/mirai-console/src/extensions/PluginLoaderProvider.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/PostStartupExtension.kt b/backend/mirai-console/src/extensions/PostStartupExtension.kt similarity index 86% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/PostStartupExtension.kt rename to backend/mirai-console/src/extensions/PostStartupExtension.kt index f18185e17..3e3015771 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/PostStartupExtension.kt +++ b/backend/mirai-console/src/extensions/PostStartupExtension.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ @@ -24,10 +24,10 @@ public fun interface PostStartupExtension : FunctionExtension { /** * 将在 Console 主线程执行. * - * @throws Exception 所有抛出的 [Exception] 都会被捕获并包装为 [ExtensionException] 抛出, 并停止 [MiraiConsole] - * * #### 内部实现细节 * 在 [MiraiConsoleImplementationBridge.doStart] 所有 [MiraiConsoleImplementationBridge.phase] 执行完成后顺序调用. + * + * @throws Exception 所有抛出的 [Exception] 都会被捕获并包装为 [ExtensionException] 抛出, 并停止 [MiraiConsole] */ @Throws(Exception::class) public operator fun invoke() diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/SingletonExtensionSelector.kt b/backend/mirai-console/src/extensions/SingletonExtensionSelector.kt similarity index 90% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/SingletonExtensionSelector.kt rename to backend/mirai-console/src/extensions/SingletonExtensionSelector.kt index 2dfce8f6c..70d48a7fd 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/SingletonExtensionSelector.kt +++ b/backend/mirai-console/src/extensions/SingletonExtensionSelector.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ @@ -28,13 +28,16 @@ import kotlin.reflect.KClass * 如有多个 [SingletonExtensionSelector] 注册, 将会停止服务器. */ public interface SingletonExtensionSelector : FunctionExtension { + /** + * 表示一个插件注册的 [Extension] + */ public data class Registry( val plugin: Plugin?, val extension: T, ) /** - * @return null 表示使用 builtin + * @return `null` 表示使用 Console 内置的 [SingletonExtensionSelector] */ public fun selectSingleton( extensionType: KClass, diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleBuildConstants.kt b/backend/mirai-console/src/internal/MiraiConsoleBuildConstants.kt similarity index 76% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleBuildConstants.kt rename to backend/mirai-console/src/internal/MiraiConsoleBuildConstants.kt index b3abe5cbd..418852398 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleBuildConstants.kt +++ b/backend/mirai-console/src/internal/MiraiConsoleBuildConstants.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -14,8 +14,8 @@ import java.time.Instant internal object MiraiConsoleBuildConstants { // auto-filled on build (task :mirai-console:fillBuildConstants) @JvmStatic - val buildDate: Instant = Instant.ofEpochSecond(1601134282) - const val versionConst: String = "1.0-RC-dev-29" + val buildDate: Instant = Instant.ofEpochSecond(1604041264) + const val versionConst: String = "1.0-RC-1" @JvmStatic val version: SemVersion = SemVersion(versionConst) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt b/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt similarity index 98% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt rename to backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt index 2389a8c36..4db45a43f 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt +++ b/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -244,6 +244,9 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI @DslMarker internal annotation class ILoveOmaeKumikoForever + /** + * 表示一个初始化阶段, 无实际作用. + */ @ILoveOmaeKumikoForever private inline fun phase(block: () -> Unit) { contract { diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/command/CommandManagerImpl.kt b/backend/mirai-console/src/internal/command/CommandManagerImpl.kt similarity index 98% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/command/CommandManagerImpl.kt rename to backend/mirai-console/src/internal/command/CommandManagerImpl.kt index f0bc776ca..82e472477 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/command/CommandManagerImpl.kt +++ b/backend/mirai-console/src/internal/command/CommandManagerImpl.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/command/CommandReflector.kt b/backend/mirai-console/src/internal/command/CommandReflector.kt similarity index 83% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/command/CommandReflector.kt rename to backend/mirai-console/src/internal/command/CommandReflector.kt index a85a7a8f8..1bf73d773 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/command/CommandReflector.kt +++ b/backend/mirai-console/src/internal/command/CommandReflector.kt @@ -1,3 +1,12 @@ +/* + * 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.command.* @@ -57,12 +66,12 @@ internal object SimpleCommandSubCommandAnnotationResolver : function.hasAnnotation() override fun getSubCommandNames(ownerCommand: Command, function: KFunction<*>): Array = - ownerCommand.secondaryNames + emptyArray() override fun getAnnotatedName(ownerCommand: Command, parameter: KParameter): String? = parameter.findAnnotation()?.value - override fun getDescription(ownerCommand: Command, function: KFunction<*>): String? = + override fun getDescription(ownerCommand: Command, function: KFunction<*>): String = ownerCommand.description } @@ -144,13 +153,13 @@ internal class CommandReflector( } else { append(CommandManager.commandPrefix) } - if (command is CompositeCommand) { - append(command.primaryName) - append(" ") - } + //if (command is CompositeCommand) { + append(command.primaryName) + append(" ") + //} append(subcommand.valueParameters.joinToString(" ") { it.render() }) - annotationResolver.getDescription(command, subcommand.originFunction).let { description -> - append(" ") + annotationResolver.getDescription(command, subcommand.originFunction)?.let { description -> + append(" # ") append(description) } } @@ -219,10 +228,16 @@ internal class CommandReflector( .onEach { it.checkExtensionReceiver() } .onEach { it.checkModifiers() } .onEach { it.checkNames() } - .map { function -> + .flatMap { function -> + val names = annotationResolver.getSubCommandNames(command, function) + if (names.isEmpty()) sequenceOf(createMapEntry(null, function)) + else names.associateWith { function }.asSequence() + } + .map { (name, function) -> val functionNameAsValueParameter = - annotationResolver.getSubCommandNames(command, function).mapIndexed { index, s -> createStringConstantParameter(index, s) } + name?.split(' ')?.mapIndexed { index, s -> createStringConstantParameter(index, s) } + .orEmpty() val functionValueParameters = function.valueParameters.associateBy { it.toUserDefinedCommandParameter() } @@ -245,14 +260,32 @@ internal class CommandReflector( val instanceParameter = function.instanceParameter if (instanceParameter != null) { + check(instanceParameter.type.classifierAsKClass().isInstance(command)) { + "Bad command call resolved. " + + "Function expects instance parameter ${instanceParameter.type} whereas actual instance is ${command::class}." + } args[instanceParameter] = command } + + val receiverParameter = function.extensionReceiverParameter + if (receiverParameter != null) { + check(receiverParameter.type.classifierAsKClass().isInstance(call.caller)) { + "Bad command call resolved. " + + "Function expects receiver parameter ${receiverParameter.type} whereas actual is ${call.caller::class}." + } + args[receiverParameter] = call.caller + } function.callSuspendBy(args) } }.toList() } - private fun KParameter.toCommandReceiverParameter(): CommandReceiverParameter? { + private fun createMapEntry(key: K, value: V) = object : Map.Entry { + override val key: K get() = key + override val value: V get() = value + } + + private fun KParameter.toCommandReceiverParameter(): CommandReceiverParameter { check(!this.isVararg) { "Receiver cannot be vararg." } check(this.type.classifierAsKClass().isSubclassOf(CommandSender::class)) { "Receiver must be subclass of CommandSender" } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/command/internal.kt b/backend/mirai-console/src/internal/command/internal.kt similarity index 94% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/command/internal.kt rename to backend/mirai-console/src/internal/command/internal.kt index a1ebfbf2e..094462f0c 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/command/internal.kt +++ b/backend/mirai-console/src/internal/command/internal.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -58,6 +58,7 @@ internal fun Group.fuzzySearchMember( disambiguationRate: Double = 0.1, ): List> { val candidates = (this.members + botAsMember) + .asSequence() .associateWith { it.nameCard.fuzzyMatchWith(nameCardTarget) } .filter { it.value >= minRate } .toList() @@ -79,7 +80,7 @@ internal fun Group.fuzzySearchMember( } } -internal fun Command.createOrFindCommandPermission(parent: Permission): Permission { +internal fun Command.findOrCreateCommandPermission(parent: Permission): Permission { val id = owner.permissionId("command.$primaryName") return PermissionService.INSTANCE[id] ?: PermissionService.INSTANCE.register(id, description, parent) } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/CompositeValueImpl.kt b/backend/mirai-console/src/internal/data/CompositeValueImpl.kt similarity index 98% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/CompositeValueImpl.kt rename to backend/mirai-console/src/internal/data/CompositeValueImpl.kt index c45d135ab..910cc04b0 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/CompositeValueImpl.kt +++ b/backend/mirai-console/src/internal/data/CompositeValueImpl.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/MemoryPluginDataStorageImpl.kt b/backend/mirai-console/src/internal/data/MemoryPluginDataStorageImpl.kt similarity index 92% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/MemoryPluginDataStorageImpl.kt rename to backend/mirai-console/src/internal/data/MemoryPluginDataStorageImpl.kt index 3f089d888..ec4794f2e 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/MemoryPluginDataStorageImpl.kt +++ b/backend/mirai-console/src/internal/data/MemoryPluginDataStorageImpl.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/MultiFilePluginDataStorageImpl.kt b/backend/mirai-console/src/internal/data/MultiFilePluginDataStorageImpl.kt similarity index 98% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/MultiFilePluginDataStorageImpl.kt rename to backend/mirai-console/src/internal/data/MultiFilePluginDataStorageImpl.kt index e8226315d..a9e9a1f2c 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/MultiFilePluginDataStorageImpl.kt +++ b/backend/mirai-console/src/internal/data/MultiFilePluginDataStorageImpl.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/PluginDataImpl.kt b/backend/mirai-console/src/internal/data/PluginDataImpl.kt similarity index 98% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/PluginDataImpl.kt rename to backend/mirai-console/src/internal/data/PluginDataImpl.kt index e52d4d79a..8792e94a3 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/PluginDataImpl.kt +++ b/backend/mirai-console/src/internal/data/PluginDataImpl.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/_PluginData.value.kt b/backend/mirai-console/src/internal/data/_PluginData.value.kt similarity index 98% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/_PluginData.value.kt rename to backend/mirai-console/src/internal/data/_PluginData.value.kt index 7e045e30e..282b60bb8 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/_PluginData.value.kt +++ b/backend/mirai-console/src/internal/data/_PluginData.value.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/_PrimitiveValueDeclarations.kt b/backend/mirai-console/src/internal/data/_PrimitiveValueDeclarations.kt similarity index 99% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/_PrimitiveValueDeclarations.kt rename to backend/mirai-console/src/internal/data/_PrimitiveValueDeclarations.kt index 44c11ee9f..aac45983b 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/_PrimitiveValueDeclarations.kt +++ b/backend/mirai-console/src/internal/data/_PrimitiveValueDeclarations.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/AutoLoginConfig.kt b/backend/mirai-console/src/internal/data/builtins/AutoLoginConfig.kt similarity index 67% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/AutoLoginConfig.kt rename to backend/mirai-console/src/internal/data/builtins/AutoLoginConfig.kt index 5cf269874..a871d754a 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/AutoLoginConfig.kt +++ b/backend/mirai-console/src/internal/data/builtins/AutoLoginConfig.kt @@ -1,3 +1,12 @@ +/* + * 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.data.builtins import net.mamoe.mirai.console.data.AutoSavePluginConfig diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/ConsoleDataScope.kt b/backend/mirai-console/src/internal/data/builtins/ConsoleDataScope.kt similarity index 91% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/ConsoleDataScope.kt rename to backend/mirai-console/src/internal/data/builtins/ConsoleDataScope.kt index ab5c122c6..8520c788a 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/ConsoleDataScope.kt +++ b/backend/mirai-console/src/internal/data/builtins/ConsoleDataScope.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/LoggerConfig.kt b/backend/mirai-console/src/internal/data/builtins/LoggerConfig.kt similarity index 100% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/LoggerConfig.kt rename to backend/mirai-console/src/internal/data/builtins/LoggerConfig.kt diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/collectionUtil.kt b/backend/mirai-console/src/internal/data/collectionUtil.kt similarity index 99% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/collectionUtil.kt rename to backend/mirai-console/src/internal/data/collectionUtil.kt index c9260c82d..255bd9931 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/collectionUtil.kt +++ b/backend/mirai-console/src/internal/data/collectionUtil.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/reflectionUtils.kt b/backend/mirai-console/src/internal/data/reflectionUtils.kt similarity index 97% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/reflectionUtils.kt rename to backend/mirai-console/src/internal/data/reflectionUtils.kt index 54818777e..d14c3b12e 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/reflectionUtils.kt +++ b/backend/mirai-console/src/internal/data/reflectionUtils.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/serializerHelper.kt b/backend/mirai-console/src/internal/data/serializerHelper.kt similarity index 98% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/serializerHelper.kt rename to backend/mirai-console/src/internal/data/serializerHelper.kt index eced14e96..b5a2a0938 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/serializerHelper.kt +++ b/backend/mirai-console/src/internal/data/serializerHelper.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/valueFromKTypeImpl.kt b/backend/mirai-console/src/internal/data/valueFromKTypeImpl.kt similarity index 98% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/valueFromKTypeImpl.kt rename to backend/mirai-console/src/internal/data/valueFromKTypeImpl.kt index 02e5ddbe9..1d63acce7 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/valueFromKTypeImpl.kt +++ b/backend/mirai-console/src/internal/data/valueFromKTypeImpl.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/extension/BuiltInSingletonExtensionSelector.kt b/backend/mirai-console/src/internal/extension/BuiltInSingletonExtensionSelector.kt similarity index 87% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/extension/BuiltInSingletonExtensionSelector.kt rename to backend/mirai-console/src/internal/extension/BuiltInSingletonExtensionSelector.kt index d096341ed..1314db595 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/extension/BuiltInSingletonExtensionSelector.kt +++ b/backend/mirai-console/src/internal/extension/BuiltInSingletonExtensionSelector.kt @@ -1,3 +1,12 @@ +/* + * 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.extension import kotlinx.coroutines.runBlocking diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/extension/ComponentStorageInternal.kt b/backend/mirai-console/src/internal/extension/ComponentStorageInternal.kt similarity index 97% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/extension/ComponentStorageInternal.kt rename to backend/mirai-console/src/internal/extension/ComponentStorageInternal.kt index 803ccc8d4..6f4af7bd2 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/extension/ComponentStorageInternal.kt +++ b/backend/mirai-console/src/internal/extension/ComponentStorageInternal.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerImpl.kt b/backend/mirai-console/src/internal/logging/LoggerControllerImpl.kt similarity index 100% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerImpl.kt rename to backend/mirai-console/src/internal/logging/LoggerControllerImpl.kt diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/MiraiConsoleLogger.kt b/backend/mirai-console/src/internal/logging/MiraiConsoleLogger.kt similarity index 100% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/MiraiConsoleLogger.kt rename to backend/mirai-console/src/internal/logging/MiraiConsoleLogger.kt diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/permission/AbstractConcurrentPermissionService.kt b/backend/mirai-console/src/internal/permission/AbstractConcurrentPermissionService.kt similarity index 91% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/permission/AbstractConcurrentPermissionService.kt rename to backend/mirai-console/src/internal/permission/AbstractConcurrentPermissionService.kt index 31641db0b..90fafa1a3 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/permission/AbstractConcurrentPermissionService.kt +++ b/backend/mirai-console/src/internal/permission/AbstractConcurrentPermissionService.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/permission/BuiltInPermissionServices.kt b/backend/mirai-console/src/internal/permission/BuiltInPermissionServices.kt similarity index 97% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/permission/BuiltInPermissionServices.kt rename to backend/mirai-console/src/internal/permission/BuiltInPermissionServices.kt index d787e3358..ae50f993b 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/permission/BuiltInPermissionServices.kt +++ b/backend/mirai-console/src/internal/permission/BuiltInPermissionServices.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/permission/parseFromStringImpl.kt b/backend/mirai-console/src/internal/permission/parseFromStringImpl.kt similarity index 97% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/permission/parseFromStringImpl.kt rename to backend/mirai-console/src/internal/permission/parseFromStringImpl.kt index 343832ab6..e1267706c 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/permission/parseFromStringImpl.kt +++ b/backend/mirai-console/src/internal/permission/parseFromStringImpl.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/BuiltInJvmPluginLoaderImpl.kt b/backend/mirai-console/src/internal/plugin/BuiltInJvmPluginLoaderImpl.kt similarity index 80% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/BuiltInJvmPluginLoaderImpl.kt rename to backend/mirai-console/src/internal/plugin/BuiltInJvmPluginLoaderImpl.kt index d9acd38b8..6a3e30969 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/BuiltInJvmPluginLoaderImpl.kt +++ b/backend/mirai-console/src/internal/plugin/BuiltInJvmPluginLoaderImpl.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -23,7 +23,6 @@ import net.mamoe.mirai.console.plugin.loader.PluginLoadException import net.mamoe.mirai.console.util.CoroutineScopeUtils.childScope import net.mamoe.mirai.utils.MiraiLogger import java.io.File -import java.net.URLClassLoader import java.util.concurrent.ConcurrentHashMap internal object BuiltInJvmPluginLoaderImpl : @@ -52,8 +51,22 @@ internal object BuiltInJvmPluginLoaderImpl : override fun Sequence.extractPlugins(): List { ensureActive() - fun Sequence>.findAllInstances(): Sequence> { - return map { (f, pluginClassLoader) -> + fun Sequence>.findAllInstances(): Sequence> { + return onEach { (_, pluginClassLoader) -> + val exportManagers = pluginClassLoader.findServices( + ExportManager::class + ).loadAllServices() + if (exportManagers.isEmpty()) { + val rules = pluginClassLoader.getResourceAsStream("export-rules.txt") + if (rules == null) + pluginClassLoader.declaredFilter = StandardExportManagers.AllExported + else rules.bufferedReader(Charsets.UTF_8).useLines { + pluginClassLoader.declaredFilter = ExportManagerImpl.parse(it.iterator()) + } + } else { + pluginClassLoader.declaredFilter = exportManagers[0] + } + }.map { (f, pluginClassLoader) -> f to pluginClassLoader.findServices( JvmPlugin::class, KotlinPlugin::class, @@ -61,6 +74,7 @@ internal object BuiltInJvmPluginLoaderImpl : JavaPlugin::class ).loadAllServices() }.flatMap { (f, list) -> + list.associateBy { f }.asSequence() } } @@ -68,7 +82,7 @@ internal object BuiltInJvmPluginLoaderImpl : val filePlugins = this.filterNot { pluginFileToInstanceMap.containsKey(it) }.associateWith { - JvmPluginClassLoader(it, MiraiConsole::class.java.classLoader) + JvmPluginClassLoader(it, MiraiConsole::class.java.classLoader, classLoaders) }.onEach { (_, classLoader) -> classLoaders.add(classLoader) }.asSequence().findAllInstances().onEach { diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/Exceptions.kt b/backend/mirai-console/src/internal/plugin/Exceptions.kt similarity index 92% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/Exceptions.kt rename to backend/mirai-console/src/internal/plugin/Exceptions.kt index 4cfadc759..6d2030643 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/Exceptions.kt +++ b/backend/mirai-console/src/internal/plugin/Exceptions.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/internal/plugin/ExportManagerImpl.kt b/backend/mirai-console/src/internal/plugin/ExportManagerImpl.kt new file mode 100644 index 000000000..9c58761d7 --- /dev/null +++ b/backend/mirai-console/src/internal/plugin/ExportManagerImpl.kt @@ -0,0 +1,55 @@ +/* + * 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.plugin + +import net.mamoe.mirai.console.plugin.jvm.ExportManager + +internal class ExportManagerImpl( + private val rules: List<(String) -> Boolean?> +) : ExportManager { + + override fun isExported(className: String): Boolean { + rules.forEach { + val result = it(className) + if (result != null) return@isExported result + } + return true + } + + companion object { + @JvmStatic + fun parse(lines: Iterator): ExportManagerImpl { + fun Boolean.without(value: Boolean) = if (this == value) null else this + + val rules = ArrayList<(String) -> Boolean?>() + lines.asSequence().map { it.trim() }.filter { it.isNotBlank() }.filterNot { + it[0] == '#' + }.forEach { line -> + val command = line.substringBefore(' ') + val argument = line.substringAfter(' ', missingDelimiterValue = "").trim() + val argumentPackage = "$argument." + + when (command) { + "exports" -> rules.add { + (it == argument || it.startsWith(argumentPackage)).without(false) + } + "protects" -> rules.add { + if (it == argument || it.startsWith(argumentPackage)) + false + else null + } + "export-all", "export-plugin", "export-system" -> rules.add { true } + "protect-all", "protect-plugin", "protect-system" -> rules.add { false } + } + } + return ExportManagerImpl(rules) + } + } +} \ No newline at end of file diff --git a/backend/mirai-console/src/internal/plugin/JvmPluginClassLoader.kt b/backend/mirai-console/src/internal/plugin/JvmPluginClassLoader.kt new file mode 100644 index 000000000..33c9e0584 --- /dev/null +++ b/backend/mirai-console/src/internal/plugin/JvmPluginClassLoader.kt @@ -0,0 +1,125 @@ +/* + * 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 + */ +@file:Suppress("MemberVisibilityCanBePrivate") + +package net.mamoe.mirai.console.internal.plugin + +import net.mamoe.mirai.console.plugin.jvm.ExportManager +import java.io.File +import java.net.URL +import java.net.URLClassLoader +import java.util.* +import java.util.concurrent.ConcurrentHashMap + +internal class JvmPluginClassLoader( + val file: File, + parent: ClassLoader?, + val classLoaders: Collection, +) : URLClassLoader(arrayOf(file.toURI().toURL()), parent) { + //// 只允许插件 getResource 时获取插件自身资源, #205 + override fun getResources(name: String?): Enumeration = findResources(name) + override fun getResource(name: String?): URL? = findResource(name) + // getResourceAsStream 在 URLClassLoader 中通过 getResource 确定资源 + // 因此无需 override getResourceAsStream + + override fun toString(): String { + return "JvmPluginClassLoader{source=$file}" + } + + private val cache = ConcurrentHashMap>() + internal var declaredFilter: ExportManager? = null + + companion object { + val loadingLock = ConcurrentHashMap() + + init { + ClassLoader.registerAsParallelCapable() + } + } + + override fun findClass(name: String): Class<*> { + synchronized(kotlin.run { + val lock = Any() + loadingLock.putIfAbsent(name, lock) ?: lock + }) { + return findClass(name, false) ?: throw ClassNotFoundException(name) + } + } + + internal fun findClass(name: String, disableGlobal: Boolean): Class<*>? { + // First. Try direct load in cache. + val cachedClass = cache[name] + if (cachedClass != null) { + if (disableGlobal) { + val filter = declaredFilter + if (filter != null && !filter.isExported(name)) { + throw LoadingDeniedException(name) + } + } + return cachedClass + } + if (disableGlobal) { + // ==== Process Loading Request From JvmPluginClassLoader ==== + // + // If load from other classloader, + // means no other loaders are cached. + // direct load + return kotlin.runCatching { + super.findClass(name).also { cache[name] = it } + }.getOrElse { + if (it is ClassNotFoundException) null + else throw it + }?.also { + // This request is from other classloader, + // so we need to check the class is exported or not. + val filter = declaredFilter + if (filter != null && !filter.isExported(name)) { + throw LoadingDeniedException(name) + } + } + } + + // ==== Process Loading Request From JDK ClassLoading System ==== + + // First. scan other classLoaders's caches + classLoaders.forEach { otherClassloader -> + if (otherClassloader === this) return@forEach + val filter = otherClassloader.declaredFilter + if (otherClassloader.cache.containsKey(name)) { + return if (filter == null || filter.isExported(name)) { + otherClassloader.cache[name] + } else throw LoadingDeniedException("$name was not exported by $otherClassloader") + } + } + + // If no cache... + return kotlin.runCatching { + // Try load this class direct.... + super.findClass(name).also { cache[name] = it } + }.getOrElse { exception -> + if (exception is ClassNotFoundException) { + // Cannot load the class from this, try others. + classLoaders.forEach { otherClassloader -> + if (otherClassloader === this) return@forEach + val other = kotlin.runCatching { + otherClassloader.findClass(name, true) + }.onFailure { err -> + if (err is LoadingDeniedException || err !is ClassNotFoundException) + throw err + }.getOrNull() + if (other != null) return other + } + } + // Great, nobody known what is the class. + throw exception + } + } +} + +internal class LoadingDeniedException(name: String) : ClassNotFoundException(name) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/JvmPluginInternal.kt b/backend/mirai-console/src/internal/plugin/JvmPluginInternal.kt similarity index 98% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/JvmPluginInternal.kt rename to backend/mirai-console/src/internal/plugin/JvmPluginInternal.kt index 33ce08713..941fa1f95 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/JvmPluginInternal.kt +++ b/backend/mirai-console/src/internal/plugin/JvmPluginInternal.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/PluginManagerImpl.kt b/backend/mirai-console/src/internal/plugin/PluginManagerImpl.kt similarity index 99% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/PluginManagerImpl.kt rename to backend/mirai-console/src/internal/plugin/PluginManagerImpl.kt index d26feac23..e93fdb365 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/PluginManagerImpl.kt +++ b/backend/mirai-console/src/internal/plugin/PluginManagerImpl.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/ByteUtils.kt b/backend/mirai-console/src/internal/util/ByteUtils.kt similarity index 90% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/ByteUtils.kt rename to backend/mirai-console/src/internal/util/ByteUtils.kt index e72dba09f..0b84be55c 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/ByteUtils.kt +++ b/backend/mirai-console/src/internal/util/ByteUtils.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/CommonUtils.kt b/backend/mirai-console/src/internal/util/CommonUtils.kt similarity index 77% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/CommonUtils.kt rename to backend/mirai-console/src/internal/util/CommonUtils.kt index 516609400..27f5d5bdd 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/CommonUtils.kt +++ b/backend/mirai-console/src/internal/util/CommonUtils.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/ConsoleInputImpl.kt b/backend/mirai-console/src/internal/util/ConsoleInputImpl.kt similarity index 91% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/ConsoleInputImpl.kt rename to backend/mirai-console/src/internal/util/ConsoleInputImpl.kt index e9e8c2562..52c87db78 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/ConsoleInputImpl.kt +++ b/backend/mirai-console/src/internal/util/ConsoleInputImpl.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/JavaPluginSchedulerImpl.kt b/backend/mirai-console/src/internal/util/JavaPluginSchedulerImpl.kt similarity index 88% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/JavaPluginSchedulerImpl.kt rename to backend/mirai-console/src/internal/util/JavaPluginSchedulerImpl.kt index 23af98223..53c11f026 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/JavaPluginSchedulerImpl.kt +++ b/backend/mirai-console/src/internal/util/JavaPluginSchedulerImpl.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -43,11 +43,10 @@ internal class JavaPluginSchedulerImpl internal constructor(parentCoroutineConte } } - override fun delayed(delayMillis: Long, runnable: Callable): CompletableFuture { + override fun delayed(delayMillis: Long, callable: Callable): CompletableFuture { return future { delay(delayMillis) - withContext(Dispatchers.IO) { runnable.call() } - null + withContext(Dispatchers.IO) { callable.call() } } } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/PluginServiceHelper.kt b/backend/mirai-console/src/internal/util/PluginServiceHelper.kt similarity index 94% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/PluginServiceHelper.kt rename to backend/mirai-console/src/internal/util/PluginServiceHelper.kt index c3c0c68dc..d64a7ddc5 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/PluginServiceHelper.kt +++ b/backend/mirai-console/src/internal/util/PluginServiceHelper.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/semver/RangeTokenReader.kt b/backend/mirai-console/src/internal/util/semver/RangeTokenReader.kt similarity index 99% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/semver/RangeTokenReader.kt rename to backend/mirai-console/src/internal/util/semver/RangeTokenReader.kt index 00a0524b2..5f761cb6e 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/semver/RangeTokenReader.kt +++ b/backend/mirai-console/src/internal/util/semver/RangeTokenReader.kt @@ -2,10 +2,9 @@ * 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 via the following link. + * 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 - * */ @file:Suppress("MemberVisibilityCanBePrivate") diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/semver/SemVersionInternal.kt b/backend/mirai-console/src/internal/util/semver/SemVersionInternal.kt similarity index 99% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/semver/SemVersionInternal.kt rename to backend/mirai-console/src/internal/util/semver/SemVersionInternal.kt index d57c226e9..1c5e013af 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/semver/SemVersionInternal.kt +++ b/backend/mirai-console/src/internal/util/semver/SemVersionInternal.kt @@ -2,10 +2,9 @@ * 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 via the following link. + * 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.util.semver diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LogPriority.kt b/backend/mirai-console/src/logging/LogPriority.kt similarity index 100% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LogPriority.kt rename to backend/mirai-console/src/logging/LogPriority.kt diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerController.kt b/backend/mirai-console/src/logging/LoggerController.kt similarity index 100% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerController.kt rename to backend/mirai-console/src/logging/LoggerController.kt diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/JvmPluginClassLoader.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/JvmPluginClassLoader.kt deleted file mode 100644 index 1787c3809..000000000 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/JvmPluginClassLoader.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 via the following link. - * - * https://github.com/mamoe/mirai/blob/master/LICENSE - * - */ - -package net.mamoe.mirai.console.internal.plugin - -import java.io.File -import java.net.URL -import java.net.URLClassLoader -import java.util.* - -internal class JvmPluginClassLoader( - file: File, - parent: ClassLoader?, -) : URLClassLoader(arrayOf(file.toURI().toURL()), parent) { - //// 只允许插件 getResource 时获取插件自身资源, #205 - override fun getResources(name: String?): Enumeration = findResources(name) - override fun getResource(name: String?): URL? = findResource(name) - // getResourceAsStream 在 URLClassLoader 中通过 getResource 确定资源 - // 因此无需 override getResourceAsStream -} diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/Permission.kt b/backend/mirai-console/src/permission/Permission.kt similarity index 92% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/Permission.kt rename to backend/mirai-console/src/permission/Permission.kt index 6a8b72425..fd21a2518 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/Permission.kt +++ b/backend/mirai-console/src/permission/Permission.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionId.kt b/backend/mirai-console/src/permission/PermissionId.kt similarity index 94% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionId.kt rename to backend/mirai-console/src/permission/PermissionId.kt index 551ca81a3..65411c3eb 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionId.kt +++ b/backend/mirai-console/src/permission/PermissionId.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionIdNamespace.kt b/backend/mirai-console/src/permission/PermissionIdNamespace.kt similarity index 74% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionIdNamespace.kt rename to backend/mirai-console/src/permission/PermissionIdNamespace.kt index 90a043608..4c805bf9e 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionIdNamespace.kt +++ b/backend/mirai-console/src/permission/PermissionIdNamespace.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ @@ -20,7 +20,7 @@ public interface PermissionIdNamespace { /** * 创建一个此命名空间下的 [PermitteeId]. * - * 在指令初始化时, 会申请对应权限. 此时 [name] 为 "command.$primaryName` 其中 [primaryName][Command.primaryName]. + * 在指令初始化时, 会申请对应权限. 此时 [name] 为 `command.$primaryName` 其中 [primaryName][Command.primaryName]. */ public fun permissionId(@ResolveContext(PERMISSION_NAME) name: String): PermissionId } \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionImplementation.kt b/backend/mirai-console/src/permission/PermissionImplementation.kt similarity index 81% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionImplementation.kt rename to backend/mirai-console/src/permission/PermissionImplementation.kt index 2e79f262e..1b27bed79 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionImplementation.kt +++ b/backend/mirai-console/src/permission/PermissionImplementation.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionRegistryConflictException.kt b/backend/mirai-console/src/permission/PermissionRegistryConflictException.kt similarity index 74% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionRegistryConflictException.kt rename to backend/mirai-console/src/permission/PermissionRegistryConflictException.kt index de85ebe53..0378a924f 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionRegistryConflictException.kt +++ b/backend/mirai-console/src/permission/PermissionRegistryConflictException.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionService.kt b/backend/mirai-console/src/permission/PermissionService.kt similarity index 98% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionService.kt rename to backend/mirai-console/src/permission/PermissionService.kt index b86f97612..49e25e94b 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionService.kt +++ b/backend/mirai-console/src/permission/PermissionService.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/Permittee.kt b/backend/mirai-console/src/permission/Permittee.kt similarity index 78% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/Permittee.kt rename to backend/mirai-console/src/permission/Permittee.kt index e7235e22a..a9a21307e 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/Permittee.kt +++ b/backend/mirai-console/src/permission/Permittee.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermitteeId.kt b/backend/mirai-console/src/permission/PermitteeId.kt similarity index 99% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermitteeId.kt rename to backend/mirai-console/src/permission/PermitteeId.kt index 3379e3b6d..267144cf3 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermitteeId.kt +++ b/backend/mirai-console/src/permission/PermitteeId.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/Plugin.kt b/backend/mirai-console/src/plugin/Plugin.kt similarity index 95% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/Plugin.kt rename to backend/mirai-console/src/plugin/Plugin.kt index 9fd35e08b..bb9d00a47 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/Plugin.kt +++ b/backend/mirai-console/src/plugin/Plugin.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -35,7 +35,7 @@ import kotlin.DeprecationLevel.ERROR */ public interface Plugin : CommandOwner { /** - * 判断此插件是否已启用 + * 当插件已启用时返回 `true`, 否则表示插件未启用. * * @see PluginManager.enablePlugin 启用一个插件 * @see PluginManager.disablePlugin 禁用一个插件 diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/PluginFileExtensions.kt b/backend/mirai-console/src/plugin/PluginFileExtensions.kt similarity index 92% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/PluginFileExtensions.kt rename to backend/mirai-console/src/plugin/PluginFileExtensions.kt index 459d768b4..931dba5b6 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/PluginFileExtensions.kt +++ b/backend/mirai-console/src/plugin/PluginFileExtensions.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/PluginManager.kt b/backend/mirai-console/src/plugin/PluginManager.kt similarity index 93% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/PluginManager.kt rename to backend/mirai-console/src/plugin/PluginManager.kt index e5ad8140f..39fa8d3de 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/PluginManager.kt +++ b/backend/mirai-console/src/plugin/PluginManager.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -140,16 +140,28 @@ public interface PluginManager { get() = this.loader as PluginLoader + /** + * @see getPluginDescription + */ @get:JvmSynthetic public inline val Plugin.description: PluginDescription get() = getPluginDescription(this) + /** + * @see disablePlugin + */ @JvmSynthetic public inline fun Plugin.disable(): Unit = disablePlugin(this) + /** + * @see enablePlugin + */ @JvmSynthetic public inline fun Plugin.enable(): Unit = enablePlugin(this) + /** + * @see loadPlugin + */ @JvmSynthetic public inline fun Plugin.load(): Unit = loadPlugin(this) } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/ResourceContainer.kt b/backend/mirai-console/src/plugin/ResourceContainer.kt similarity index 97% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/ResourceContainer.kt rename to backend/mirai-console/src/plugin/ResourceContainer.kt index 8937f4146..8332df1ca 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/ResourceContainer.kt +++ b/backend/mirai-console/src/plugin/ResourceContainer.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/center/PluginCenter.kt b/backend/mirai-console/src/plugin/center/PluginCenter.kt similarity index 96% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/center/PluginCenter.kt rename to backend/mirai-console/src/plugin/center/PluginCenter.kt index 9e5979319..045392df3 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/center/PluginCenter.kt +++ b/backend/mirai-console/src/plugin/center/PluginCenter.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/IllegalPluginDescriptionException.kt b/backend/mirai-console/src/plugin/description/IllegalPluginDescriptionException.kt similarity index 91% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/IllegalPluginDescriptionException.kt rename to backend/mirai-console/src/plugin/description/IllegalPluginDescriptionException.kt index d2a05199e..ba4244be4 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/IllegalPluginDescriptionException.kt +++ b/backend/mirai-console/src/plugin/description/IllegalPluginDescriptionException.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDependency.kt b/backend/mirai-console/src/plugin/description/PluginDependency.kt similarity index 95% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDependency.kt rename to backend/mirai-console/src/plugin/description/PluginDependency.kt index d73ac9cec..ea45ea173 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDependency.kt +++ b/backend/mirai-console/src/plugin/description/PluginDependency.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDescription.kt b/backend/mirai-console/src/plugin/description/PluginDescription.kt similarity index 96% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDescription.kt rename to backend/mirai-console/src/plugin/description/PluginDescription.kt index 7c84a2807..7c0053bae 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDescription.kt +++ b/backend/mirai-console/src/plugin/description/PluginDescription.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -90,7 +90,7 @@ public interface PluginDescription { * - `v1.0` (不允许 "v") * - `V1.0` (不允许 "V") * - * @see Semver 语义化版本. 允许 [宽松][Semver.SemverType.LOOSE] 类型版本. + * @see SemVersion 语义化版本. */ @ResolveContext(SEMANTIC_VERSION) public val version: SemVersion @@ -116,7 +116,7 @@ public interface PluginDescription { * * @see PluginDescription.id */ - public val ID_REGEX: Regex = Regex("""([a-zA-Z]+(?:\.[a-zA-Z0-9]+)*)\.([a-zA-Z]+(?:-[a-zA-Z0-9]+)*)""") + public val ID_REGEX: Regex = Regex("""([a-zA-Z][a-zA-Z0-9]*(?:\.[a-zA-Z][a-zA-Z0-9]*)*)\.([a-zA-Z][a-zA-Z0-9]*(?:-[a-zA-Z0-9]+)*)""") /** * 在 [PluginDescription.id] 和 [PluginDescription.name] 中禁止用的完全匹配名称列表. diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/AbstractJvmPlugin.kt b/backend/mirai-console/src/plugin/jvm/AbstractJvmPlugin.kt similarity index 97% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/AbstractJvmPlugin.kt rename to backend/mirai-console/src/plugin/jvm/AbstractJvmPlugin.kt index 1f19786fa..c5a3c378f 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/AbstractJvmPlugin.kt +++ b/backend/mirai-console/src/plugin/jvm/AbstractJvmPlugin.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/plugin/jvm/ExportManager.kt b/backend/mirai-console/src/plugin/jvm/ExportManager.kt new file mode 100644 index 000000000..c9bac5cde --- /dev/null +++ b/backend/mirai-console/src/plugin/jvm/ExportManager.kt @@ -0,0 +1,110 @@ +/* + * 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.plugin.jvm + +import net.mamoe.mirai.console.internal.plugin.ExportManagerImpl +import net.mamoe.mirai.console.util.ConsoleExperimentalApi + +/** + * 插件的类导出管理器 + * + * + * 允许插件将一些内部实现保护起来, 避免其他插件调用, 要启动这个特性, + * 只需要创建名为 `export-rules.txt` 的规则文件,便可以控制插件的类的公开规则。 + * + * 如果正在使用 `Gradle` 项目, 该规则文件一般位于 `src/main/resources` 下 + * + * Example: + * ```text + * + * # #开头的行全部识别为注释 + * + * # exports, 允许其他插件直接使用某个类 + * + * # 导出了一个internal包的一个类 + * # + * exports org.example.miraiconsole.myplugin.internal.OpenInternal + * + * # 导出了整个 api 包 + * # + * exports org.example.miraiconsole.myplugin.api + * + * # 保护 org.example.miraiconsole.myplugin.api2.Internal, 不允许其他插件直接使用 + * # + * protects org.example.miraiconsole.myplugin.api2.Internal + * + * # 保护整个包 + * # + * # 别名: protect-package + * protects org.example.miraiconsole.myplugin.internal + * + * # 此规则不会生效, 因为在此条规则之前, + * # org.example.miraiconsole.myplugin.internal 已经被加入到保护域中 + * exports org.example.miraiconsole.myplugin.internal.NotOpenInternal + * + * + * # export-plugin, 允许其他插件使用除了已经被保护的全部类 + * # 使用此规则会同时让此规则后的所有规则全部失效 + * # 别名: export-all, export-system + * # export-plugin + * + * + * # 将整个插件放入保护域中 + * # 除了此规则之前显式 export 的类, 其他插件将不允许直接使用被保护的插件的任何类 + * # 别名: protect-all, protect-system + * protect-plugin + * + * ``` + * + * 插件也可以通过 Service 来自定义导出控制 + * + * Example: + * ```kotlin + * @AutoService(ExportManager::class) + * object MyExportManager: ExportManager { + * override fun isExported(className: String): Boolean { + * println(" <== $className") + * return true + * } + * } + * ``` + * + */ +@ConsoleExperimentalApi +public interface ExportManager { + /** + * 如果 [className] 能够通过 [ExportManager] 的规则, 返回 true + * + * @param className [className] 是一个合法的满足 [ClassLoader] 的加载规则 的全限定名. + * [className] 不应该是数组的全限定名或者JVM基本类型的名字. + * See also: [ClassLoader.loadClass] + * [ClassLoader#name](https://docs.oracle.com/javase/8/docs/api/java/lang/ClassLoader.html#name) + */ + public fun isExported(className: String): Boolean +} + +@ConsoleExperimentalApi +public object StandardExportManagers { + @ConsoleExperimentalApi + public object AllExported : ExportManager { + override fun isExported(className: String): Boolean = true + } + + @ConsoleExperimentalApi + public object AllDenied : ExportManager { + override fun isExported(className: String): Boolean = false + } + + @ConsoleExperimentalApi + @JvmStatic + public fun parse(lines: Iterator): ExportManager { + return ExportManagerImpl.parse(lines) + } +} \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JavaPlugin.kt b/backend/mirai-console/src/plugin/jvm/JavaPlugin.kt similarity index 92% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JavaPlugin.kt rename to backend/mirai-console/src/plugin/jvm/JavaPlugin.kt index b3fe8dd54..51ef697ae 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JavaPlugin.kt +++ b/backend/mirai-console/src/plugin/jvm/JavaPlugin.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JavaPluginScheduler.kt b/backend/mirai-console/src/plugin/jvm/JavaPluginScheduler.kt similarity index 85% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JavaPluginScheduler.kt rename to backend/mirai-console/src/plugin/jvm/JavaPluginScheduler.kt index 684832703..cfeb23cf2 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JavaPluginScheduler.kt +++ b/backend/mirai-console/src/plugin/jvm/JavaPluginScheduler.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -19,6 +19,7 @@ import java.util.concurrent.Callable import java.util.concurrent.CompletableFuture import java.util.concurrent.Future import kotlin.coroutines.CoroutineContext +import kotlin.coroutines.EmptyCoroutineContext /** @@ -48,9 +49,9 @@ public interface JavaPluginScheduler : CoroutineScope { /** * 新增一个 Delayed Task (延迟任务) * - * 在延迟 [delayMillis] 后执行 [runnable] + * 在延迟 [delayMillis] 后执行 [callable] */ - public fun delayed(delayMillis: Long, runnable: Callable): CompletableFuture + public fun delayed(delayMillis: Long, callable: Callable): CompletableFuture /** * 异步执行一个任务, 最终返回 [Future], 与 Java 使用方法无异, 但效率更高且可以在插件关闭时停止 @@ -68,7 +69,8 @@ public interface JavaPluginScheduler : CoroutineScope { */ @JvmStatic @JvmName("create") - public operator fun invoke(parentCoroutineContext: CoroutineContext): JavaPluginScheduler = + @JvmOverloads + public operator fun invoke(parentCoroutineContext: CoroutineContext = EmptyCoroutineContext): JavaPluginScheduler = JavaPluginSchedulerImpl(parentCoroutineContext) } } \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPlugin.kt b/backend/mirai-console/src/plugin/jvm/JvmPlugin.kt similarity index 96% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPlugin.kt rename to backend/mirai-console/src/plugin/jvm/JvmPlugin.kt index d3aa7e7cb..4fc8d8233 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPlugin.kt +++ b/backend/mirai-console/src/plugin/jvm/JvmPlugin.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginDescription.kt b/backend/mirai-console/src/plugin/jvm/JvmPluginDescription.kt similarity index 98% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginDescription.kt rename to backend/mirai-console/src/plugin/jvm/JvmPluginDescription.kt index b147e8873..d4bb97196 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginDescription.kt +++ b/backend/mirai-console/src/plugin/jvm/JvmPluginDescription.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginLoader.kt b/backend/mirai-console/src/plugin/jvm/JvmPluginLoader.kt similarity index 94% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginLoader.kt rename to backend/mirai-console/src/plugin/jvm/JvmPluginLoader.kt index 30b4e7f34..7123805a4 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginLoader.kt +++ b/backend/mirai-console/src/plugin/jvm/JvmPluginLoader.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/KotlinPlugin.kt b/backend/mirai-console/src/plugin/jvm/KotlinPlugin.kt similarity index 93% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/KotlinPlugin.kt rename to backend/mirai-console/src/plugin/jvm/KotlinPlugin.kt index 04a4ea380..50f8ee835 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/KotlinPlugin.kt +++ b/backend/mirai-console/src/plugin/jvm/KotlinPlugin.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/loader/FilePluginLoader.kt b/backend/mirai-console/src/plugin/loader/FilePluginLoader.kt similarity index 80% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/loader/FilePluginLoader.kt rename to backend/mirai-console/src/plugin/loader/FilePluginLoader.kt index f770711a4..4a5b4e60e 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/loader/FilePluginLoader.kt +++ b/backend/mirai-console/src/plugin/loader/FilePluginLoader.kt @@ -1,3 +1,12 @@ +/* + * 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.plugin.loader import net.mamoe.mirai.console.plugin.Plugin diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/loader/PluginLoadException.kt b/backend/mirai-console/src/plugin/loader/PluginLoadException.kt similarity index 91% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/loader/PluginLoadException.kt rename to backend/mirai-console/src/plugin/loader/PluginLoadException.kt index ac6e6621b..d038971f5 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/loader/PluginLoadException.kt +++ b/backend/mirai-console/src/plugin/loader/PluginLoadException.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/loader/PluginLoader.kt b/backend/mirai-console/src/plugin/loader/PluginLoader.kt similarity index 98% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/loader/PluginLoader.kt rename to backend/mirai-console/src/plugin/loader/PluginLoader.kt index 208f4e743..e4b9e863f 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/loader/PluginLoader.kt +++ b/backend/mirai-console/src/plugin/loader/PluginLoader.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/Annotations.kt b/backend/mirai-console/src/util/Annotations.kt similarity index 95% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/Annotations.kt rename to backend/mirai-console/src/util/Annotations.kt index 161120038..beba09b57 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/Annotations.kt +++ b/backend/mirai-console/src/util/Annotations.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/ConsoleInput.kt b/backend/mirai-console/src/util/ConsoleInput.kt similarity index 85% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/ConsoleInput.kt rename to backend/mirai-console/src/util/ConsoleInput.kt index dc30c4d81..9f9897be8 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/ConsoleInput.kt +++ b/backend/mirai-console/src/util/ConsoleInput.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -18,7 +18,7 @@ import net.mamoe.mirai.console.MiraiConsole import net.mamoe.mirai.console.internal.util.ConsoleInputImpl /** - * Console 输入. 由于 console 接管了 [stdin][System. in], [readLine] 等操作需要在这里进行. + * Console 输入. 由于 console 接管了 [标准输入][System. in], [readLine] 等操作需要在这里进行. */ public interface ConsoleInput { /** diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/ContactUtils.kt b/backend/mirai-console/src/util/ContactUtils.kt similarity index 93% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/ContactUtils.kt rename to backend/mirai-console/src/util/ContactUtils.kt index bdd37219d..039989002 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/ContactUtils.kt +++ b/backend/mirai-console/src/util/ContactUtils.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/CoroutineScopeUtils.kt b/backend/mirai-console/src/util/CoroutineScopeUtils.kt similarity index 88% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/CoroutineScopeUtils.kt rename to backend/mirai-console/src/util/CoroutineScopeUtils.kt index ee2917b80..c275d1250 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/CoroutineScopeUtils.kt +++ b/backend/mirai-console/src/util/CoroutineScopeUtils.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/MessageScope.kt b/backend/mirai-console/src/util/MessageScope.kt similarity index 99% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/MessageScope.kt rename to backend/mirai-console/src/util/MessageScope.kt index 92a82a616..023642dcb 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/MessageScope.kt +++ b/backend/mirai-console/src/util/MessageScope.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ @@ -72,6 +72,7 @@ import kotlin.internal.LowPriorityInOverloadResolution * val duration = Random.nextInt(1, 15) * target.mute(duration) * + * * // 不使用 MessageScope, 无用的样板代码 * val thisGroup = this.getGroupOrNull() * val message = "${this.name} 禁言 ${target.nameCardOrNick} $duration 秒" @@ -80,12 +81,14 @@ import kotlin.internal.LowPriorityInOverloadResolution * } * sendMessage(message) * + * * // 使用 MessageScope, 清晰逻辑 * // 表示至少发送给 `this`, 当 `this` 的真实发信对象与 `target.group` 不同时, 还额外发送给 `target.group` * this.scopeWith(target.group) { * sendMessage("${name} 禁言了 ${target.nameCardOrNick} $duration 秒") * } * + * * // 同样地, 可以扩展用法, 同时私聊指令执行者: * // this.scopeWith( * // target, @@ -132,6 +135,8 @@ public inline operator fun MS.invoke(action: MS.() -> R): /* * 实现提示: 以下所有代码都通过 codegen 模块中 net.mamoe.mirai.console.codegen.MessageScopeCodegen 生成. 请不要手动修改它们. + * + * 建议阅读 [MessageScope] 的文档. */ //// region MessageScopeBuilders CODEGEN //// diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/MessageUtils.kt b/backend/mirai-console/src/util/MessageUtils.kt similarity index 79% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/MessageUtils.kt rename to backend/mirai-console/src/util/MessageUtils.kt index 475481b08..117b7307f 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/MessageUtils.kt +++ b/backend/mirai-console/src/util/MessageUtils.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt b/backend/mirai-console/src/util/SemVersion.kt similarity index 99% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt rename to backend/mirai-console/src/util/SemVersion.kt index 779b97e5d..47c207fa8 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt +++ b/backend/mirai-console/src/util/SemVersion.kt @@ -2,10 +2,9 @@ * 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 via the following link. + * 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 - * */ /* diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/StandardUtils.kt b/backend/mirai-console/src/util/StandardUtils.kt similarity index 76% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/StandardUtils.kt rename to backend/mirai-console/src/util/StandardUtils.kt index 0d7dc8630..4d44aa978 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/StandardUtils.kt +++ b/backend/mirai-console/src/util/StandardUtils.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/retryCatching.kt b/backend/mirai-console/src/util/retryCatching.kt similarity index 94% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/retryCatching.kt rename to backend/mirai-console/src/util/retryCatching.kt index 41c3358b4..88b951706 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/retryCatching.kt +++ b/backend/mirai-console/src/util/retryCatching.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt b/backend/mirai-console/test/TestMiraiConosle.kt similarity index 100% rename from backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt rename to backend/mirai-console/test/TestMiraiConosle.kt diff --git a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/command/TestCommand.kt b/backend/mirai-console/test/command/TestCommand.kt similarity index 99% rename from backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/command/TestCommand.kt rename to backend/mirai-console/test/command/TestCommand.kt index bf3b7c796..3a89ca769 100644 --- a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/command/TestCommand.kt +++ b/backend/mirai-console/test/command/TestCommand.kt @@ -338,4 +338,4 @@ internal fun assertSuccess(result: CommandExecuteResult) { if (result.isFailure()) { throw result.exception ?: AssertionError(result.toString()) } -} \ No newline at end of file +} diff --git a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/command/commanTestingUtil.kt b/backend/mirai-console/test/command/commanTestingUtil.kt similarity index 100% rename from backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/command/commanTestingUtil.kt rename to backend/mirai-console/test/command/commanTestingUtil.kt diff --git a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/data/SettingTest.kt b/backend/mirai-console/test/data/SettingTest.kt similarity index 100% rename from backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/data/SettingTest.kt rename to backend/mirai-console/test/data/SettingTest.kt diff --git a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/permission/PermissionsBasicsTest.kt b/backend/mirai-console/test/permission/PermissionsBasicsTest.kt similarity index 100% rename from backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/permission/PermissionsBasicsTest.kt rename to backend/mirai-console/test/permission/PermissionsBasicsTest.kt diff --git a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/util/TestSemVersion.kt b/backend/mirai-console/test/util/TestSemVersion.kt similarity index 100% rename from backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/util/TestSemVersion.kt rename to backend/mirai-console/test/util/TestSemVersion.kt diff --git a/build.gradle.kts b/build.gradle.kts index ca24e980d..426e01df6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,9 @@ @file:Suppress("UnstableApiUsage") + +import org.jetbrains.kotlin.gradle.dsl.* +import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation +import org.jetbrains.kotlin.utils.addToStdlib.safeAs + plugins { kotlin("jvm") version Versions.kotlinCompiler kotlin("plugin.serialization") version Versions.kotlinCompiler @@ -28,6 +33,129 @@ subprojects { afterEvaluate { apply() - setJavaCompileTarget() + configureJvmTarget() + configureEncoding() + configureKotlinExperimentalUsages() + configureKotlinCompilerSettings() + configureKotlinTestSettings() + configureSourceSets() } -} \ No newline at end of file +} + +val experimentalAnnotations = arrayOf( + "kotlin.RequiresOptIn", + "kotlin.ExperimentalUnsignedTypes", + // "kotlin.ExperimentalStdlibApi", + "kotlin.contracts.ExperimentalContracts", + "kotlin.experimental.ExperimentalTypeInference", + // "kotlinx.coroutines.ExperimentalCoroutinesApi", + "io.ktor.util.KtorExperimentalAPI", + "kotlin.time.ExperimentalTime" +) + + +fun Project.configureJvmTarget() { + tasks.withType(KotlinJvmCompile::class.java) { + kotlinOptions.jvmTarget = "1.8" + } + + extensions.findByType(JavaPluginExtension::class.java)?.run { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } +} + +fun Project.useIr() { + tasks { + withType(KotlinJvmCompile::class.java) { + kotlinOptions.useIR = true + } + } +} + +fun Project.configureKotlinTestSettings() { + tasks.withType(Test::class) { + useJUnitPlatform() + } + when { + isKotlinJvmProject -> { + dependencies { + testImplementation(kotlin("test-junit5")) + + testApi("org.junit.jupiter:junit-jupiter-api:5.2.0") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.2.0") + } + } + isKotlinMpp -> { + kotlinSourceSets?.forEach { sourceSet -> + if (sourceSet.name == "common") { + sourceSet.dependencies { + implementation(kotlin("test")) + implementation(kotlin("test-annotations-common")) + } + } else { + sourceSet.dependencies { + implementation(kotlin("test-junit5")) + + implementation("org.junit.jupiter:junit-jupiter-api:5.2.0") + implementation("org.junit.jupiter:junit-jupiter-engine:5.2.0") + } + } + } + } + } +} + +fun Project.configureKotlinCompilerSettings() { + val kotlinCompilations = kotlinCompilations ?: return + for (kotlinCompilation in kotlinCompilations) with(kotlinCompilation) { + if (isKotlinJvmProject) { + @Suppress("UNCHECKED_CAST") + this as KotlinCompilation + } + kotlinOptions.freeCompilerArgs += "-Xjvm-default=all" + } +} + +fun Project.configureEncoding() { + tasks.withType(JavaCompile::class.java) { + options.encoding = "UTF8" + } +} + +fun Project.configureSourceSets() { + sourceSets { + findByName("main")?.apply { + resources.setSrcDirs(listOf(projectDir.resolve("resources"))) + java.setSrcDirs(listOf(projectDir.resolve("src"))) + } + findByName("test")?.apply { + resources.setSrcDirs(listOf(projectDir.resolve("resources"))) + java.setSrcDirs(listOf(projectDir.resolve("test"))) + } + } +} + +fun Project.configureKotlinExperimentalUsages() { + val sourceSets = kotlinSourceSets ?: return + + for (target in sourceSets) { + experimentalAnnotations.forEach { a -> + target.languageSettings.useExperimentalAnnotation(a) + //target.languageSettings.enableLanguageFeature("InlineClasses") + } + } +} + +val Project.kotlinSourceSets get() = extensions.findByName("kotlin").safeAs()?.sourceSets + +val Project.kotlinTargets + get() = + extensions.findByName("kotlin").safeAs()?.target?.let { listOf(it) } + ?: extensions.findByName("kotlin").safeAs()?.targets + +val Project.isKotlinJvmProject: Boolean get() = extensions.findByName("kotlin") is KotlinJvmProjectExtension +val Project.isKotlinMpp: Boolean get() = extensions.findByName("kotlin") is KotlinMultiplatformExtension + +val Project.kotlinCompilations + get() = kotlinTargets?.flatMap { it.compilations } \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/MiraiConsoleBuildPlugin.kt b/buildSrc/src/main/kotlin/MiraiConsoleBuildPlugin.kt index 8dbd47d8a..97b642409 100644 --- a/buildSrc/src/main/kotlin/MiraiConsoleBuildPlugin.kt +++ b/buildSrc/src/main/kotlin/MiraiConsoleBuildPlugin.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/buildSrc/src/main/kotlin/PublishingHelpers.kt b/buildSrc/src/main/kotlin/PublishingHelpers.kt index 95e16283a..a48ca62d0 100644 --- a/buildSrc/src/main/kotlin/PublishingHelpers.kt +++ b/buildSrc/src/main/kotlin/PublishingHelpers.kt @@ -1,3 +1,12 @@ +/* + * 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 + */ + @file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "NOTHING_TO_INLINE", "RemoveRedundantBackticks") import org.gradle.api.Project diff --git a/buildSrc/src/main/kotlin/SetCompileTargetPlugin.kt b/buildSrc/src/main/kotlin/SetCompileTargetPlugin.kt deleted file mode 100644 index 1e8b8315d..000000000 --- a/buildSrc/src/main/kotlin/SetCompileTargetPlugin.kt +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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 via the following link. - * - * https://github.com/mamoe/mirai/blob/master/LICENSE - */ - -import org.gradle.api.JavaVersion -import org.gradle.api.Project -import org.gradle.api.plugins.JavaPluginExtension -import org.gradle.api.tasks.compile.JavaCompile -import java.lang.reflect.Method -import kotlin.reflect.KClass - - -fun Any.reflectMethod(name: String, vararg params: KClass): Pair { - return this to this::class.java.getMethod(name, *params.map { it.java }.toTypedArray()) -} - -operator fun Pair.invoke(vararg args: Any?): Any? { - return second.invoke(first, *args) -} - -@Suppress("NOTHING_TO_INLINE") // or error -fun Project.setJavaCompileTarget() { - tasks.filter { it.name in arrayOf("compileKotlin", "compileTestKotlin") }.forEach { task -> - task - .reflectMethod("getKotlinOptions")()!! - .reflectMethod("setJvmTarget", String::class)("1.8") - } - - - kotlin.runCatching { // apply only when java plugin is available - (extensions.getByName("java") as JavaPluginExtension).run { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 - } - - tasks.withType(JavaCompile::class.java) { - options.encoding = "UTF8" - } - } -} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index ac6523639..09016f70a 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -2,14 +2,14 @@ * 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 via the following link. + * 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 */ object Versions { const val core = "1.3.2" - const val console = "1.0-RC-dev-32" + const val console = "1.0-RC-1" const val consoleGraphical = "0.0.7" const val consoleTerminal = console diff --git a/buildSrc/src/main/kotlin/dependencyExtensions.kt b/buildSrc/src/main/kotlin/dependencyExtensions.kt index 76b6fd9b5..761651eb4 100644 --- a/buildSrc/src/main/kotlin/dependencyExtensions.kt +++ b/buildSrc/src/main/kotlin/dependencyExtensions.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/buildSrc/src/main/kotlin/upload/Bintray.kt b/buildSrc/src/main/kotlin/upload/Bintray.kt index a6eb25152..fdf543ddf 100644 --- a/buildSrc/src/main/kotlin/upload/Bintray.kt +++ b/buildSrc/src/main/kotlin/upload/Bintray.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/buildSrc/src/main/kotlin/upload/CuiCloud.kt b/buildSrc/src/main/kotlin/upload/CuiCloud.kt index effcfab09..df5ca35ef 100644 --- a/buildSrc/src/main/kotlin/upload/CuiCloud.kt +++ b/buildSrc/src/main/kotlin/upload/CuiCloud.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/buildSrc/src/main/kotlin/upload/GitHub.kt b/buildSrc/src/main/kotlin/upload/GitHub.kt index e71210f06..5a9ed545c 100644 --- a/buildSrc/src/main/kotlin/upload/GitHub.kt +++ b/buildSrc/src/main/kotlin/upload/GitHub.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/docs/Commands.md b/docs/Commands.md index 816884f77..0fad7bcf8 100644 --- a/docs/Commands.md +++ b/docs/Commands.md @@ -1,47 +1,47 @@ # Mirai Console Backend - Commands -[`Plugin`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/Plugin.kt -[`PluginDescription`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDescription.kt -[`PluginLoader`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/loader/PluginLoader.kt -[`PluginManager`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/PluginManager.kt -[`JvmPluginLoader`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginLoader.kt -[`JvmPlugin`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPlugin.kt -[`JvmPluginDescription`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginDescription.kt -[`AbstractJvmPlugin`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/AbstractJvmPlugin.kt -[`KotlinPlugin`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/KotlinPlugin.kt -[`JavaPlugin`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JavaPlugin.kt +[`Plugin`]: ../backend/mirai-console/src/plugin/Plugin.kt +[`PluginDescription`]: ../backend/mirai-console/src/plugin/description/PluginDescription.kt +[`PluginLoader`]: ../backend/mirai-console/src/plugin/loader/PluginLoader.kt +[`PluginManager`]: ../backend/mirai-console/src/plugin/PluginManager.kt +[`JvmPluginLoader`]: ../backend/mirai-console/src/plugin/jvm/JvmPluginLoader.kt +[`JvmPlugin`]: ../backend/mirai-console/src/plugin/jvm/JvmPlugin.kt +[`JvmPluginDescription`]: ../backend/mirai-console/src/plugin/jvm/JvmPluginDescription.kt +[`AbstractJvmPlugin`]: ../backend/mirai-console/src/plugin/jvm/AbstractJvmPlugin.kt +[`KotlinPlugin`]: ../backend/mirai-console/src/plugin/jvm/KotlinPlugin.kt +[`JavaPlugin`]: ../backend/mirai-console/src/plugin/jvm/JavaPlugin.kt -[`Value`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/Value.kt -[`PluginData`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginData.kt -[`AbstractPluginData`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AbstractPluginData.kt -[`AutoSavePluginData`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AutoSavePluginData.kt -[`AutoSavePluginConfig`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AutoSavePluginConfig.kt -[`PluginConfig`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginConfig.kt -[`PluginDataStorage`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataStorage.kt -[`MultiFilePluginDataStorage`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataStorage.kt#L116 -[`MemoryPluginDataStorage`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataStorage.kt#L100 -[`AutoSavePluginDataHolder`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataHolder.kt#L45 -[`PluginDataHolder`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataHolder.kt -[`PluginDataExtensions`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataExtensions.kt +[`Value`]: ../backend/mirai-console/src/data/Value.kt +[`PluginData`]: ../backend/mirai-console/src/data/PluginData.kt +[`AbstractPluginData`]: ../backend/mirai-console/src/data/AbstractPluginData.kt +[`AutoSavePluginData`]: ../backend/mirai-console/src/data/AutoSavePluginData.kt +[`AutoSavePluginConfig`]: ../backend/mirai-console/src/data/AutoSavePluginConfig.kt +[`PluginConfig`]: ../backend/mirai-console/src/data/PluginConfig.kt +[`PluginDataStorage`]: ../backend/mirai-console/src/data/PluginDataStorage.kt +[`MultiFilePluginDataStorage`]: ../backend/mirai-console/src/data/PluginDataStorage.kt#L116 +[`MemoryPluginDataStorage`]: ../backend/mirai-console/src/data/PluginDataStorage.kt#L100 +[`AutoSavePluginDataHolder`]: ../backend/mirai-console/src/data/PluginDataHolder.kt#L45 +[`PluginDataHolder`]: ../backend/mirai-console/src/data/PluginDataHolder.kt +[`PluginDataExtensions`]: ../backend/mirai-console/src/data/PluginDataExtensions.kt -[`MiraiConsole`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt -[`MiraiConsoleImplementation`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt - +[`MiraiConsole`]: ../backend/mirai-console/src/MiraiConsole.kt +[`MiraiConsoleImplementation`]: ../backend/mirai-console/src/MiraiConsoleImplementation.kt + -[`Command`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/Command.kt -[`AbstractCommand`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/Command.kt#L90 -[`CompositeCommand`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CompositeCommand.kt -[`SimpleCommand`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/SimpleCommand.kt -[`RawCommand`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/RawCommand.kt -[`CommandManager`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandManager.kt -[`CommandSender`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandSender.kt -[`CommandArgumentParser`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandArgumentParser.kt -[`CommandArgumentContext`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandArgumentContext.kt -[`CommandArgumentContext.BuiltIns`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandArgumentContext.kt#L66 +[`Command`]: ../backend/mirai-console/src/command/Command.kt +[`AbstractCommand`]: ../backend/mirai-console/src/command/Command.kt#L90 +[`CompositeCommand`]: ../backend/mirai-console/src/command/CompositeCommand.kt +[`SimpleCommand`]: ../backend/mirai-console/src/command/SimpleCommand.kt +[`RawCommand`]: ../backend/mirai-console/src/command/RawCommand.kt +[`CommandManager`]: ../backend/mirai-console/src/command/CommandManager.kt +[`CommandSender`]: ../backend/mirai-console/src/command/CommandSender.kt +[`CommandValueArgumentParser`]: ../backend/mirai-console/src/command/descriptor/CommandValueArgumentParser.kt +[`CommandArgumentContext`]: ../backend/mirai-console/src/command/descriptor/CommandArgumentContext.kt +[`CommandArgumentContext.BuiltIns`]: ../backend/mirai-console/src/command/descriptor/CommandArgumentContext.kt#L66 -[`MessageScope`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/MessageScope.kt +[`MessageScope`]: ../backend/mirai-console/src/util/MessageScope.kt ## [`Command`] @@ -95,7 +95,7 @@ abstract override suspend fun CommandSender.onCommand(args: MessageChain) Mirai Console 为了简化处理指令时的解析过程,设计了参数智能解析。 -### [`CommandArgumentParser`] +### [`CommandValueArgumentParser`] ```kotlin interface CommandArgumentParser { fun parse(raw: String, sender: CommandSender): T @@ -107,13 +107,13 @@ interface CommandArgumentParser { ### [`CommandArgumentContext`] -是 `Class` 到 [`CommandArgumentParser`] 的映射。作用是为某一个类型分配解析器。 +是 `Class` 到 [`CommandValueArgumentParser`] 的映射。作用是为某一个类型分配解析器。 #### [内建 `CommandArgumentContext`][`CommandArgumentContext.BuiltIns`] 支持原生数据类型,`Contact` 及其子类,`Bot`。 #### 构建 [`CommandArgumentContext`] -查看源码内注释:[CommandArgumentContext.kt: Line 146](../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandArgumentContext.kt#L146-L183) +查看源码内注释:[CommandArgumentContext.kt: Line 146](../backend/mirai-console/src/command/descriptor/CommandArgumentContext.kt#L146-L183) ### 支持参数解析的 [`Command`] 实现 Mirai Console 内建 [`SimpleCommand`] 与 [`CompositeCommand`] 拥有 [`CommandArgumentContext`],在处理参数时会首先解析参数再传递给插件的实现。 @@ -140,8 +140,8 @@ object MySimpleCommand : SimpleCommand( 1. 被分割为 `/`, `"tell"`, `"123456"`, `"Hello"` 2. `MySimpleCommand` 被匹配到,根据 `/` 和 `"test"`。`"123456"`, `"Hello"` 被作为指令的原生参数。 3. 由于 `MySimpleCommand` 定义的 `handle` 需要两个参数, `User` 和 `String`,`"123456"` 需要转换成 `User`,`"Hello"` 需要转换成 `String`。 -4. Console 在 [内建 `CommandArgumentContext`][`CommandArgumentContext.BuiltIns`] 寻找适合于 `User` 的 [`CommandArgumentParser`] -5. `"123456"` 被传入这个 [`CommandArgumentParser`],得到 `User` +4. Console 在 [内建 `CommandArgumentContext`][`CommandArgumentContext.BuiltIns`] 寻找适合于 `User` 的 [`CommandValueArgumentParser`] +5. `"123456"` 被传入这个 [`CommandValueArgumentParser`],得到 `User` 6. `"Hello"` 也会按照 4~5 的步骤转换为 `String` 类型的参数 7. 解析完成的参数被传入 `handle` @@ -253,7 +253,7 @@ ConsoleCommandSender AbstractUserCommandSender | +-----------------------------+----------------------------+---------------+ ``` -有关类型的详细信息,请查看 [CommandSender.kt](../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandSender.kt#L48-L135) +有关类型的详细信息,请查看 [CommandSender.kt](../backend/mirai-console/src/command/CommandSender.kt#L48-L135) ### 获取 @@ -263,4 +263,4 @@ ConsoleCommandSender AbstractUserCommandSender | 表示几个消息对象的’域‘,即消息对象的集合。用于最小化将同一条消息发送给多个类型不同的目标的付出。 -参考 [MessageScope](../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/MessageScope.kt#L28-L99) \ No newline at end of file +参考 [MessageScope](../backend/mirai-console/src/util/MessageScope.kt#L28-L99) \ No newline at end of file diff --git a/docs/ConfiguringProjects.md b/docs/ConfiguringProjects.md index 6831ff24d..5063a8857 100644 --- a/docs/ConfiguringProjects.md +++ b/docs/ConfiguringProjects.md @@ -11,8 +11,6 @@ console 由后端和前端一起工作. 使用时必须选择一个前端. - `mirai-console-terminal`: 终端前端,适用于 JVM。 - [`MiraiAndroid`](https://github.com/mzdluo123/MiraiAndroid): Android 应用前端。 -**注意:`mirai-console` 1.0-RC 发布之前, 前端请使用 `mirai-console-pure` 而不是 `mirai-console-terminal`** - ## 选择版本 有关各类版本的区别,参考 [版本规范](Appendix.md#版本规范) @@ -20,10 +18,10 @@ console 由后端和前端一起工作. 使用时必须选择一个前端. [Version]: https://api.bintray.com/packages/him188moe/mirai/mirai-console/images/download.svg? [Bintray Download]: https://bintray.com/him188moe/mirai/mirai-console/ -| 版本类型 | 版本号 | -|:------:|:------------:| -| 稳定 | - | -| 预览 | 1.0-M4 | +| 版本类型 | 版本号 | +|:------:|:------------------------------:| +| 稳定 | - | +| 预览 | 1.0-RC-1 | | 开发 | [![Version]][Bintray Download] | ## 配置项目 @@ -74,7 +72,6 @@ dependencies { compileOnly("net.mamoe:mirai-console:$CONSOLE_VERSION") // 后端 testImplementation("net.mamoe:mirai-console-terminal:$CONSOLE_VERSION") // 前端, 用于启动测试 - testImplementation("net.mamoe:mirai-console-terminal:$CONSOLE_VERSION") // 前端, 用于启动测试 } ``` diff --git a/docs/Extensions.md b/docs/Extensions.md index 6958c0c5b..9a741b0c0 100644 --- a/docs/Extensions.md +++ b/docs/Extensions.md @@ -4,10 +4,10 @@ Mirai Console 拥有灵活的 Extensions API,支持扩展 Console 的一些服 Extensions 属于插件开发的进阶内容。 -[`Extension`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extension/Extension.kt -[`ExtensionPoint`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extension/ExtensionPoint.kt -[`PluginComponentStorage`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extension/PluginComponentStorage.kt -[`ComponentStorage`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extension/ComponentStorage.kt +[`Extension`]: ../backend/mirai-console/src/extension/Extension.kt +[`ExtensionPoint`]: ../backend/mirai-console/src/extension/ExtensionPoint.kt +[`PluginComponentStorage`]: ../backend/mirai-console/src/extension/PluginComponentStorage.kt +[`ComponentStorage`]: ../backend/mirai-console/src/extension/ComponentStorage.kt ## [扩展][`Extension`] @@ -34,4 +34,4 @@ object MyPlugin : KotlinPlugin( /* ... */ ) { ### 可用扩展 -查看 [extensions](../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/)。每个文件对应一个扩展。 \ No newline at end of file +查看 [extensions](../backend/mirai-console/src/extensions)。每个文件对应一个扩展。 \ No newline at end of file diff --git a/docs/Permissions.md b/docs/Permissions.md index 6ba743f00..9cb6b0fcd 100644 --- a/docs/Permissions.md +++ b/docs/Permissions.md @@ -2,15 +2,15 @@ 权限系统。 -[`PermissionService`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionService.kt -[`Permission`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/Permission.kt -[`RootPermission`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/Permission.kt#L82 -[`PermissionId`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionId.kt -[`PermissionIdNamespace`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionIdNamespace.kt -[`Permittee`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/Permittee.kt -[`PermitteeId`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermitteeId.kt -[`AbstractPermitteeId`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermitteeId.kt#L77 -[`CommandSender`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandSender.kt +[`PermissionService`]: ../backend/mirai-console/src/permission/PermissionService.kt +[`Permission`]: ../backend/mirai-console/src/permission/Permission.kt +[`RootPermission`]: ../backend/mirai-console/src/permission/Permission.kt#L82 +[`PermissionId`]: ../backend/mirai-console/src/permission/PermissionId.kt +[`PermissionIdNamespace`]: ../backend/mirai-console/src/permission/PermissionIdNamespace.kt +[`Permittee`]: ../backend/mirai-console/src/permission/Permittee.kt +[`PermitteeId`]: ../backend/mirai-console/src/permission/PermitteeId.kt +[`AbstractPermitteeId`]: ../backend/mirai-console/src/permission/PermitteeId.kt#L77 +[`CommandSender`]: ../backend/mirai-console/src/command/CommandSender.kt ## 权限 diff --git a/docs/PluginData.md b/docs/PluginData.md index bde09d2c1..c1731f9c3 100644 --- a/docs/PluginData.md +++ b/docs/PluginData.md @@ -1,45 +1,45 @@ # Mirai Console Backend - PluginData -[`Plugin`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/Plugin.kt -[`PluginDescription`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDescription.kt -[`PluginLoader`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/loader/PluginLoader.kt -[`PluginManager`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/PluginManager.kt -[`JvmPluginLoader`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginLoader.kt -[`JvmPlugin`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPlugin.kt -[`JvmPluginDescription`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginDescription.kt -[`AbstractJvmPlugin`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/AbstractJvmPlugin.kt -[`KotlinPlugin`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/KotlinPlugin.kt -[`JavaPlugin`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JavaPlugin.kt +[`Plugin`]: ../backend/mirai-console/src/plugin/Plugin.kt +[`PluginDescription`]: ../backend/mirai-console/src/plugin/description/PluginDescription.kt +[`PluginLoader`]: ../backend/mirai-console/src/plugin/loader/PluginLoader.kt +[`PluginManager`]: ../backend/mirai-console/src/plugin/PluginManager.kt +[`JvmPluginLoader`]: ../backend/mirai-console/src/plugin/jvm/JvmPluginLoader.kt +[`JvmPlugin`]: ../backend/mirai-console/src/plugin/jvm/JvmPlugin.kt +[`JvmPluginDescription`]: ../backend/mirai-console/src/plugin/jvm/JvmPluginDescription.kt +[`AbstractJvmPlugin`]: ../backend/mirai-console/src/plugin/jvm/AbstractJvmPlugin.kt +[`KotlinPlugin`]: ../backend/mirai-console/src/plugin/jvm/KotlinPlugin.kt +[`JavaPlugin`]: ../backend/mirai-console/src/plugin/jvm/JavaPlugin.kt -[`Value`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/Value.kt -[`PluginData`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginData.kt -[`AbstractPluginData`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AbstractPluginData.kt -[`AutoSavePluginData`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AutoSavePluginData.kt -[`AutoSavePluginConfig`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AutoSavePluginConfig.kt -[`PluginConfig`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginConfig.kt -[`PluginDataStorage`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataStorage.kt -[`MultiFilePluginDataStorage`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataStorage.kt#L116 -[`MemoryPluginDataStorage`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataStorage.kt#L100 -[`AutoSavePluginDataHolder`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataHolder.kt#L45 -[`PluginDataHolder`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataHolder.kt -[`PluginDataExtensions`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataExtensions.kt +[`Value`]: ../backend/mirai-console/src/data/Value.kt +[`PluginData`]: ../backend/mirai-console/src/data/PluginData.kt +[`AbstractPluginData`]: ../backend/mirai-console/src/data/AbstractPluginData.kt +[`AutoSavePluginData`]: ../backend/mirai-console/src/data/AutoSavePluginData.kt +[`AutoSavePluginConfig`]: ../backend/mirai-console/src/data/AutoSavePluginConfig.kt +[`PluginConfig`]: ../backend/mirai-console/src/data/PluginConfig.kt +[`PluginDataStorage`]: ../backend/mirai-console/src/data/PluginDataStorage.kt +[`MultiFilePluginDataStorage`]: ../backend/mirai-console/src/data/PluginDataStorage.kt#L116 +[`MemoryPluginDataStorage`]: ../backend/mirai-console/src/data/PluginDataStorage.kt#L100 +[`AutoSavePluginDataHolder`]: ../backend/mirai-console/src/data/PluginDataHolder.kt#L45 +[`PluginDataHolder`]: ../backend/mirai-console/src/data/PluginDataHolder.kt +[`PluginDataExtensions`]: ../backend/mirai-console/src/data/PluginDataExtensions.kt -[`MiraiConsole`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt -[`MiraiConsoleImplementation`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt - +[`MiraiConsole`]: ../backend/mirai-console/src/MiraiConsole.kt +[`MiraiConsoleImplementation`]: ../backend/mirai-console/src/MiraiConsoleImplementation.kt + -[`Command`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/Command.kt -[`CompositeCommand`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CompositeCommand.kt -[`SimpleCommand`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/SimpleCommand.kt -[`RawCommand`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/RawCommand.kt -[`CommandManager`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandManager.kt +[`Command`]: ../backend/mirai-console/src/command/Command.kt +[`CompositeCommand`]: ../backend/mirai-console/src/command/CompositeCommand.kt +[`SimpleCommand`]: ../backend/mirai-console/src/command/SimpleCommand.kt +[`RawCommand`]: ../backend/mirai-console/src/command/RawCommand.kt +[`CommandManager`]: ../backend/mirai-console/src/command/CommandManager.kt -[`Annotations`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/Annotations.kt -[`ConsoleInput`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/ConsoleInput.kt -[`JavaPluginScheduler`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JavaPluginScheduler.kt -[`ResourceContainer`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/ResourceContainer.kt -[`PluginFileExtensions`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/PluginFileExtensions.kt +[`Annotations`]: ../backend/mirai-console/src/util/Annotations.kt +[`ConsoleInput`]: ../backend/mirai-console/src/util/ConsoleInput.kt +[`JavaPluginScheduler`]: ../backend/mirai-console/src/plugin/jvm/JavaPluginScheduler.kt +[`ResourceContainer`]: ../backend/mirai-console/src/plugin/ResourceContainer.kt +[`PluginFileExtensions`]: ../backend/mirai-console/src/plugin/PluginFileExtensions.kt [Kotlin]: https://www.kotlincn.net/ [Java]: https://www.java.com/zh_CN/ @@ -116,7 +116,7 @@ object MyData : AutoSavePluginData() { *由于 Java 语法局限,为 Kotlin 而设计的 PluginData 在 Java 使用很复杂。* *即使 Mirai Console 为 Java 提供适配器,也强烈推荐 Java 用户在项目中混用 Kotlin 代码来完成数据模型定义。* -参考 [JAutoSavePluginData](../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/java/JAutoSavePluginData.kt#L69) +参考 [JAutoSavePluginData](../backend/mirai-console/src/data/java/JAutoSavePluginData.kt#L69) ### 非引用赋值 由于实现特殊, 赋值时不会写其引用. 即: diff --git a/docs/Plugins.md b/docs/Plugins.md index f04beb5f7..63cee40f7 100644 --- a/docs/Plugins.md +++ b/docs/Plugins.md @@ -1,37 +1,39 @@ # Mirai Console Backend - Plugins -[`Plugin`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/Plugin.kt -[`PluginDescription`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDescription.kt -[`PluginLoader`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/loader/PluginLoader.kt -[`PluginManager`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/PluginManager.kt -[`JvmPluginLoader`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginLoader.kt -[`JvmPlugin`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPlugin.kt -[`JvmPluginDescription`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginDescription.kt -[`AbstractJvmPlugin`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/AbstractJvmPlugin.kt -[`KotlinPlugin`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/KotlinPlugin.kt -[`JavaPlugin`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JavaPlugin.kt +[`Plugin`]: ../backend/mirai-console/src/plugin/Plugin.kt +[`PluginDescription`]: ../backend/mirai-console/src/plugin/description/PluginDescription.kt +[`PluginLoader`]: ../backend/mirai-console/src/plugin/loader/PluginLoader.kt +[`PluginManager`]: ../backend/mirai-console/src/plugin/PluginManager.kt +[`JvmPluginLoader`]: ../backend/mirai-console/src/plugin/jvm/JvmPluginLoader.kt +[`JvmPlugin`]: ../backend/mirai-console/src/plugin/jvm/JvmPlugin.kt +[`JvmPluginDescription`]: ../backend/mirai-console/src/plugin/jvm/JvmPluginDescription.kt +[`AbstractJvmPlugin`]: ../backend/mirai-console/src/plugin/jvm/AbstractJvmPlugin.kt +[`KotlinPlugin`]: ../backend/mirai-console/src/plugin/jvm/KotlinPlugin.kt +[`JavaPlugin`]: ../backend/mirai-console/src/plugin/jvm/JavaPlugin.kt -[`PluginData`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginData.kt -[`PluginConfig`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginConfig.kt -[`PluginDataStorage`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataStorage.kt +[`PluginData`]: ../backend/mirai-console/src/data/PluginData.kt +[`PluginConfig`]: ../backend/mirai-console/src/data/PluginConfig.kt +[`PluginDataStorage`]: ../backend/mirai-console/src/data/PluginDataStorage.kt -[`MiraiConsole`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt -[`MiraiConsoleImplementation`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt - +[`ExportManager`]: ../backend/mirai-console/src/plugin/jvm/ExportManager.kt -[`Command`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/Command.kt -[`CompositeCommand`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CompositeCommand.kt -[`SimpleCommand`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/SimpleCommand.kt -[`RawCommand`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/RawCommand.kt -[`CommandManager`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandManager.kt +[`MiraiConsole`]: ../backend/mirai-console/src/MiraiConsole.kt +[`MiraiConsoleImplementation`]: ../backend/mirai-console/src/MiraiConsoleImplementation.kt + -[`Annotations`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/Annotations.kt -[`ConsoleInput`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/ConsoleInput.kt -[`JavaPluginScheduler`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JavaPluginScheduler.kt -[`ResourceContainer`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/ResourceContainer.kt -[`PluginFileExtensions`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/PluginFileExtensions.kt -[`AutoSavePluginDataHolder`]: ../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataHolder.kt#L45 +[`Command`]: ../backend/mirai-console/src/command/Command.kt +[`CompositeCommand`]: ../backend/mirai-console/src/command/CompositeCommand.kt +[`SimpleCommand`]: ../backend/mirai-console/src/command/SimpleCommand.kt +[`RawCommand`]: ../backend/mirai-console/src/command/RawCommand.kt +[`CommandManager`]: ../backend/mirai-console/src/command/CommandManager.kt + +[`Annotations`]: ../backend/mirai-console/src/util/Annotations.kt +[`ConsoleInput`]: ../backend/mirai-console/src/util/ConsoleInput.kt +[`JavaPluginScheduler`]: ../backend/mirai-console/src/plugin/jvm/JavaPluginScheduler.kt +[`ResourceContainer`]: ../backend/mirai-console/src/plugin/ResourceContainer.kt +[`PluginFileExtensions`]: ../backend/mirai-console/src/plugin/PluginFileExtensions.kt +[`AutoSavePluginDataHolder`]: ../backend/mirai-console/src/data/PluginDataHolder.kt#L45 [Kotlin]: https://www.kotlincn.net/ [Java]: https://www.java.com/zh_CN/ @@ -160,6 +162,68 @@ public final class JExample extends JavaPlugin { 多个插件的加载是*顺序的*,意味着若一个插件的 `onLoad()` 等回调处理缓慢,后续插件的加载也会被延后,即使它们可能没有依赖关系。 因此请尽量让 `onLoad()`,`onEnable()`,`onDisable()`快速返回。 +### API 导出管理 + +允许插件将一些内部实现保护起来, 避免其他插件调用, 要启动这个特性, +只需要创建名为 `export-rules.txt` 的规则文件,便可以控制插件的类的公开规则。 + +如果正在使用 `Gradle` 项目, 该规则文件一般位于 `src/main/resources` 下 + +Example: +```text + +# #开头的行全部识别为注释 + +# exports, 允许其他插件直接使用某个类 + +# 导出了一个internal包的一个类 +# +exports org.example.miraiconsole.myplugin.internal.OpenInternal + +# 导出了整个 api 包 +# +exports org.example.miraiconsole.myplugin.api + +# 保护 org.example.miraiconsole.myplugin.api2.Internal, 不允许其他插件直接使用 +# +protects org.example.miraiconsole.myplugin.api2.Internal + +# 保护整个包 +# +# 别名: protect-package +protects org.example.miraiconsole.myplugin.internal + +# 此规则不会生效, 因为在此条规则之前, +# org.example.miraiconsole.myplugin.internal 已经被加入到保护域中 +exports org.example.miraiconsole.myplugin.internal.NotOpenInternal + + +# export-plugin, 允许其他插件使用除了已经被保护的全部类 +# 使用此规则会同时让此规则后的所有规则全部失效 +# 别名: export-all, export-system +# export-plugin + + +# 将整个插件放入保护域中 +# 除了此规则之前显式 export 的类, 其他插件将不允许直接使用被保护的插件的任何类 +# 别名: protect-all, protect-system +protect-plugin + +``` + +插件也可以通过 Service 来自定义导出控制 + +Example: +```kotlin +@AutoService(ExportManager::class) +object MyExportManager: ExportManager { + override fun isExported(className: String): Boolean { + println(" <== $className") + return true + } +} +``` + ### 插件生命周期 Mirai Console 不提供热加载和热卸载功能,所有插件只能在服务器启动前加载,在服务器结束时卸载。([为什么不支持热加载和卸载插件?]) diff --git a/frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/MiraiConsoleGraphicalLoader.kt b/frontend/mirai-console-graphical/src/MiraiConsoleGraphicalLoader.kt similarity index 100% rename from frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/MiraiConsoleGraphicalLoader.kt rename to frontend/mirai-console-graphical/src/MiraiConsoleGraphicalLoader.kt diff --git a/frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/MiraiGraphical.kt b/frontend/mirai-console-graphical/src/MiraiGraphical.kt similarity index 100% rename from frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/MiraiGraphical.kt rename to frontend/mirai-console-graphical/src/MiraiGraphical.kt diff --git a/frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/controller/MiraiGraphicalFrontEndController.kt b/frontend/mirai-console-graphical/src/controller/MiraiGraphicalFrontEndController.kt similarity index 100% rename from frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/controller/MiraiGraphicalFrontEndController.kt rename to frontend/mirai-console-graphical/src/controller/MiraiGraphicalFrontEndController.kt diff --git a/frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/event/ReloadEvent.kt b/frontend/mirai-console-graphical/src/event/ReloadEvent.kt similarity index 100% rename from frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/event/ReloadEvent.kt rename to frontend/mirai-console-graphical/src/event/ReloadEvent.kt diff --git a/frontend/mirai-console-graphical/src/main/resources/character.png b/frontend/mirai-console-graphical/src/main/resources/character.png deleted file mode 100644 index b55153f1e..000000000 Binary files a/frontend/mirai-console-graphical/src/main/resources/character.png and /dev/null differ diff --git a/frontend/mirai-console-graphical/src/main/resources/logo.png b/frontend/mirai-console-graphical/src/main/resources/logo.png deleted file mode 100644 index f0fd0064e..000000000 Binary files a/frontend/mirai-console-graphical/src/main/resources/logo.png and /dev/null differ diff --git a/frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/model/BotModel.kt b/frontend/mirai-console-graphical/src/model/BotModel.kt similarity index 100% rename from frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/model/BotModel.kt rename to frontend/mirai-console-graphical/src/model/BotModel.kt diff --git a/frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/model/ConsoleInfo.kt b/frontend/mirai-console-graphical/src/model/ConsoleInfo.kt similarity index 100% rename from frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/model/ConsoleInfo.kt rename to frontend/mirai-console-graphical/src/model/ConsoleInfo.kt diff --git a/frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/model/GlobalSetting.kt b/frontend/mirai-console-graphical/src/model/GlobalSetting.kt similarity index 100% rename from frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/model/GlobalSetting.kt rename to frontend/mirai-console-graphical/src/model/GlobalSetting.kt diff --git a/frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/model/PluginModel.kt b/frontend/mirai-console-graphical/src/model/PluginModel.kt similarity index 100% rename from frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/model/PluginModel.kt rename to frontend/mirai-console-graphical/src/model/PluginModel.kt diff --git a/frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/model/VerificationCodeModel.kt b/frontend/mirai-console-graphical/src/model/VerificationCodeModel.kt similarity index 100% rename from frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/model/VerificationCodeModel.kt rename to frontend/mirai-console-graphical/src/model/VerificationCodeModel.kt diff --git a/frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/stylesheet/BaseStyleSheet.kt b/frontend/mirai-console-graphical/src/stylesheet/BaseStyleSheet.kt similarity index 100% rename from frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/stylesheet/BaseStyleSheet.kt rename to frontend/mirai-console-graphical/src/stylesheet/BaseStyleSheet.kt diff --git a/frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/stylesheet/LoginViewStyleSheet.kt b/frontend/mirai-console-graphical/src/stylesheet/LoginViewStyleSheet.kt similarity index 100% rename from frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/stylesheet/LoginViewStyleSheet.kt rename to frontend/mirai-console-graphical/src/stylesheet/LoginViewStyleSheet.kt diff --git a/frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/stylesheet/PluginViewStyleSheet.kt b/frontend/mirai-console-graphical/src/stylesheet/PluginViewStyleSheet.kt similarity index 100% rename from frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/stylesheet/PluginViewStyleSheet.kt rename to frontend/mirai-console-graphical/src/stylesheet/PluginViewStyleSheet.kt diff --git a/frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/stylesheet/PrimaryStyleSheet.kt b/frontend/mirai-console-graphical/src/stylesheet/PrimaryStyleSheet.kt similarity index 100% rename from frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/stylesheet/PrimaryStyleSheet.kt rename to frontend/mirai-console-graphical/src/stylesheet/PrimaryStyleSheet.kt diff --git a/frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/util/JFoenixAdaptor.kt b/frontend/mirai-console-graphical/src/util/JFoenixAdaptor.kt similarity index 100% rename from frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/util/JFoenixAdaptor.kt rename to frontend/mirai-console-graphical/src/util/JFoenixAdaptor.kt diff --git a/frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/util/SVG.kt b/frontend/mirai-console-graphical/src/util/SVG.kt similarity index 100% rename from frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/util/SVG.kt rename to frontend/mirai-console-graphical/src/util/SVG.kt diff --git a/frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/util/controls.kt b/frontend/mirai-console-graphical/src/util/controls.kt similarity index 100% rename from frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/util/controls.kt rename to frontend/mirai-console-graphical/src/util/controls.kt diff --git a/frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/Decorator.kt b/frontend/mirai-console-graphical/src/view/Decorator.kt similarity index 100% rename from frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/Decorator.kt rename to frontend/mirai-console-graphical/src/view/Decorator.kt diff --git a/frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/LoginView.kt b/frontend/mirai-console-graphical/src/view/LoginView.kt similarity index 100% rename from frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/LoginView.kt rename to frontend/mirai-console-graphical/src/view/LoginView.kt diff --git a/frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PluginsCenterView.kt b/frontend/mirai-console-graphical/src/view/PluginsCenterView.kt similarity index 100% rename from frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PluginsCenterView.kt rename to frontend/mirai-console-graphical/src/view/PluginsCenterView.kt diff --git a/frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PluginsView.kt b/frontend/mirai-console-graphical/src/view/PluginsView.kt similarity index 100% rename from frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PluginsView.kt rename to frontend/mirai-console-graphical/src/view/PluginsView.kt diff --git a/frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PrimaryView.kt b/frontend/mirai-console-graphical/src/view/PrimaryView.kt similarity index 100% rename from frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PrimaryView.kt rename to frontend/mirai-console-graphical/src/view/PrimaryView.kt diff --git a/frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/SettingsView.kt b/frontend/mirai-console-graphical/src/view/SettingsView.kt similarity index 100% rename from frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/SettingsView.kt rename to frontend/mirai-console-graphical/src/view/SettingsView.kt diff --git a/frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/dialog/InputDialog.kt b/frontend/mirai-console-graphical/src/view/dialog/InputDialog.kt similarity index 100% rename from frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/dialog/InputDialog.kt rename to frontend/mirai-console-graphical/src/view/dialog/InputDialog.kt diff --git a/frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/dialog/PluginDetailFragment.kt b/frontend/mirai-console-graphical/src/view/dialog/PluginDetailFragment.kt similarity index 100% rename from frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/dialog/PluginDetailFragment.kt rename to frontend/mirai-console-graphical/src/view/dialog/PluginDetailFragment.kt diff --git a/frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/dialog/VerificationCodeFragment.kt b/frontend/mirai-console-graphical/src/view/dialog/VerificationCodeFragment.kt similarity index 100% rename from frontend/mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/dialog/VerificationCodeFragment.kt rename to frontend/mirai-console-graphical/src/view/dialog/VerificationCodeFragment.kt diff --git a/frontend/mirai-console-graphical/src/test/kotlin/Main.kt b/frontend/mirai-console-graphical/test/Main.kt similarity index 100% rename from frontend/mirai-console-graphical/src/test/kotlin/Main.kt rename to frontend/mirai-console-graphical/test/Main.kt diff --git a/frontend/mirai-console-terminal/.gitignore b/frontend/mirai-console-terminal/.gitignore new file mode 100644 index 000000000..f35003d5a --- /dev/null +++ b/frontend/mirai-console-terminal/.gitignore @@ -0,0 +1 @@ +/run \ No newline at end of file diff --git a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/BufferedOutputStream.kt b/frontend/mirai-console-terminal/src/BufferedOutputStream.kt similarity index 96% rename from frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/BufferedOutputStream.kt rename to frontend/mirai-console-terminal/src/BufferedOutputStream.kt index ad7f18160..847e42ce9 100644 --- a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/BufferedOutputStream.kt +++ b/frontend/mirai-console-terminal/src/BufferedOutputStream.kt @@ -2,10 +2,9 @@ * 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 via the following link. + * 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.terminal diff --git a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/ConsoleInputImpl.kt b/frontend/mirai-console-terminal/src/ConsoleInputImpl.kt similarity index 97% rename from frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/ConsoleInputImpl.kt rename to frontend/mirai-console-terminal/src/ConsoleInputImpl.kt index c0a83f707..9f69d8765 100644 --- a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/ConsoleInputImpl.kt +++ b/frontend/mirai-console-terminal/src/ConsoleInputImpl.kt @@ -2,10 +2,9 @@ * 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 via the following link. + * 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.terminal diff --git a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/ConsoleTerminalSettings.kt b/frontend/mirai-console-terminal/src/ConsoleTerminalSettings.kt similarity index 90% rename from frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/ConsoleTerminalSettings.kt rename to frontend/mirai-console-terminal/src/ConsoleTerminalSettings.kt index 0c780724e..e652ab4fb 100644 --- a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/ConsoleTerminalSettings.kt +++ b/frontend/mirai-console-terminal/src/ConsoleTerminalSettings.kt @@ -2,10 +2,9 @@ * 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 via the following link. + * 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 - * */ /* * @author Karlatemp @@ -27,7 +26,7 @@ package net.mamoe.mirai.console.terminal annotation class ConsoleTerminalExperimentalApi @ConsoleTerminalExperimentalApi -public object ConsoleTerminalSettings { +object ConsoleTerminalSettings { @JvmField var setupAnsi: Boolean = System.getProperty("os.name") .toLowerCase() diff --git a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/ConsoleThread.kt b/frontend/mirai-console-terminal/src/ConsoleThread.kt similarity index 97% rename from frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/ConsoleThread.kt rename to frontend/mirai-console-terminal/src/ConsoleThread.kt index 5703eb512..97294ca1c 100644 --- a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/ConsoleThread.kt +++ b/frontend/mirai-console-terminal/src/ConsoleThread.kt @@ -2,10 +2,9 @@ * 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 via the following link. + * 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.terminal diff --git a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt b/frontend/mirai-console-terminal/src/MiraiConsoleImplementationTerminal.kt similarity index 97% rename from frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt rename to frontend/mirai-console-terminal/src/MiraiConsoleImplementationTerminal.kt index f86949c16..dbcb26a82 100644 --- a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt +++ b/frontend/mirai-console-terminal/src/MiraiConsoleImplementationTerminal.kt @@ -2,10 +2,9 @@ * 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 via the following link. + * 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 - * */ @file:Suppress( @@ -60,7 +59,7 @@ import java.nio.file.Paths @ConsoleExperimentalApi class MiraiConsoleImplementationTerminal @JvmOverloads constructor( - override val rootPath: Path = Paths.get(".").toAbsolutePath(), + override val rootPath: Path = Paths.get(System.getProperty("user.dir", ".")).toAbsolutePath(), override val builtInPluginLoaders: List>> = listOf(lazy { JvmPluginLoader }), override val frontEndDescription: MiraiConsoleFrontEndDescription = ConsoleFrontEndDescImpl, override val consoleCommandSender: MiraiConsoleImplementation.ConsoleCommandSenderImpl = ConsoleCommandSenderImplTerminal, diff --git a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleTerminalLoader.kt b/frontend/mirai-console-terminal/src/MiraiConsoleTerminalLoader.kt similarity index 98% rename from frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleTerminalLoader.kt rename to frontend/mirai-console-terminal/src/MiraiConsoleTerminalLoader.kt index 930e72b48..aead7f1d8 100644 --- a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleTerminalLoader.kt +++ b/frontend/mirai-console-terminal/src/MiraiConsoleTerminalLoader.kt @@ -2,10 +2,9 @@ * 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 via the following link. + * 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 - * */ @file:Suppress( diff --git a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/pure/MiraiConsolePureLoader.kt b/frontend/mirai-console-terminal/src/net/mamoe/mirai/console/pure/MiraiConsolePureLoader.kt similarity index 93% rename from frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/pure/MiraiConsolePureLoader.kt rename to frontend/mirai-console-terminal/src/net/mamoe/mirai/console/pure/MiraiConsolePureLoader.kt index 477d8dcdc..56cd040e3 100644 --- a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/pure/MiraiConsolePureLoader.kt +++ b/frontend/mirai-console-terminal/src/net/mamoe/mirai/console/pure/MiraiConsolePureLoader.kt @@ -2,10 +2,9 @@ * 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 via the following link. + * 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.pure diff --git a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/noconsole/NoConsole.kt b/frontend/mirai-console-terminal/src/noconsole/NoConsole.kt similarity index 98% rename from frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/noconsole/NoConsole.kt rename to frontend/mirai-console-terminal/src/noconsole/NoConsole.kt index 45a8be66d..bf0c054d6 100644 --- a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/noconsole/NoConsole.kt +++ b/frontend/mirai-console-terminal/src/noconsole/NoConsole.kt @@ -2,7 +2,7 @@ * 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 via the following link. + * 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 */ diff --git a/frontend/mirai-console-terminal/test/RunTerminal.kt b/frontend/mirai-console-terminal/test/RunTerminal.kt new file mode 100644 index 000000000..901433db3 --- /dev/null +++ b/frontend/mirai-console-terminal/test/RunTerminal.kt @@ -0,0 +1,33 @@ +/* + * Copyright 2020 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + */ + +package net.mamoe.mirai.console.terminal + +import kotlinx.coroutines.runBlocking +import net.mamoe.mirai.console.MiraiConsole +import java.io.File + +fun main() { + configureUserDir() + + MiraiConsoleTerminalLoader.startAsDaemon() + runCatching { runBlocking { MiraiConsole.job.join() } } +} + +internal fun configureUserDir() { + val projectDir = runCatching { + File(".").resolve("frontend").resolve("mirai-console-terminal") + }.getOrElse { return } + if (projectDir.isDirectory) { + val run = projectDir.resolve("run") + run.mkdir() + System.setProperty("user.dir", run.absolutePath) + println("[Mirai Console] Set user.dir = ${run.absolutePath}") + } +} \ No newline at end of file diff --git a/tools/compiler-common/src/diagnostics/MiraiConsoleErrors.kt b/tools/compiler-common/src/diagnostics/MiraiConsoleErrors.kt new file mode 100644 index 000000000..03d21ea9e --- /dev/null +++ b/tools/compiler-common/src/diagnostics/MiraiConsoleErrors.kt @@ -0,0 +1,58 @@ +/* + * 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.compiler.common.diagnostics + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.diagnostics.DiagnosticFactory1.create +import org.jetbrains.kotlin.diagnostics.DiagnosticFactory2.create +import org.jetbrains.kotlin.diagnostics.Errors +import org.jetbrains.kotlin.diagnostics.Severity.ERROR +import org.jetbrains.kotlin.psi.KtNamedDeclaration + +object MiraiConsoleErrors { + @JvmStatic + val ILLEGAL_PLUGIN_DESCRIPTION = create(ERROR) + + @JvmStatic + val NOT_CONSTRUCTABLE_TYPE = create(ERROR) + + @JvmStatic + val UNSERIALIZABLE_TYPE = create(ERROR) + + @JvmStatic + val ILLEGAL_COMMAND_NAME = create(ERROR) + + @JvmStatic + val ILLEGAL_PERMISSION_NAME = create(ERROR) + + @JvmStatic + val ILLEGAL_PERMISSION_ID = create(ERROR) + + @JvmStatic + val ILLEGAL_PERMISSION_NAMESPACE = create(ERROR) + + @JvmStatic + val ILLEGAL_COMMAND_REGISTER_USE = create(ERROR) + + @JvmStatic + val ILLEGAL_PERMISSION_REGISTER_USE = create(ERROR) + + @Suppress("ObjectPropertyName", "unused") + @JvmStatic + @Deprecated("", level = DeprecationLevel.ERROR) + val _init: Any = object : Any() { + init { + Errors.Initializer.initializeFactoryNamesAndDefaultErrorMessages( + MiraiConsoleErrors::class.java, + MiraiConsoleErrorsRendering + ) + } + } +} \ No newline at end of file diff --git a/tools/compiler-common/src/main/kotlin/net/mamoe/mirai/console/compiler/common/diagnostics/MiraiConsoleErrorsRendering.kt b/tools/compiler-common/src/diagnostics/MiraiConsoleErrorsRendering.kt similarity index 71% rename from tools/compiler-common/src/main/kotlin/net/mamoe/mirai/console/compiler/common/diagnostics/MiraiConsoleErrorsRendering.kt rename to tools/compiler-common/src/diagnostics/MiraiConsoleErrorsRendering.kt index ca79ec5b3..734a3a02a 100644 --- a/tools/compiler-common/src/main/kotlin/net/mamoe/mirai/console/compiler/common/diagnostics/MiraiConsoleErrorsRendering.kt +++ b/tools/compiler-common/src/diagnostics/MiraiConsoleErrorsRendering.kt @@ -2,14 +2,22 @@ * 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 via the following link. + * 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.compiler.common.diagnostics -import net.mamoe.mirai.console.compiler.common.diagnostics.MiraiConsoleErrors.* +import net.mamoe.mirai.console.compiler.common.diagnostics.MiraiConsoleErrors.ILLEGAL_COMMAND_NAME +import net.mamoe.mirai.console.compiler.common.diagnostics.MiraiConsoleErrors.ILLEGAL_COMMAND_REGISTER_USE +import net.mamoe.mirai.console.compiler.common.diagnostics.MiraiConsoleErrors.ILLEGAL_PERMISSION_ID +import net.mamoe.mirai.console.compiler.common.diagnostics.MiraiConsoleErrors.ILLEGAL_PERMISSION_NAME +import net.mamoe.mirai.console.compiler.common.diagnostics.MiraiConsoleErrors.ILLEGAL_PERMISSION_NAMESPACE +import net.mamoe.mirai.console.compiler.common.diagnostics.MiraiConsoleErrors.ILLEGAL_PERMISSION_REGISTER_USE +import net.mamoe.mirai.console.compiler.common.diagnostics.MiraiConsoleErrors.ILLEGAL_PLUGIN_DESCRIPTION +import net.mamoe.mirai.console.compiler.common.diagnostics.MiraiConsoleErrors.NOT_CONSTRUCTABLE_TYPE +import net.mamoe.mirai.console.compiler.common.diagnostics.MiraiConsoleErrors.UNSERIALIZABLE_TYPE import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages import org.jetbrains.kotlin.diagnostics.rendering.DiagnosticFactoryToRendererMap import org.jetbrains.kotlin.diagnostics.rendering.Renderers diff --git a/tools/compiler-common/src/main/java/net/mamoe/mirai/console/compiler/common/diagnostics/MiraiConsoleErrors.java b/tools/compiler-common/src/main/java/net/mamoe/mirai/console/compiler/common/diagnostics/MiraiConsoleErrors.java deleted file mode 100644 index a8181fb84..000000000 --- a/tools/compiler-common/src/main/java/net/mamoe/mirai/console/compiler/common/diagnostics/MiraiConsoleErrors.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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 via the following link. - * - * https://github.com/mamoe/mirai/blob/master/LICENSE - */ - -package net.mamoe.mirai.console.compiler.common.diagnostics; - -import com.intellij.psi.PsiElement; -import org.jetbrains.kotlin.descriptors.ClassDescriptor; -import org.jetbrains.kotlin.diagnostics.DiagnosticFactory1; -import org.jetbrains.kotlin.diagnostics.DiagnosticFactory2; -import org.jetbrains.kotlin.diagnostics.Errors; -import org.jetbrains.kotlin.psi.KtNamedDeclaration; - -import static org.jetbrains.kotlin.diagnostics.Severity.ERROR; - -public interface MiraiConsoleErrors { - DiagnosticFactory1 ILLEGAL_PLUGIN_DESCRIPTION = DiagnosticFactory1.create(ERROR); - DiagnosticFactory1 NOT_CONSTRUCTABLE_TYPE = DiagnosticFactory1.create(ERROR); - DiagnosticFactory1 UNSERIALIZABLE_TYPE = DiagnosticFactory1.create(ERROR); - DiagnosticFactory2 ILLEGAL_COMMAND_NAME = DiagnosticFactory2.create(ERROR); - DiagnosticFactory2 ILLEGAL_PERMISSION_NAME = DiagnosticFactory2.create(ERROR); - DiagnosticFactory2 ILLEGAL_PERMISSION_ID = DiagnosticFactory2.create(ERROR); - DiagnosticFactory2 ILLEGAL_PERMISSION_NAMESPACE = DiagnosticFactory2.create(ERROR); - DiagnosticFactory2 ILLEGAL_COMMAND_REGISTER_USE = DiagnosticFactory2.create(ERROR); - DiagnosticFactory2 ILLEGAL_PERMISSION_REGISTER_USE = DiagnosticFactory2.create(ERROR); - - @Deprecated - Object _init = new Object() { - { - Errors.Initializer.initializeFactoryNamesAndDefaultErrorMessages( - MiraiConsoleErrors.class, - MiraiConsoleErrorsRendering.INSTANCE - ); - } - }; -} diff --git a/tools/compiler-common/src/main/kotlin/net/mamoe/mirai/console/compiler/common/resolve/resolveCommon.kt b/tools/compiler-common/src/resolve/resolveCommon.kt similarity index 88% rename from tools/compiler-common/src/main/kotlin/net/mamoe/mirai/console/compiler/common/resolve/resolveCommon.kt rename to tools/compiler-common/src/resolve/resolveCommon.kt index 670ccba04..b58b40d78 100644 --- a/tools/compiler-common/src/main/kotlin/net/mamoe/mirai/console/compiler/common/resolve/resolveCommon.kt +++ b/tools/compiler-common/src/resolve/resolveCommon.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/tools/compiler-common/src/main/kotlin/net/mamoe/mirai/console/compiler/common/resolve/resolveTypes.kt b/tools/compiler-common/src/resolve/resolveTypes.kt similarity index 93% rename from tools/compiler-common/src/main/kotlin/net/mamoe/mirai/console/compiler/common/resolve/resolveTypes.kt rename to tools/compiler-common/src/resolve/resolveTypes.kt index b09530ae4..9687dc4b9 100644 --- a/tools/compiler-common/src/main/kotlin/net/mamoe/mirai/console/compiler/common/resolve/resolveTypes.kt +++ b/tools/compiler-common/src/resolve/resolveTypes.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ @@ -56,7 +56,7 @@ val RESOLVE_CONTEXT_FQ_NAME = FqName("net.mamoe.mirai.console.compiler.common.Re enum class ResolveContextKind { PLUGIN_ID, PLUGIN_NAME, - PLUGIN_VERSION, + SEMANTIC_VERSION, VERSION_REQUIREMENT, diff --git a/tools/compiler-common/src/main/kotlin/net/mamoe/mirai/console/compiler/common/utilCommon.kt b/tools/compiler-common/src/utilCommon.kt similarity index 79% rename from tools/compiler-common/src/main/kotlin/net/mamoe/mirai/console/compiler/common/utilCommon.kt rename to tools/compiler-common/src/utilCommon.kt index 4726abb9f..6ee261353 100644 --- a/tools/compiler-common/src/main/kotlin/net/mamoe/mirai/console/compiler/common/utilCommon.kt +++ b/tools/compiler-common/src/utilCommon.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/tools/gradle-plugin/src/main/kotlin/net/mamoe/mirai/console/gradle/IGNORED_DEPENDENCIES_IN_SHADOW.kt b/tools/gradle-plugin/src/IGNORED_DEPENDENCIES_IN_SHADOW.kt similarity index 95% rename from tools/gradle-plugin/src/main/kotlin/net/mamoe/mirai/console/gradle/IGNORED_DEPENDENCIES_IN_SHADOW.kt rename to tools/gradle-plugin/src/IGNORED_DEPENDENCIES_IN_SHADOW.kt index 4b619f28f..ddc9951d9 100644 --- a/tools/gradle-plugin/src/main/kotlin/net/mamoe/mirai/console/gradle/IGNORED_DEPENDENCIES_IN_SHADOW.kt +++ b/tools/gradle-plugin/src/IGNORED_DEPENDENCIES_IN_SHADOW.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/tools/gradle-plugin/src/main/kotlin/net/mamoe/mirai/console/gradle/MiraiConsoleExtension.kt b/tools/gradle-plugin/src/MiraiConsoleExtension.kt similarity index 94% rename from tools/gradle-plugin/src/main/kotlin/net/mamoe/mirai/console/gradle/MiraiConsoleExtension.kt rename to tools/gradle-plugin/src/MiraiConsoleExtension.kt index 74dc3043a..572a74a76 100644 --- a/tools/gradle-plugin/src/main/kotlin/net/mamoe/mirai/console/gradle/MiraiConsoleExtension.kt +++ b/tools/gradle-plugin/src/MiraiConsoleExtension.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/tools/gradle-plugin/src/main/kotlin/net/mamoe/mirai/console/gradle/MiraiConsoleGradlePlugin.kt b/tools/gradle-plugin/src/MiraiConsoleGradlePlugin.kt similarity index 97% rename from tools/gradle-plugin/src/main/kotlin/net/mamoe/mirai/console/gradle/MiraiConsoleGradlePlugin.kt rename to tools/gradle-plugin/src/MiraiConsoleGradlePlugin.kt index 051502390..427eba7b9 100644 --- a/tools/gradle-plugin/src/main/kotlin/net/mamoe/mirai/console/gradle/MiraiConsoleGradlePlugin.kt +++ b/tools/gradle-plugin/src/MiraiConsoleGradlePlugin.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/tools/gradle-plugin/src/main/kotlin/net/mamoe/mirai/console/gradle/VersionConstants.kt b/tools/gradle-plugin/src/VersionConstants.kt similarity index 55% rename from tools/gradle-plugin/src/main/kotlin/net/mamoe/mirai/console/gradle/VersionConstants.kt rename to tools/gradle-plugin/src/VersionConstants.kt index 8dd24fdf1..2ed00f770 100644 --- a/tools/gradle-plugin/src/main/kotlin/net/mamoe/mirai/console/gradle/VersionConstants.kt +++ b/tools/gradle-plugin/src/VersionConstants.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ @@ -10,6 +10,6 @@ package net.mamoe.mirai.console.gradle internal object VersionConstants { - const val CONSOLE_VERSION = "1.0-RC-dev-32" // value is written here automatically during build + const val CONSOLE_VERSION = "1.0-RC-1" // value is written here automatically during build const val CORE_VERSION = "1.3.2" // value is written here automatically during build } \ No newline at end of file diff --git a/tools/intellij-plugin/README.md b/tools/intellij-plugin/README.md index 1d79320c2..db1cc56c6 100644 --- a/tools/intellij-plugin/README.md +++ b/tools/intellij-plugin/README.md @@ -8,9 +8,7 @@ IntelliJ 平台的 Mirai Console 开发插件 #### ILLEGAL_PLUGIN_DESCRIPTION -[PluginDescriptionChecker.kt](src/main/kotlin/net/mamoe/mirai/console/intellij/diagnostics/PluginDescriptionChecker.kt#L34) - -- 使用 [ResolveContext](../../backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/compiler/common/ResolveContext.kt) +- 使用 [ResolveContext](../../backend/mirai-console/src/common/ResolveContext.kt) - 检测 Plugin Id, Plugin Name, Plugin Version 的合法性. 并在非法时提示正确的语法. - 支持编译期常量 diff --git a/tools/intellij-plugin/src/main/resources/META-INF/plugin.xml b/tools/intellij-plugin/resources/META-INF/plugin.xml similarity index 81% rename from tools/intellij-plugin/src/main/resources/META-INF/plugin.xml rename to tools/intellij-plugin/resources/META-INF/plugin.xml index 12267adbc..3dbd79325 100644 --- a/tools/intellij-plugin/src/main/resources/META-INF/plugin.xml +++ b/tools/intellij-plugin/resources/META-INF/plugin.xml @@ -1,3 +1,12 @@ + + net.mamoe.mirai-console diff --git a/tools/intellij-plugin/src/main/resources/icons/commandDeclaration.svg b/tools/intellij-plugin/resources/icons/commandDeclaration.svg similarity index 100% rename from tools/intellij-plugin/src/main/resources/icons/commandDeclaration.svg rename to tools/intellij-plugin/resources/icons/commandDeclaration.svg diff --git a/tools/intellij-plugin/src/main/resources/icons/pluginIcon.svg b/tools/intellij-plugin/resources/icons/pluginIcon.svg similarity index 100% rename from tools/intellij-plugin/src/main/resources/icons/pluginIcon.svg rename to tools/intellij-plugin/resources/icons/pluginIcon.svg diff --git a/tools/intellij-plugin/resources/icons/pluginMainDeclaration.png b/tools/intellij-plugin/resources/icons/pluginMainDeclaration.png new file mode 100644 index 000000000..386d238b2 Binary files /dev/null and b/tools/intellij-plugin/resources/icons/pluginMainDeclaration.png differ diff --git a/tools/intellij-plugin/run/projects/test-project/build.gradle.kts b/tools/intellij-plugin/run/projects/test-project/build.gradle.kts index 7125213bc..f1d0e6a2a 100644 --- a/tools/intellij-plugin/run/projects/test-project/build.gradle.kts +++ b/tools/intellij-plugin/run/projects/test-project/build.gradle.kts @@ -21,8 +21,8 @@ kotlin.sourceSets.all { dependencies { compileOnly(kotlin("stdlib-jdk8")) - val core = "1.3.0" - val console = "1.0-RC-dev-28" + val core = "1.3.2" + val console = "1.0-RC-dev-33" compileOnly("net.mamoe:mirai-console:$console") compileOnly("net.mamoe:mirai-core:$core") diff --git a/tools/intellij-plugin/run/projects/test-project/src/main/kotlin/org/example/myplugin/MyPluginMain.kt b/tools/intellij-plugin/run/projects/test-project/src/main/kotlin/org/example/myplugin/MyPluginMain.kt index 7c90205d7..8856e0d1b 100644 --- a/tools/intellij-plugin/run/projects/test-project/src/main/kotlin/org/example/myplugin/MyPluginMain.kt +++ b/tools/intellij-plugin/run/projects/test-project/src/main/kotlin/org/example/myplugin/MyPluginMain.kt @@ -8,12 +8,12 @@ import net.mamoe.mirai.console.permission.PermissionService import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription import net.mamoe.mirai.console.plugin.jvm.KotlinPlugin -val T = "org.example" // 编译期常量 +const val T = "org.example" // 编译期常量 object MyPluginMain : KotlinPlugin( JvmPluginDescription( T, - "0.1.0", + "1.0-M4", ) { name(".") } diff --git a/tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/IDEContainerContributor.kt b/tools/intellij-plugin/src/IDEContainerContributor.kt similarity index 83% rename from tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/IDEContainerContributor.kt rename to tools/intellij-plugin/src/IDEContainerContributor.kt index 772e5acb4..00b331fc7 100644 --- a/tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/IDEContainerContributor.kt +++ b/tools/intellij-plugin/src/IDEContainerContributor.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/Icons.kt b/tools/intellij-plugin/src/Icons.kt similarity index 71% rename from tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/Icons.kt rename to tools/intellij-plugin/src/Icons.kt index ae7217290..3e7b6f5d2 100644 --- a/tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/Icons.kt +++ b/tools/intellij-plugin/src/Icons.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/QuickFixRegistrar.kt b/tools/intellij-plugin/src/QuickFixRegistrar.kt similarity index 71% rename from tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/QuickFixRegistrar.kt rename to tools/intellij-plugin/src/QuickFixRegistrar.kt index 6e338736c..e13b263ba 100644 --- a/tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/QuickFixRegistrar.kt +++ b/tools/intellij-plugin/src/QuickFixRegistrar.kt @@ -1,3 +1,12 @@ +/* + * 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.intellij import com.intellij.codeInsight.intention.IntentionAction diff --git a/tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/diagnostics/ContextualParametersChecker.kt b/tools/intellij-plugin/src/diagnostics/ContextualParametersChecker.kt similarity index 87% rename from tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/diagnostics/ContextualParametersChecker.kt rename to tools/intellij-plugin/src/diagnostics/ContextualParametersChecker.kt index ab82110a8..67d62adc1 100644 --- a/tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/diagnostics/ContextualParametersChecker.kt +++ b/tools/intellij-plugin/src/diagnostics/ContextualParametersChecker.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ @@ -10,7 +10,11 @@ package net.mamoe.mirai.console.intellij.diagnostics import com.intellij.psi.PsiElement -import net.mamoe.mirai.console.compiler.common.diagnostics.MiraiConsoleErrors.* +import net.mamoe.mirai.console.compiler.common.diagnostics.MiraiConsoleErrors.ILLEGAL_COMMAND_NAME +import net.mamoe.mirai.console.compiler.common.diagnostics.MiraiConsoleErrors.ILLEGAL_PERMISSION_ID +import net.mamoe.mirai.console.compiler.common.diagnostics.MiraiConsoleErrors.ILLEGAL_PERMISSION_NAME +import net.mamoe.mirai.console.compiler.common.diagnostics.MiraiConsoleErrors.ILLEGAL_PERMISSION_NAMESPACE +import net.mamoe.mirai.console.compiler.common.diagnostics.MiraiConsoleErrors.ILLEGAL_PLUGIN_DESCRIPTION import net.mamoe.mirai.console.compiler.common.resolve.ResolveContextKind import net.mamoe.mirai.console.compiler.common.resolve.resolveContextKinds import net.mamoe.mirai.console.intellij.resolve.resolveAllCalls @@ -24,11 +28,11 @@ import org.jetbrains.kotlin.resolve.checkers.DeclarationCheckerContext import java.util.* /** - * Checks paramters with [ResolveContextKind] + * Checks parameters with [ResolveContextKind] */ class ContextualParametersChecker : DeclarationChecker { companion object { - private val ID_REGEX: Regex = Regex("""([a-zA-Z]+(?:\.[a-zA-Z0-9]+)*)\.([a-zA-Z]+(?:-[a-zA-Z0-9]+)*)""") + private val ID_REGEX: Regex = Regex("""([a-zA-Z][a-zA-Z0-9]*(?:\.[a-zA-Z][a-zA-Z0-9]*)*)\.([a-zA-Z][a-zA-Z0-9]*(?:-[a-zA-Z0-9]+)*)""") private val FORBIDDEN_ID_NAMES: Array = arrayOf("main", "console", "plugin", "config", "data") private const val syntax = """类似于 "net.mamoe.mirai.example-plugin", 其中 "net.mamoe.mirai" 为 groupId, "example-plugin" 为插件名""" @@ -37,7 +41,7 @@ class ContextualParametersChecker : DeclarationChecker { * https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string */ private val SEMANTIC_VERSIONING_REGEX = - Regex("""^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?${'$'}""") + Regex("""^(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?${'$'}""") fun checkPluginId(inspectionTarget: PsiElement, value: String): Diagnostic? { if (value.isBlank()) return ILLEGAL_PLUGIN_DESCRIPTION.on(inspectionTarget, "插件 Id 不能为空. \n插件 Id$syntax") @@ -120,7 +124,7 @@ class ContextualParametersChecker : DeclarationChecker { EnumMap Diagnostic?>(ResolveContextKind::class.java).apply { put(ResolveContextKind.PLUGIN_NAME, ::checkPluginName) put(ResolveContextKind.PLUGIN_ID, ::checkPluginId) - put(ResolveContextKind.PLUGIN_VERSION, ::checkPluginVersion) + put(ResolveContextKind.SEMANTIC_VERSION, ::checkPluginVersion) put(ResolveContextKind.COMMAND_NAME, ::checkCommandName) put(ResolveContextKind.PERMISSION_NAME, ::checkPermissionName) put(ResolveContextKind.PERMISSION_NAMESPACE, ::checkPermissionNamespace) diff --git a/tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/diagnostics/PluginDataValuesChecker.kt b/tools/intellij-plugin/src/diagnostics/PluginDataValuesChecker.kt similarity index 93% rename from tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/diagnostics/PluginDataValuesChecker.kt rename to tools/intellij-plugin/src/diagnostics/PluginDataValuesChecker.kt index 862e29d89..79b584b3f 100644 --- a/tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/diagnostics/PluginDataValuesChecker.kt +++ b/tools/intellij-plugin/src/diagnostics/PluginDataValuesChecker.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/diagnostics/diagnosticsUtil.kt b/tools/intellij-plugin/src/diagnostics/diagnosticsUtil.kt similarity index 83% rename from tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/diagnostics/diagnosticsUtil.kt rename to tools/intellij-plugin/src/diagnostics/diagnosticsUtil.kt index 1c7d4911f..066a3985b 100644 --- a/tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/diagnostics/diagnosticsUtil.kt +++ b/tools/intellij-plugin/src/diagnostics/diagnosticsUtil.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/diagnostics/fix/AbuseYellowIntention.kt b/tools/intellij-plugin/src/diagnostics/fix/AbuseYellowIntention.kt similarity index 84% rename from tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/diagnostics/fix/AbuseYellowIntention.kt rename to tools/intellij-plugin/src/diagnostics/fix/AbuseYellowIntention.kt index fbb08fea4..e2cd2dbb0 100644 --- a/tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/diagnostics/fix/AbuseYellowIntention.kt +++ b/tools/intellij-plugin/src/diagnostics/fix/AbuseYellowIntention.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/diagnostics/fix/AddSerializerFix.kt b/tools/intellij-plugin/src/diagnostics/fix/AddSerializerFix.kt similarity index 83% rename from tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/diagnostics/fix/AddSerializerFix.kt rename to tools/intellij-plugin/src/diagnostics/fix/AddSerializerFix.kt index e2cb8625c..dd71d28c3 100644 --- a/tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/diagnostics/fix/AddSerializerFix.kt +++ b/tools/intellij-plugin/src/diagnostics/fix/AddSerializerFix.kt @@ -1,3 +1,12 @@ +/* + * 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.intellij.diagnostics.fix import com.intellij.codeInsight.intention.IntentionAction diff --git a/tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/line/marker/CommandDeclarationLineMarkerProvider.kt b/tools/intellij-plugin/src/line/marker/CommandDeclarationLineMarkerProvider.kt similarity index 89% rename from tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/line/marker/CommandDeclarationLineMarkerProvider.kt rename to tools/intellij-plugin/src/line/marker/CommandDeclarationLineMarkerProvider.kt index 43ba32e21..d2f6c4c8f 100644 --- a/tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/line/marker/CommandDeclarationLineMarkerProvider.kt +++ b/tools/intellij-plugin/src/line/marker/CommandDeclarationLineMarkerProvider.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/line/marker/PluginMainLineMarkerProvider.kt b/tools/intellij-plugin/src/line/marker/PluginMainLineMarkerProvider.kt similarity index 92% rename from tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/line/marker/PluginMainLineMarkerProvider.kt rename to tools/intellij-plugin/src/line/marker/PluginMainLineMarkerProvider.kt index b69cd1f4d..4bd6b1bfb 100644 --- a/tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/line/marker/PluginMainLineMarkerProvider.kt +++ b/tools/intellij-plugin/src/line/marker/PluginMainLineMarkerProvider.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */ diff --git a/tools/intellij-plugin/src/main/resources/icons/pluginMainDeclaration.png b/tools/intellij-plugin/src/main/resources/icons/pluginMainDeclaration.png deleted file mode 100644 index 7b107ff3d..000000000 Binary files a/tools/intellij-plugin/src/main/resources/icons/pluginMainDeclaration.png and /dev/null differ diff --git a/tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/resolve/resolveIdea.kt b/tools/intellij-plugin/src/resolve/resolveIdea.kt similarity index 97% rename from tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/resolve/resolveIdea.kt rename to tools/intellij-plugin/src/resolve/resolveIdea.kt index a8afeb64b..dfcd8389b 100644 --- a/tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/resolve/resolveIdea.kt +++ b/tools/intellij-plugin/src/resolve/resolveIdea.kt @@ -1,8 +1,8 @@ /* - * Copyright 2020 Mamoe Technologies and contributors. + * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * 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 */