diff --git a/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt b/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt index 26a2ad896..cb0d1fffc 100644 --- a/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt +++ b/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt @@ -10,19 +10,17 @@ package net.mamoe.mirai.console */ import kotlinx.coroutines.runBlocking +import net.mamoe.mirai.Bot +import net.mamoe.mirai.alsoLogin import net.mamoe.mirai.api.http.MiraiHttpAPIServer import net.mamoe.mirai.api.http.generateSessionKey -import net.mamoe.mirai.contact.sendMessage import net.mamoe.mirai.console.plugins.PluginManager import net.mamoe.mirai.console.plugins.loadAsConfig import net.mamoe.mirai.console.plugins.withDefaultWrite import net.mamoe.mirai.console.plugins.withDefaultWriteSave -import net.mamoe.mirai.Bot -import net.mamoe.mirai.alsoLogin +import net.mamoe.mirai.contact.sendMessage import net.mamoe.mirai.utils.SimpleLogger -import org.bouncycastle.jce.provider.BouncyCastleProvider import java.io.File -import java.security.Security import java.util.* import java.util.concurrent.LinkedBlockingQueue import kotlin.concurrent.thread @@ -307,10 +305,6 @@ class MiraiConsoleLoader { companion object { @JvmStatic fun main(args: Array) { - Security.removeProvider("BC") - Security.addProvider(BouncyCastleProvider()) - Security.addProvider(org.bouncycastle.jce.provider.BouncyCastleProvider()) - //Security.addProvider(BouncyCastle) MiraiConsoleUI.start() MiraiConsole.start() Runtime.getRuntime().addShutdownHook(thread(start = false) { diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt index bc4a87a1b..fa748655b 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt @@ -12,6 +12,8 @@ package net.mamoe.mirai.event import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.channels.ReceiveChannel import net.mamoe.mirai.Bot import net.mamoe.mirai.contact.isAdministrator import net.mamoe.mirai.contact.isOperator @@ -125,6 +127,17 @@ inline fun Bot.subscribeFriendMessages(crossinline listeners: MessageSubscri }.run(listeners) } +/** + * 返回一个指定事件的接收通道 + */ +inline fun Bot.incoming(): ReceiveChannel { + return Channel(8).apply { + subscribeAlways { + send(this) + } + } +} + /** * 消息事件的处理器. diff --git a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/cryptor/ECDHJvm.kt b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/cryptor/ECDHJvm.kt index b0abdf991..0d6e93829 100644 --- a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/cryptor/ECDHJvm.kt +++ b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/cryptor/ECDHJvm.kt @@ -43,13 +43,12 @@ actual fun ECDH() = ECDH(ECDH.generateKeyPair()) actual class ECDH actual constructor(actual val keyPair: ECDHKeyPair) { actual companion object { private var isECDHAvailable = true + init { - if (kotlin.runCatching { - Security.addProvider(BouncyCastleProvider()) - generateKeyPair() // try if it is working - }.exceptionOrNull() == null) { - isECDHAvailable = true - } + isECDHAvailable = kotlin.runCatching { + Security.addProvider(BouncyCastleProvider()) + generateKeyPair() // try if it is working + }.isSuccess } actual fun generateKeyPair(): ECDHKeyPair {