From cebdd40e76bed5c2b93453adb5853ce4829139f0 Mon Sep 17 00:00:00 2001 From: HoshinoTented Date: Sun, 16 Feb 2020 00:59:56 +0800 Subject: [PATCH] add incoming channel --- .../net.mamoe.mirai/event/MessageSubscribers.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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) + } + } +} + /** * 消息事件的处理器.