mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-25 15:40:28 +08:00
Merge branch 'master' into command
# Conflicts: # tools/gradle-plugin/src/main/kotlin/net/mamoe/mirai/console/gradle/VersionConstants.kt
This commit is contained in:
commit
fa43f2689c
@ -100,8 +100,8 @@ tasks {
|
|||||||
})"""
|
})"""
|
||||||
}
|
}
|
||||||
.replace(
|
.replace(
|
||||||
Regex("""val version: SemVersion = SemVersion.parse\(".*"\)""")
|
Regex("""const val versionConst:\s+String\s+=\s+".*"""")
|
||||||
) { """val version: SemVersion = SemVersion.parse("${project.version}")""" }
|
) { """const val versionConst: String = "${project.version}"""" }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,5 @@ public interface MiraiConsoleFrontEndDescription {
|
|||||||
/**
|
/**
|
||||||
* 返回显示在 [MiraiConsole] 启动时的信息
|
* 返回显示在 [MiraiConsole] 启动时的信息
|
||||||
*/
|
*/
|
||||||
@JvmDefault
|
|
||||||
public fun render(): String = "Frontend ${name}: version ${version}, provided by $vendor"
|
public fun render(): String = "Frontend ${name}: version ${version}, provided by $vendor"
|
||||||
}
|
}
|
@ -108,12 +108,10 @@ public interface MiraiConsoleImplementation : CoroutineScope {
|
|||||||
|
|
||||||
|
|
||||||
@JvmSynthetic
|
@JvmSynthetic
|
||||||
@JvmDefault
|
|
||||||
public override suspend fun sendMessage(message: Message): Unit =
|
public override suspend fun sendMessage(message: Message): Unit =
|
||||||
withContext(Dispatchers.IO) { sendMessageJ(message) }
|
withContext(Dispatchers.IO) { sendMessageJ(message) }
|
||||||
|
|
||||||
@JvmSynthetic
|
@JvmSynthetic
|
||||||
@JvmDefault
|
|
||||||
public override suspend fun sendMessage(message: String): Unit =
|
public override suspend fun sendMessage(message: String): Unit =
|
||||||
withContext(Dispatchers.IO) { sendMessageJ(message) }
|
withContext(Dispatchers.IO) { sendMessageJ(message) }
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,6 @@ public interface CommandSender : CoroutineScope, Permittee {
|
|||||||
*
|
*
|
||||||
* 对于 [MemberCommandSender], 这个函数总是发送给所在群
|
* 对于 [MemberCommandSender], 这个函数总是发送给所在群
|
||||||
*/
|
*/
|
||||||
@JvmDefault
|
|
||||||
@JvmBlockingBridge
|
@JvmBlockingBridge
|
||||||
public suspend fun sendMessage(message: String): MessageReceipt<Contact>?
|
public suspend fun sendMessage(message: String): MessageReceipt<Contact>?
|
||||||
|
|
||||||
|
@ -77,7 +77,6 @@ public interface CommandValueArgumentParser<out T : Any> {
|
|||||||
* @see CommandArgumentParserException
|
* @see CommandArgumentParserException
|
||||||
*/
|
*/
|
||||||
@Throws(CommandArgumentParserException::class)
|
@Throws(CommandArgumentParserException::class)
|
||||||
@JvmDefault
|
|
||||||
public fun parse(raw: MessageContent, sender: CommandSender): T = parse(raw.content, sender)
|
public fun parse(raw: MessageContent, sender: CommandSender): T = parse(raw.content, sender)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,6 @@ public interface PluginDataHolder {
|
|||||||
* @see Companion.newPluginDataInstance
|
* @see Companion.newPluginDataInstance
|
||||||
* @see KClass.createType
|
* @see KClass.createType
|
||||||
*/
|
*/
|
||||||
@JvmDefault
|
|
||||||
public fun <T : PluginData> newPluginDataInstance(type: KType): T =
|
public fun <T : PluginData> newPluginDataInstance(type: KType): T =
|
||||||
newPluginDataInstanceUsingReflection<PluginData>(type) as T
|
newPluginDataInstanceUsingReflection<PluginData>(type) as T
|
||||||
|
|
||||||
@ -64,7 +63,6 @@ public interface AutoSavePluginDataHolder : PluginDataHolder, CoroutineScope {
|
|||||||
/**
|
/**
|
||||||
* 仅支持确切的 [PluginData] 类型
|
* 仅支持确切的 [PluginData] 类型
|
||||||
*/
|
*/
|
||||||
@JvmDefault
|
|
||||||
public override fun <T : PluginData> newPluginDataInstance(type: KType): T {
|
public override fun <T : PluginData> newPluginDataInstance(type: KType): T {
|
||||||
val classifier = type.classifier?.cast<KClass<PluginData>>()
|
val classifier = type.classifier?.cast<KClass<PluginData>>()
|
||||||
require(classifier != null && classifier.java == PluginData::class.java) {
|
require(classifier != null && classifier.java == PluginData::class.java) {
|
||||||
|
@ -14,8 +14,9 @@ import java.time.Instant
|
|||||||
|
|
||||||
internal object MiraiConsoleBuildConstants { // auto-filled on build (task :mirai-console:fillBuildConstants)
|
internal object MiraiConsoleBuildConstants { // auto-filled on build (task :mirai-console:fillBuildConstants)
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
val buildDate: Instant = Instant.ofEpochSecond(1600663022)
|
val buildDate: Instant = Instant.ofEpochSecond(1601134282)
|
||||||
|
const val versionConst: String = "1.0-RC-dev-29"
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
val version: SemVersion = SemVersion("1.0-RC-dev-28")
|
val version: SemVersion = SemVersion(versionConst)
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ import net.mamoe.mirai.console.permission.AbstractPermitteeId.*
|
|||||||
|
|
||||||
internal fun parseFromStringImpl(string: String): AbstractPermitteeId {
|
internal fun parseFromStringImpl(string: String): AbstractPermitteeId {
|
||||||
val str = string.trim { it.isWhitespace() }.toLowerCase()
|
val str = string.trim { it.isWhitespace() }.toLowerCase()
|
||||||
|
if (str == "*") return AnyContact
|
||||||
if (str == "console") return Console
|
if (str == "console") return Console
|
||||||
if (str.isNotEmpty()) {
|
if (str.isNotEmpty()) {
|
||||||
when (str[0]) {
|
when (str[0]) {
|
||||||
|
@ -42,7 +42,7 @@ internal object BuiltInJvmPluginLoaderImpl :
|
|||||||
override val dataStorage: PluginDataStorage
|
override val dataStorage: PluginDataStorage
|
||||||
get() = MiraiConsoleImplementationBridge.dataStorageForJvmPluginLoader
|
get() = MiraiConsoleImplementationBridge.dataStorageForJvmPluginLoader
|
||||||
|
|
||||||
internal val classLoaders: MutableList<ClassLoader> = mutableListOf()
|
internal val classLoaders: MutableList<JvmPluginClassLoader> = mutableListOf()
|
||||||
|
|
||||||
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") // doesn't matter
|
@Suppress("EXTENSION_SHADOWED_BY_MEMBER") // doesn't matter
|
||||||
override fun getPluginDescription(plugin: JvmPlugin): JvmPluginDescription = plugin.description
|
override fun getPluginDescription(plugin: JvmPlugin): JvmPluginDescription = plugin.description
|
||||||
@ -68,7 +68,7 @@ internal object BuiltInJvmPluginLoaderImpl :
|
|||||||
val filePlugins = this.filterNot {
|
val filePlugins = this.filterNot {
|
||||||
pluginFileToInstanceMap.containsKey(it)
|
pluginFileToInstanceMap.containsKey(it)
|
||||||
}.associateWith {
|
}.associateWith {
|
||||||
URLClassLoader(arrayOf(it.toURI().toURL()), MiraiConsole::class.java.classLoader)
|
JvmPluginClassLoader(it, MiraiConsole::class.java.classLoader)
|
||||||
}.onEach { (_, classLoader) ->
|
}.onEach { (_, classLoader) ->
|
||||||
classLoaders.add(classLoader)
|
classLoaders.add(classLoader)
|
||||||
}.asSequence().findAllInstances().onEach {
|
}.asSequence().findAllInstances().onEach {
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* 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<URL> = findResources(name)
|
||||||
|
override fun getResource(name: String?): URL? = findResource(name)
|
||||||
|
// getResourceAsStream 在 URLClassLoader 中通过 getResource 确定资源
|
||||||
|
// 因此无需 override getResourceAsStream
|
||||||
|
}
|
@ -18,7 +18,6 @@ import net.mamoe.mirai.console.extension.PluginComponentStorage
|
|||||||
import net.mamoe.mirai.console.internal.data.mkdir
|
import net.mamoe.mirai.console.internal.data.mkdir
|
||||||
import net.mamoe.mirai.console.permission.Permission
|
import net.mamoe.mirai.console.permission.Permission
|
||||||
import net.mamoe.mirai.console.permission.PermissionService
|
import net.mamoe.mirai.console.permission.PermissionService
|
||||||
import net.mamoe.mirai.console.permission.PermissionService.Companion.allocatePermissionIdForPlugin
|
|
||||||
import net.mamoe.mirai.console.plugin.Plugin
|
import net.mamoe.mirai.console.plugin.Plugin
|
||||||
import net.mamoe.mirai.console.plugin.PluginManager
|
import net.mamoe.mirai.console.plugin.PluginManager
|
||||||
import net.mamoe.mirai.console.plugin.PluginManager.INSTANCE.safeLoader
|
import net.mamoe.mirai.console.plugin.PluginManager.INSTANCE.safeLoader
|
||||||
@ -26,7 +25,6 @@ import net.mamoe.mirai.console.plugin.ResourceContainer.Companion.asResourceCont
|
|||||||
import net.mamoe.mirai.console.plugin.jvm.AbstractJvmPlugin
|
import net.mamoe.mirai.console.plugin.jvm.AbstractJvmPlugin
|
||||||
import net.mamoe.mirai.console.plugin.jvm.JvmPlugin
|
import net.mamoe.mirai.console.plugin.jvm.JvmPlugin
|
||||||
import net.mamoe.mirai.console.plugin.jvm.JvmPlugin.Companion.onLoad
|
import net.mamoe.mirai.console.plugin.jvm.JvmPlugin.Companion.onLoad
|
||||||
import net.mamoe.mirai.console.plugin.name
|
|
||||||
import net.mamoe.mirai.console.util.NamedSupervisorJob
|
import net.mamoe.mirai.console.util.NamedSupervisorJob
|
||||||
import net.mamoe.mirai.utils.MiraiLogger
|
import net.mamoe.mirai.utils.MiraiLogger
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -50,7 +48,7 @@ internal abstract class JvmPluginInternal(
|
|||||||
|
|
||||||
final override val parentPermission: Permission by lazy {
|
final override val parentPermission: Permission by lazy {
|
||||||
PermissionService.INSTANCE.register(
|
PermissionService.INSTANCE.register(
|
||||||
PermissionService.INSTANCE.allocatePermissionIdForPlugin(name, "*"),
|
PermissionService.INSTANCE.allocatePermissionIdForPlugin(this, "*", PermissionService.PluginPermissionIdRequestType.ROOT_PERMISSION),
|
||||||
"The base permission"
|
"The base permission"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,13 @@ public data class PermissionId(
|
|||||||
@ResolveContext(PERMISSION_NAME) public val name: String,
|
@ResolveContext(PERMISSION_NAME) public val name: String,
|
||||||
) {
|
) {
|
||||||
init {
|
init {
|
||||||
|
require(!namespace.contains(' ')) {
|
||||||
|
"' ' is not allowed in namespace"
|
||||||
|
}
|
||||||
|
require(!name.contains(' ')) {
|
||||||
|
"' ' is not allowed in id"
|
||||||
|
}
|
||||||
|
|
||||||
require(!namespace.contains(':')) {
|
require(!namespace.contains(':')) {
|
||||||
"':' is not allowed in namespace"
|
"':' is not allowed in namespace"
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@ import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.COMMAND_NAME
|
|||||||
import net.mamoe.mirai.console.extensions.PermissionServiceProvider
|
import net.mamoe.mirai.console.extensions.PermissionServiceProvider
|
||||||
import net.mamoe.mirai.console.internal.permission.checkType
|
import net.mamoe.mirai.console.internal.permission.checkType
|
||||||
import net.mamoe.mirai.console.permission.Permission.Companion.parentsWithSelf
|
import net.mamoe.mirai.console.permission.Permission.Companion.parentsWithSelf
|
||||||
|
import net.mamoe.mirai.console.plugin.Plugin
|
||||||
|
import net.mamoe.mirai.console.plugin.name
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,6 +91,13 @@ public interface PermissionService<P : Permission> {
|
|||||||
parent: Permission = RootPermission,
|
parent: Permission = RootPermission,
|
||||||
): P
|
): P
|
||||||
|
|
||||||
|
/** 为 [Plugin] 分配一个 [PermissionId] */
|
||||||
|
public fun allocatePermissionIdForPlugin(
|
||||||
|
plugin: Plugin,
|
||||||
|
@ResolveContext(COMMAND_NAME) permissionName: String,
|
||||||
|
reason: PluginPermissionIdRequestType
|
||||||
|
): PermissionId = allocatePermissionIdForPluginDefaultImplement(plugin, permissionName, reason)
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -116,6 +125,15 @@ public interface PermissionService<P : Permission> {
|
|||||||
@Throws(UnsupportedOperationException::class)
|
@Throws(UnsupportedOperationException::class)
|
||||||
public fun cancel(permitteeId: PermitteeId, permission: P, recursive: Boolean)
|
public fun cancel(permitteeId: PermitteeId, permission: P, recursive: Boolean)
|
||||||
|
|
||||||
|
/** [Plugin] 尝试分配的 [PermissionId] 来源 */
|
||||||
|
public enum class PluginPermissionIdRequestType {
|
||||||
|
/** For [Plugin.parentPermission] */
|
||||||
|
ROOT_PERMISSION,
|
||||||
|
|
||||||
|
/** For [Plugin.permissionId] */
|
||||||
|
PERMISSION_ID
|
||||||
|
}
|
||||||
|
|
||||||
public companion object {
|
public companion object {
|
||||||
internal var instanceField: PermissionService<*>? = null
|
internal var instanceField: PermissionService<*>? = null
|
||||||
|
|
||||||
@ -131,8 +149,14 @@ public interface PermissionService<P : Permission> {
|
|||||||
public fun <P : Permission> PermissionService<P>.getOrFail(id: PermissionId): P =
|
public fun <P : Permission> PermissionService<P>.getOrFail(id: PermissionId): P =
|
||||||
get(id) ?: throw NoSuchElementException("Permission not found: $id")
|
get(id) ?: throw NoSuchElementException("Permission not found: $id")
|
||||||
|
|
||||||
internal fun PermissionService<*>.allocatePermissionIdForPlugin(pluginName: String, @ResolveContext(COMMAND_NAME) permissionName: String) =
|
internal fun PermissionService<*>.allocatePermissionIdForPluginDefaultImplement(
|
||||||
PermissionId("plugin.${pluginName.toLowerCase()}", permissionName.toLowerCase())
|
plugin: Plugin,
|
||||||
|
@ResolveContext(COMMAND_NAME) permissionName: String,
|
||||||
|
reason: PluginPermissionIdRequestType
|
||||||
|
) = PermissionId(
|
||||||
|
plugin.name.toLowerCase().replace(' ', '.'),
|
||||||
|
permissionName.toLowerCase()
|
||||||
|
)
|
||||||
|
|
||||||
public fun PermissionId.findCorrespondingPermission(): Permission? = INSTANCE[this]
|
public fun PermissionId.findCorrespondingPermission(): Permission? = INSTANCE[this]
|
||||||
|
|
||||||
@ -202,4 +226,4 @@ public interface PermissionService<P : Permission> {
|
|||||||
return p.testPermission(permissible)
|
return p.testPermission(permissible)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -266,13 +266,13 @@ public sealed class AbstractPermitteeId(
|
|||||||
/**
|
/**
|
||||||
* 表示唯一的一个好友
|
* 表示唯一的一个好友
|
||||||
*
|
*
|
||||||
* - **直接父标识符**: [ExactUser]
|
* - **直接父标识符**: [ExactUser], [AnyFriend]
|
||||||
* - **间接父标识符**: [AnyUser], [AnyContact]
|
* - **间接父标识符**: [AnyUser], [AnyContact]
|
||||||
* - 字符串表示: "f$id"
|
* - 字符串表示: "f$id"
|
||||||
*/
|
*/
|
||||||
public data class ExactFriend(
|
public data class ExactFriend(
|
||||||
public val id: Long,
|
public val id: Long,
|
||||||
) : AbstractPermitteeId(ExactUser(id)) {
|
) : AbstractPermitteeId(ExactUser(id), AnyFriend) {
|
||||||
override fun asString(): String = "f$id"
|
override fun asString(): String = "f$id"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,7 +304,7 @@ public sealed class AbstractPermitteeId(
|
|||||||
* 表示唯一的一个 *在临时会话发送消息的* [群成员][Member]
|
* 表示唯一的一个 *在临时会话发送消息的* [群成员][Member]
|
||||||
*
|
*
|
||||||
* - **直接父标识符**: [ExactMember]
|
* - **直接父标识符**: [ExactMember]
|
||||||
* - **间接父标识符**: [AnyUser], [AnyMember], [ExactUser], [AnyContact]
|
* - **间接父标识符**: [AnyUser], [AnyMember], [ExactUser], [AnyContact], [AnyMemberFromAnyGroup]
|
||||||
* - 字符串表示: "t$groupId.$memberId"
|
* - 字符串表示: "t$groupId.$memberId"
|
||||||
*/
|
*/
|
||||||
public data class ExactTemp(
|
public data class ExactTemp(
|
||||||
|
@ -41,28 +41,24 @@ public interface PluginFileExtensions {
|
|||||||
* 从数据目录获取一个文件.
|
* 从数据目录获取一个文件.
|
||||||
* @see dataFolderPath
|
* @see dataFolderPath
|
||||||
*/
|
*/
|
||||||
@JvmDefault
|
|
||||||
public fun resolveDataFile(relativePath: String): File = dataFolderPath.resolve(relativePath).toFile()
|
public fun resolveDataFile(relativePath: String): File = dataFolderPath.resolve(relativePath).toFile()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从数据目录获取一个文件.
|
* 从数据目录获取一个文件.
|
||||||
* @see dataFolderPath
|
* @see dataFolderPath
|
||||||
*/
|
*/
|
||||||
@JvmDefault
|
|
||||||
public fun resolveDataPath(relativePath: String): Path = dataFolderPath.resolve(relativePath)
|
public fun resolveDataPath(relativePath: String): Path = dataFolderPath.resolve(relativePath)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从数据目录获取一个文件.
|
* 从数据目录获取一个文件.
|
||||||
* @see dataFolderPath
|
* @see dataFolderPath
|
||||||
*/
|
*/
|
||||||
@JvmDefault
|
|
||||||
public fun resolveDataFile(relativePath: Path): File = dataFolderPath.resolve(relativePath).toFile()
|
public fun resolveDataFile(relativePath: Path): File = dataFolderPath.resolve(relativePath).toFile()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从数据目录获取一个文件路径.
|
* 从数据目录获取一个文件路径.
|
||||||
* @see dataFolderPath
|
* @see dataFolderPath
|
||||||
*/
|
*/
|
||||||
@JvmDefault
|
|
||||||
public fun resolveDataPath(relativePath: Path): Path = dataFolderPath.resolve(relativePath)
|
public fun resolveDataPath(relativePath: Path): Path = dataFolderPath.resolve(relativePath)
|
||||||
|
|
||||||
|
|
||||||
@ -83,27 +79,23 @@ public interface PluginFileExtensions {
|
|||||||
* 从配置目录获取一个文件.
|
* 从配置目录获取一个文件.
|
||||||
* @see configFolderPath
|
* @see configFolderPath
|
||||||
*/
|
*/
|
||||||
@JvmDefault
|
|
||||||
public fun resolveConfigFile(relativePath: String): File = configFolderPath.resolve(relativePath).toFile()
|
public fun resolveConfigFile(relativePath: String): File = configFolderPath.resolve(relativePath).toFile()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从配置目录获取一个文件.
|
* 从配置目录获取一个文件.
|
||||||
* @see configFolderPath
|
* @see configFolderPath
|
||||||
*/
|
*/
|
||||||
@JvmDefault
|
|
||||||
public fun resolveConfigPath(relativePath: String): Path = configFolderPath.resolve(relativePath)
|
public fun resolveConfigPath(relativePath: String): Path = configFolderPath.resolve(relativePath)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从配置目录获取一个文件.
|
* 从配置目录获取一个文件.
|
||||||
* @see configFolderPath
|
* @see configFolderPath
|
||||||
*/
|
*/
|
||||||
@JvmDefault
|
|
||||||
public fun resolveConfigFile(relativePath: Path): File = configFolderPath.resolve(relativePath).toFile()
|
public fun resolveConfigFile(relativePath: Path): File = configFolderPath.resolve(relativePath).toFile()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从配置目录获取一个文件路径.
|
* 从配置目录获取一个文件路径.
|
||||||
* @see configFolderPath
|
* @see configFolderPath
|
||||||
*/
|
*/
|
||||||
@JvmDefault
|
|
||||||
public fun resolveConfigPath(relativePath: Path): Path = configFolderPath.resolve(relativePath)
|
public fun resolveConfigPath(relativePath: Path): Path = configFolderPath.resolve(relativePath)
|
||||||
}
|
}
|
@ -37,7 +37,6 @@ public interface ResourceContainer {
|
|||||||
*
|
*
|
||||||
* @return 资源文件内容. 在未找到文件时返回 `null`.
|
* @return 资源文件内容. 在未找到文件时返回 `null`.
|
||||||
*/
|
*/
|
||||||
@JvmDefault
|
|
||||||
public fun getResource(path: String): String? = getResource(path, Charsets.UTF_8)
|
public fun getResource(path: String): String? = getResource(path, Charsets.UTF_8)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,7 +44,6 @@ public interface ResourceContainer {
|
|||||||
*
|
*
|
||||||
* @return 资源文件内容. 在未找到文件时返回 `null`.
|
* @return 资源文件内容. 在未找到文件时返回 `null`.
|
||||||
*/
|
*/
|
||||||
@JvmDefault
|
|
||||||
public fun getResource(path: String, charset: Charset): String? =
|
public fun getResource(path: String, charset: Charset): String? =
|
||||||
this.getResourceAsStream(path)?.use(InputStream::readBytes)?.let(::String)
|
this.getResourceAsStream(path)?.use(InputStream::readBytes)?.let(::String)
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ import net.mamoe.mirai.console.data.PluginConfig
|
|||||||
import net.mamoe.mirai.console.data.PluginData
|
import net.mamoe.mirai.console.data.PluginData
|
||||||
import net.mamoe.mirai.console.internal.plugin.JvmPluginInternal
|
import net.mamoe.mirai.console.internal.plugin.JvmPluginInternal
|
||||||
import net.mamoe.mirai.console.permission.PermissionId
|
import net.mamoe.mirai.console.permission.PermissionId
|
||||||
|
import net.mamoe.mirai.console.permission.PermissionService
|
||||||
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
|
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
|
||||||
import net.mamoe.mirai.utils.minutesToMillis
|
import net.mamoe.mirai.utils.minutesToMillis
|
||||||
import net.mamoe.mirai.utils.secondsToMillis
|
import net.mamoe.mirai.utils.secondsToMillis
|
||||||
@ -37,7 +38,8 @@ public abstract class AbstractJvmPlugin @JvmOverloads constructor(
|
|||||||
|
|
||||||
public final override val loader: JvmPluginLoader get() = super<JvmPluginInternal>.loader
|
public final override val loader: JvmPluginLoader get() = super<JvmPluginInternal>.loader
|
||||||
|
|
||||||
public final override fun permissionId(name: String): PermissionId = PermissionId(description.id, name)
|
public final override fun permissionId(name: String): PermissionId =
|
||||||
|
PermissionService.INSTANCE.allocatePermissionIdForPlugin(this, name, PermissionService.PluginPermissionIdRequestType.PERMISSION_ID)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重载 [PluginData]
|
* 重载 [PluginData]
|
||||||
@ -73,4 +75,4 @@ public inline fun AbstractJvmPlugin.reloadPluginData(instance: PluginData): Unit
|
|||||||
* @see AbstractJvmPlugin.reload
|
* @see AbstractJvmPlugin.reload
|
||||||
*/
|
*/
|
||||||
@JvmSynthetic
|
@JvmSynthetic
|
||||||
public inline fun AbstractJvmPlugin.reloadPluginConfig(instance: PluginConfig): Unit = this.run { instance.reload() }
|
public inline fun AbstractJvmPlugin.reloadPluginConfig(instance: PluginConfig): Unit = this.run { instance.reload() }
|
||||||
|
@ -96,7 +96,7 @@ import kotlin.internal.LowPriorityInOverloadResolution
|
|||||||
*/
|
*/
|
||||||
public interface MessageScope {
|
public interface MessageScope {
|
||||||
/**
|
/**
|
||||||
* 如果此 [MessageScope], 仅包含一个消息对象, 则 [realTarget] 指向这个对象.
|
* 如果此 [MessageScope] 仅包含一个消息对象, 则 [realTarget] 指向这个对象. 否则 [realTarget] 为 `null`.
|
||||||
*
|
*
|
||||||
* 对于 [CommandSender] 作为 [MessageScope], [realTarget] 总是指令执行者 [User], 即 [CommandSender.user]
|
* 对于 [CommandSender] 作为 [MessageScope], [realTarget] 总是指令执行者 [User], 即 [CommandSender.user]
|
||||||
*
|
*
|
||||||
@ -116,7 +116,6 @@ public interface MessageScope {
|
|||||||
/**
|
/**
|
||||||
* 立刻以此发送消息给所有在此 [MessageScope] 下的消息对象
|
* 立刻以此发送消息给所有在此 [MessageScope] 下的消息对象
|
||||||
*/
|
*/
|
||||||
@JvmDefault
|
|
||||||
@JvmBlockingBridge
|
@JvmBlockingBridge
|
||||||
public suspend fun sendMessage(message: String)
|
public suspend fun sendMessage(message: String)
|
||||||
}
|
}
|
||||||
|
@ -36,8 +36,8 @@ class MiraiConsoleBuildPlugin : Plugin<Project> {
|
|||||||
attributes(
|
attributes(
|
||||||
"Manifest-Version" to "1",
|
"Manifest-Version" to "1",
|
||||||
"Implementation-Vendor" to "Mamoe Technologies",
|
"Implementation-Vendor" to "Mamoe Technologies",
|
||||||
"Implementation-Title" to target.name.toString(),
|
"Implementation-Title" to target.name,
|
||||||
"Implementation-Version" to target.version.toString() + "+" + gitVersion
|
"Implementation-Version" to target.version.toString() //+ "+" + gitVersion
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
@ -120,15 +120,16 @@ fun Project.findLatestFile(): Pair<String, File> {
|
|||||||
} ?: error("cannot find any file to upload")*/
|
} ?: error("cannot find any file to upload")*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
val gitVersion: String by lazy {
|
val gitVersion: String by lazy {
|
||||||
runCatching {
|
runCatching {
|
||||||
val exec = Runtime.getRuntime().exec("git rev-parse HEAD")
|
val exec = Runtime.getRuntime().exec("git rev-parse HEAD")
|
||||||
exec.waitFor()
|
exec.waitFor()
|
||||||
exec.inputStream.readBytes().toString(Charsets.UTF_8).trim().also {
|
exec.inputStream.readBytes().toString(Charsets.UTF_8).trim().also {
|
||||||
println("Git commit id: $it")
|
println("Git commit id: $it")
|
||||||
}
|
} }.onFailure {
|
||||||
}.onFailure {
|
|
||||||
it.printStackTrace()
|
it.printStackTrace()
|
||||||
return@lazy "UNKNOWN"
|
return@lazy "UNKNOWN"
|
||||||
}.getOrThrow()
|
}.getOrThrow()
|
||||||
}
|
}
|
||||||
|
*/
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
object Versions {
|
object Versions {
|
||||||
const val core = "1.3.0"
|
const val core = "1.3.0"
|
||||||
const val console = "1.0-RC-dev-29"
|
const val console = "1.0-RC-dev-30"
|
||||||
const val consoleGraphical = "0.0.7"
|
const val consoleGraphical = "0.0.7"
|
||||||
const val consoleTerminal = console
|
const val consoleTerminal = console
|
||||||
|
|
||||||
@ -26,6 +26,6 @@ object Versions {
|
|||||||
|
|
||||||
const val bintray = "1.8.5"
|
const val bintray = "1.8.5"
|
||||||
|
|
||||||
const val blockingBridge = "1.0.5"
|
const val blockingBridge = "1.1.0"
|
||||||
const val yamlkt = "0.5.3"
|
const val yamlkt = "0.5.3"
|
||||||
}
|
}
|
@ -28,6 +28,8 @@ console 由后端和前端一起工作. 使用时必须选择一个前端.
|
|||||||
|
|
||||||
## 配置项目
|
## 配置项目
|
||||||
|
|
||||||
|
请选择以下三种方法之一。
|
||||||
|
|
||||||
### 使用模板项目
|
### 使用模板项目
|
||||||
|
|
||||||
Mirai 鼓励插件开发者将自己的作品开源,并为此提供了模板项目。
|
Mirai 鼓励插件开发者将自己的作品开源,并为此提供了模板项目。
|
||||||
@ -77,4 +79,4 @@ dependencies {
|
|||||||
```
|
```
|
||||||
|
|
||||||
之后还需要配置 Kotlin `jvm-default` 编译参数,Kotlin 和 Java 的编译目标等。
|
之后还需要配置 Kotlin `jvm-default` 编译参数,Kotlin 和 Java 的编译目标等。
|
||||||
在打包插件时必须将依赖一并打包进插件 JAR,且排除 `mirai-core`,`mirai-console` 和它们的间接依赖,否则插件不会被加载。
|
在打包插件时必须将依赖一并打包进插件 JAR,且排除 `mirai-core`,`mirai-console` 和它们的间接依赖,否则插件不会被加载。
|
||||||
|
@ -151,7 +151,9 @@ val terminal: Terminal = run {
|
|||||||
private object ConsoleFrontEndDescImpl : MiraiConsoleFrontEndDescription {
|
private object ConsoleFrontEndDescImpl : MiraiConsoleFrontEndDescription {
|
||||||
override val name: String get() = "Terminal"
|
override val name: String get() = "Terminal"
|
||||||
override val vendor: String get() = "Mamoe Technologies"
|
override val vendor: String get() = "Mamoe Technologies"
|
||||||
override val version: SemVersion = net.mamoe.mirai.console.internal.MiraiConsoleBuildConstants.version
|
// net.mamoe.mirai.console.internal.MiraiConsoleBuildConstants.version
|
||||||
|
// is console's version not frontend's version
|
||||||
|
override val version: SemVersion = SemVersion(net.mamoe.mirai.console.internal.MiraiConsoleBuildConstants.versionConst)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val ANSI_RESET = Ansi().reset().toString()
|
private val ANSI_RESET = Ansi().reset().toString()
|
||||||
|
@ -59,7 +59,8 @@ object MiraiConsoleTerminalLoader {
|
|||||||
@ConsoleTerminalExperimentalApi
|
@ConsoleTerminalExperimentalApi
|
||||||
fun printHelpMessage() {
|
fun printHelpMessage() {
|
||||||
val help = listOf(
|
val help = listOf(
|
||||||
"" to "Mirai-Console[Terminal FrontEnd] v" + kotlin.runCatching {
|
"" to "Mirai-Console[Terminal FrontEnd] v" + net.mamoe.mirai.console.internal.MiraiConsoleBuildConstants.versionConst,
|
||||||
|
"" to " [ BackEnd] v" + kotlin.runCatching {
|
||||||
net.mamoe.mirai.console.internal.MiraiConsoleBuildConstants.version
|
net.mamoe.mirai.console.internal.MiraiConsoleBuildConstants.version
|
||||||
}.getOrElse { "<unknown>" },
|
}.getOrElse { "<unknown>" },
|
||||||
"" to "",
|
"" to "",
|
||||||
@ -171,14 +172,18 @@ internal fun overrideSTD() {
|
|||||||
PrintStream(
|
PrintStream(
|
||||||
BufferedOutputStream(
|
BufferedOutputStream(
|
||||||
logger = DefaultLogger("stdout").run { ({ line: String? -> info(line) }) }
|
logger = DefaultLogger("stdout").run { ({ line: String? -> info(line) }) }
|
||||||
)
|
),
|
||||||
|
false,
|
||||||
|
"UTF-8"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
System.setErr(
|
System.setErr(
|
||||||
PrintStream(
|
PrintStream(
|
||||||
BufferedOutputStream(
|
BufferedOutputStream(
|
||||||
logger = DefaultLogger("stderr").run { ({ line: String? -> warning(line) }) }
|
logger = DefaultLogger("stderr").run { ({ line: String? -> warning(line) }) }
|
||||||
)
|
),
|
||||||
|
false,
|
||||||
|
"UTF-8"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,6 @@
|
|||||||
package net.mamoe.mirai.console.gradle
|
package net.mamoe.mirai.console.gradle
|
||||||
|
|
||||||
internal object VersionConstants {
|
internal object VersionConstants {
|
||||||
const val CONSOLE_VERSION = "1.0-RC-dev-29" // value is written here automatically during build
|
const val CONSOLE_VERSION = "1.0-RC-dev-30" // value is written here automatically during build
|
||||||
const val CORE_VERSION = "1.3.0" // value is written here automatically during build
|
const val CORE_VERSION = "1.3.0" // value is written here automatically during build
|
||||||
}
|
}
|
@ -52,7 +52,7 @@ tasks.withType<org.jetbrains.intellij.tasks.PatchPluginXmlTask> {
|
|||||||
sinceBuild("193.*")
|
sinceBuild("193.*")
|
||||||
untilBuild("205.*")
|
untilBuild("205.*")
|
||||||
pluginDescription("""
|
pluginDescription("""
|
||||||
Plugin development support for <a href='https://github.com/mamoe/mirai-console'>Mirai Conosle</a>
|
Plugin development support for <a href='https://github.com/mamoe/mirai-console'>Mirai Console</a>
|
||||||
|
|
||||||
<h3>Features</h3>
|
<h3>Features</h3>
|
||||||
<ul>
|
<ul>
|
||||||
|
@ -22,7 +22,7 @@ dependencies {
|
|||||||
compileOnly(kotlin("stdlib-jdk8"))
|
compileOnly(kotlin("stdlib-jdk8"))
|
||||||
|
|
||||||
val core = "1.3.0"
|
val core = "1.3.0"
|
||||||
val console = "1.0-RC-dev-4"
|
val console = "1.0-RC-dev-28"
|
||||||
|
|
||||||
compileOnly("net.mamoe:mirai-console:$console")
|
compileOnly("net.mamoe:mirai-console:$console")
|
||||||
compileOnly("net.mamoe:mirai-core:$core")
|
compileOnly("net.mamoe:mirai-core:$core")
|
||||||
|
@ -19,7 +19,6 @@ import net.mamoe.mirai.console.compiler.common.resolve.findParent
|
|||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
|
|
||||||
import org.jetbrains.kotlin.idea.refactoring.fqName.getKotlinFqName
|
import org.jetbrains.kotlin.idea.refactoring.fqName.getKotlinFqName
|
||||||
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
|
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
|
||||||
import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor
|
import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor
|
||||||
@ -98,7 +97,7 @@ fun KtDeclaration.resolveAllCallsWithElement(bindingContext: BindingContext): Se
|
|||||||
.filterIsInstance<KtCallExpression>()
|
.filterIsInstance<KtCallExpression>()
|
||||||
.mapNotNull {
|
.mapNotNull {
|
||||||
val callee = it.calleeExpression ?: return@mapNotNull null
|
val callee = it.calleeExpression ?: return@mapNotNull null
|
||||||
val resolved = callee.getResolvedCallOrResolveToCall(bindingContext) ?: return@mapNotNull null
|
val resolved = callee.getResolvedCall(bindingContext) ?: return@mapNotNull null
|
||||||
|
|
||||||
resolved to it
|
resolved to it
|
||||||
}
|
}
|
||||||
@ -128,7 +127,7 @@ fun KtElement?.getResolvedCallOrResolveToCall(
|
|||||||
context: BindingContext,
|
context: BindingContext,
|
||||||
bodyResolveMode: BodyResolveMode = BodyResolveMode.PARTIAL,
|
bodyResolveMode: BodyResolveMode = BodyResolveMode.PARTIAL,
|
||||||
): ResolvedCall<out CallableDescriptor>? {
|
): ResolvedCall<out CallableDescriptor>? {
|
||||||
return this?.getCall(context)?.getResolvedCall(context) ?: this?.resolveToCall(bodyResolveMode)
|
return this?.getCall(context)?.getResolvedCall(context)// ?: this?.resolveToCall(bodyResolveMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
val ResolvedCall<out CallableDescriptor>.valueParameters: List<ValueParameterDescriptor> get() = this.resultingDescriptor.valueParameters
|
val ResolvedCall<out CallableDescriptor>.valueParameters: List<ValueParameterDescriptor> get() = this.resultingDescriptor.valueParameters
|
||||||
|
Loading…
Reference in New Issue
Block a user