mirai-core / net.mamoe.mirai.event

Package net.mamoe.mirai.event

Types

AbstractCancellableEvent

可被取消的事件的实现

abstract class AbstractCancellableEvent : Event, CancellableEvent

BroadcastControllable

可控制是否需要广播这个事件包

interface BroadcastControllable : Event

CancellableEvent

可被取消的事件

interface CancellableEvent

Event

可被监听的类, 可以是任何 class 或 object.

interface Event

FriendMessageSubscribersBuilder

typealias FriendMessageSubscribersBuilder = MessageSubscribersBuilder<FriendMessage, Listener<FriendMessage>, Unit, Unit>

GroupMessageSubscribersBuilder

typealias GroupMessageSubscribersBuilder = MessageSubscribersBuilder<GroupMessage, Listener<GroupMessage>, Unit, Unit>

Listener

事件监听器. 由 subscribe 等方法返回.

interface Listener<in E : Event> : CompletableJob

ListeningStatus

订阅者的状态

enum class ListeningStatus

MessageListener

消息事件的处理器.

typealias MessageListener<T, R> = suspend T.(String) -> R

MessagePacketSubscribersBuilder

typealias MessagePacketSubscribersBuilder = MessageSubscribersBuilder<ContactMessage, Listener<ContactMessage>, Unit, Unit>

MessageSelectBuilder

selectMessages 时的 DSL 构建器.

abstract class MessageSelectBuilder<M : ContactMessage, R> : MessageSelectBuilderUnit<M, R>

MessageSelectBuilderUnit

selectMessagesUnitselectMessages 时的 DSL 构建器.

abstract class MessageSelectBuilderUnit<M : ContactMessage, R> : MessageSubscribersBuilder<M, Unit, R, Any?>

MessageSelectionTimeoutChecker

class MessageSelectionTimeoutChecker

MessageSubscribersBuilder

消息订阅构造器

open class MessageSubscribersBuilder<M : ContactMessage, out Ret, R : RR, RR>

TempMessageSubscribersBuilder

typealias TempMessageSubscribersBuilder = MessageSubscribersBuilder<TempMessage, Listener<TempMessage>, Unit, Unit>

Annotations

MessageDsl

DSL 标记. 将能让 IDE 阻止一些错误的方法调用.

annotation class MessageDsl

Exceptions

MessageSelectionTimeoutException

class MessageSelectionTimeoutException : RuntimeException

Extensions for External Classes

kotlinx.coroutines.CoroutineScope

Properties

EventDisabled

设置为 true 以关闭事件. 所有的 subscribe 都能正常添加到监听器列表, 但所有的广播都会直接返回.

var EventDisabled: Boolean

Functions

broadcast

广播一个事件的唯一途径.

suspend fun <E : Event> E.broadcast(): E

incoming

打开一个来自指定 Bot 的指定事件的接收通道

fun <E : BotEvent> Bot.incoming(coroutineContext: CoroutineContext = EmptyCoroutineContext, concurrencyKind: ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT, capacity: Int = Channel.UNLIMITED): ReceiveChannel<E>

selectMessages

挂起当前协程, 等待任意一个事件监听器触发后返回其返回值.

suspend fun <T : ContactMessage, R> T.selectMessages(timeoutMillis: Long = -1, filterContext: Boolean = true, selectBuilder: MessageSelectBuilder<T, R>.() -> Unit): R

selectMessagesUnit

selectMessagesUnit 返回值捷径 (由于 Kotlin 无法推断 Unit 类型)

suspend fun <T : ContactMessage> T.selectMessagesUnit(timeoutMillis: Long = -1, filterContext: Boolean = true, selectBuilder: MessageSelectBuilderUnit<T, Unit>.() -> Unit): Unit

subscribe

BotCoroutineScope 下订阅所有 E 及其子类事件. 每当 事件广播 时, handler 都会被执行, 当 handler 返回 ListeningStatus.STOPPED 时停止监听

fun <E : BotEvent> Bot.subscribe(coroutineContext: CoroutineContext = EmptyCoroutineContext, concurrency: ConcurrencyKind = Listener.ConcurrencyKind.LOCKED, handler: suspend E.(E) -> ListeningStatus): Listener<E>fun <E : BotEvent> Bot.subscribe(eventClass: KClass<E>, coroutineContext: CoroutineContext = EmptyCoroutineContext, concurrency: ConcurrencyKind = Listener.ConcurrencyKind.LOCKED, handler: suspend E.(E) -> ListeningStatus): Listener<E>

subscribeAlways

BotCoroutineScope 下订阅所有 E 及其子类事件. 每当 事件广播 时, listener 都会被执行.

fun <E : BotEvent> Bot.subscribeAlways(coroutineContext: CoroutineContext = EmptyCoroutineContext, concurrency: ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT, listener: suspend E.(E) -> Unit): Listener<E>fun <E : BotEvent> Bot.subscribeAlways(eventClass: KClass<E>, coroutineContext: CoroutineContext = EmptyCoroutineContext, concurrency: ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT, listener: suspend E.(E) -> Unit): Listener<E>

subscribeFriendMessages

订阅来自这个 Bot 的所有好友消息事件.

fun <R> Bot.subscribeFriendMessages(coroutineContext: CoroutineContext = EmptyCoroutineContext, concurrencyKind: ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT, listeners: FriendMessageSubscribersBuilder.() -> R): R

subscribeGroupMessages

订阅来自这个 Bot 的所有群消息事件

fun <R> Bot.subscribeGroupMessages(coroutineContext: CoroutineContext = EmptyCoroutineContext, concurrencyKind: ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT, listeners: GroupMessageSubscribersBuilder.() -> R): R

subscribeMessages

订阅来自这个 Bot 的所有联系人的消息事件. 联系人可以是任意群或任意好友或临时会话.

fun <R> Bot.subscribeMessages(coroutineContext: CoroutineContext = EmptyCoroutineContext, concurrencyKind: ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT, listeners: MessagePacketSubscribersBuilder.() -> R): R

subscribeOnce

BotCoroutineScope 下订阅所有 E 及其子类事件. 仅在第一次 事件广播 时, listener 会被执行.

fun <E : BotEvent> Bot.subscribeOnce(coroutineContext: CoroutineContext = EmptyCoroutineContext, listener: suspend E.(E) -> Unit): Listener<E>fun <E : BotEvent> Bot.subscribeOnce(eventClass: KClass<E>, coroutineContext: CoroutineContext = EmptyCoroutineContext, listener: suspend E.(E) -> Unit): Listener<E>

subscribeTempMessages

订阅来自这个 Bot 的所有临时会话消息事件.

fun <R> Bot.subscribeTempMessages(coroutineContext: CoroutineContext = EmptyCoroutineContext, concurrencyKind: ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT, listeners: TempMessageSubscribersBuilder.() -> R): R

syncFromEvent

挂起当前协程, 监听事件 E, 并尝试从这个事件中同步一个值, 在超时时抛出 TimeoutCancellationException

suspend fun <E : Event, R : Any> syncFromEvent(timeoutMillis: Long = -1, mapper: suspend E.(E) -> R?): R

syncFromEventOrNull

挂起当前协程, 监听这个事件, 并尝试从这个事件中获取一个值, 在超时时返回 null

suspend fun <E : Event, R : Any> syncFromEventOrNull(timeoutMillis: Long, mapper: suspend E.(E) -> R?): R?

whileSelectMessages

挂起当前协程, 等待任意一个事件监听器返回 false 后返回.

suspend fun <T : ContactMessage> T.whileSelectMessages(timeoutMillis: Long = -1, filterContext: Boolean = true, selectBuilder: MessageSelectBuilder<T, Boolean>.() -> Unit): Unit