Package net.mamoe.mirai.event

Types

Link copied to clipboard
abstract class AbstractEvent : Event

所有实现了 Event 接口的类都应该继承的父类.

Link copied to clipboard
interface BroadcastControllable : Event

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

Link copied to clipboard
interface CancellableEvent : Event

可被取消的事件

Link copied to clipboard
abstract class CommonMessageSelectBuilderUnit<M : MessageEvent, R> : MessageSubscribersBuilder<M, Unit, R, Any?>

MessageSelectBuilderUnit 的跨平台实现

Link copied to clipboard
enum ConcurrencyKind : Enum<ConcurrencyKind>
Link copied to clipboard
interface Event

表示一个事件.

Link copied to clipboard
expect abstract class EventChannel<out BaseEvent : Event> @MiraiInternalApi constructor(baseEventClass: KClass<out BaseEvent>, defaultCoroutineContext: CoroutineContext)

事件通道.

actual abstract class EventChannel<out BaseEvent : Event> @MiraiInternalApi constructor(val baseEventClass: KClass<out BaseEvent>, val defaultCoroutineContext: CoroutineContext)

事件通道.

actual abstract class EventChannel<out BaseEvent : Event> @MiraiInternalApi constructor(val baseEventClass: KClass<out BaseEvent>, val defaultCoroutineContext: CoroutineContext)

事件通道.

Link copied to clipboard
@Target(allowedTargets = [AnnotationTarget.FUNCTION])
annotation class EventHandler(    val priority: EventPriority = EventPriority.NORMAL,     val ignoreCancelled: Boolean = true,     val concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT)

标注一个函数为事件监听器.

Link copied to clipboard
enum EventPriority : Enum<EventPriority>

事件优先级.

Link copied to clipboard
class ExceptionInEventChannelFilterException(    val event: Event,     val eventChannel: EventChannel<*>,     val message: String = "Exception in EventHandler",     val cause: Throwable) : IllegalStateException

包装 EventChannel.filterfilter lambda 抛出的异常并重新抛出.

Link copied to clipboard
class ExceptionInEventHandlerException(    val event: Event,     val message: String = "Exception in EventHandler",     val cause: Throwable) : IllegalStateException

EventHandler 标记的函数在处理事件时产生异常时包装异常并重新抛出

Link copied to clipboard
object GlobalEventChannel : EventChannel<Event>

全局事件通道. 此通道包含来自所有 Bot 的所有类型的事件. 可通过 EventChannel.filter 过滤得到范围更小的 EventChannel.

Link copied to clipboard
interface InternalGlobalEventChannelProvider
Link copied to clipboard
interface Listener<in E : Event> : CompletableJob

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

Link copied to clipboard
interface ListenerHost

实现这个接口的对象可以通过 EventHandler 标注事件监听函数, 并通过 registerTo 注册.

Link copied to clipboard
enum ListeningStatus : Enum<ListeningStatus>

订阅者的状态

Link copied to clipboard
annotation class MessageDsl

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

Link copied to clipboard
Link copied to clipboard
typealias MessageListener<T, R> = suspend T.(String) -> R

消息事件的处理器.

注: 接受者 T 为 MessageEvent 参数 String 为 转为字符串了的消息 (Message.toString)

Link copied to clipboard
abstract class MessageSelectBuilder<M : MessageEvent, R> : MessageSelectBuilderUnit<M, R>

selectMessages 时的 DSL 构建器.

Link copied to clipboard
expect abstract class MessageSelectBuilderUnit<M : MessageEvent, R> : CommonMessageSelectBuilderUnit<M, R>

selectMessagesUnitselectMessages 时的 DSL 构建器.

actual abstract class MessageSelectBuilderUnit<M : MessageEvent, R> : CommonMessageSelectBuilderUnit<M, R>

selectMessagesUnitselectMessages 时的 DSL 构建器.

actual abstract class MessageSelectBuilderUnit<M : MessageEvent, R> : CommonMessageSelectBuilderUnit<M, R>

selectMessagesUnitselectMessages 时的 DSL 构建器.

Link copied to clipboard
value class MessageSelectionTimeoutChecker
Link copied to clipboard
class MessageSelectionTimeoutException : RuntimeException
Link copied to clipboard
open class MessageSubscribersBuilder<M : MessageEvent, out Ret, R : RR, RR>

消息订阅构造器

Link copied to clipboard
abstract class SimpleListenerHost @JvmOverloads constructor(coroutineContext: CoroutineContext = EmptyCoroutineContext) : ListenerHost

携带一个异常处理器的 ListenerHost.

Functions

Link copied to clipboard
suspend fun <E : Event> E.broadcast(): E

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

Link copied to clipboard
fun CoroutineScope.globalEventChannel(coroutineContext: CoroutineContext = EmptyCoroutineContext): EventChannel<Event>

在此 CoroutineScope 下创建一个监听所有事件的 EventChannel. 相当于 GlobalEventChannel.parentScope(this).context(coroutineContext).

Link copied to clipboard
inline suspend fun <E : Event> EventChannel<*>.nextEvent(priority: EventPriority = EventPriority.NORMAL, noinline filter: suspend (E) -> Boolean = { true }): E
inline suspend fun <E : Event> EventChannel<*>.nextEvent(    priority: EventPriority = EventPriority.NORMAL,     intercept: Boolean = false,     noinline filter: suspend (E) -> Boolean = { true }): E

挂起当前协程, 直到监听到事件 E 的广播并通过 filter, 返回这个事件实例.

Link copied to clipboard
inline fun <T : ListenerHost> T.registerTo(eventChannel: EventChannel<*>)

反射得到所有标注了 EventHandler 的函数 (Java 为方法), 并注册为事件监听器

Link copied to clipboard
inline suspend fun <T : MessageEvent, R> T.selectMessages(    timeoutMillis: Long = -1,     filterContext: Boolean = true,     priority: EventPriority = EventPriority.MONITOR,     crossinline selectBuilder: MessageSelectBuilder<T, R>.() -> Unit): R

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

Link copied to clipboard
@JvmName(name = "selectMessages1")
inline suspend fun <T : MessageEvent> T.selectMessagesUnit(    timeoutMillis: Long = -1,     filterContext: Boolean = true,     priority: EventPriority = EventPriority.MONITOR,     crossinline selectBuilder: MessageSelectBuilderUnit<T, Unit>.() -> Unit)

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

Link copied to clipboard
inline fun <BaseEvent : Event, E : Event> EventChannel<BaseEvent>.subscribe(    crossinline handler: (E) -> ListeningStatus,     priority: EventPriority = EventPriority.NORMAL,     concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT,     coroutineContext: CoroutineContext = EmptyCoroutineContext): Listener<E>
inline fun <BaseEvent : Event, E : Event> EventChannel<BaseEvent>.subscribe(    crossinline handler: suspend E.(E) -> ListeningStatus,     priority: EventPriority = EventPriority.NORMAL,     concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT,     coroutineContext: CoroutineContext = EmptyCoroutineContext): Listener<E>

支持 Kotlin 带接收者的挂起函数的函数引用的监听方式.

inline fun <BaseEvent : Event, E : Event> EventChannel<BaseEvent>.subscribe(    crossinline handler: E.(E) -> ListeningStatus,     priority: EventPriority = EventPriority.NORMAL,     concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT,     coroutineContext: CoroutineContext = EmptyCoroutineContext): Listener<E>

支持 Kotlin 带接收者的函数的函数引用的监听方式.

@JvmName(name = "subscribe1")
inline fun <BaseEvent : Event, E : Event> EventChannel<BaseEvent>.subscribe(    crossinline handler: suspend (E) -> ListeningStatus,     priority: EventPriority = EventPriority.NORMAL,     concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT,     coroutineContext: CoroutineContext = EmptyCoroutineContext): Listener<E>

支持 Kotlin 挂起函数的函数引用的监听方式.

Link copied to clipboard
inline fun <BaseEvent : Event, E : Event> EventChannel<BaseEvent>.subscribeAlways(    crossinline handler: (E) -> Unit,     priority: EventPriority = EventPriority.NORMAL,     concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT,     coroutineContext: CoroutineContext = EmptyCoroutineContext): Listener<E>
inline fun <BaseEvent : Event, E : Event> EventChannel<BaseEvent>.subscribeAlways(    crossinline handler: suspend E.(E) -> Unit,     priority: EventPriority = EventPriority.NORMAL,     concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT,     coroutineContext: CoroutineContext = EmptyCoroutineContext): Listener<E>

支持 Kotlin 带接收者的挂起函数的函数引用的监听方式.

inline fun <BaseEvent : Event, E : Event> EventChannel<BaseEvent>.subscribeAlways(    crossinline handler: E.(E) -> Unit,     priority: EventPriority = EventPriority.NORMAL,     concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT,     coroutineContext: CoroutineContext = EmptyCoroutineContext): Listener<E>

支持 Kotlin 带接收者的函数的函数引用的监听方式.

@JvmName(name = "subscribeAlways1")
inline fun <BaseEvent : Event, E : Event> EventChannel<BaseEvent>.subscribeAlways(    crossinline handler: suspend (E) -> Unit,     priority: EventPriority = EventPriority.NORMAL,     concurrency: ConcurrencyKind = ConcurrencyKind.CONCURRENT,     coroutineContext: CoroutineContext = EmptyCoroutineContext): Listener<E>

支持 Kotlin 挂起函数的函数引用的监听方式.

Link copied to clipboard
fun <R> EventChannel<*>.subscribeFriendMessages(    coroutineContext: CoroutineContext = EmptyCoroutineContext,     concurrencyKind: ConcurrencyKind = CONCURRENT,     priority: EventPriority = EventPriority.MONITOR,     listeners: FriendMessageSubscribersBuilder.() -> R): R

通过 DSL 订阅来自所有 Bot 的所有好友消息事件. DSL 语法查看 subscribeMessages.

Link copied to clipboard
fun <R> EventChannel<*>.subscribeGroupMessages(    coroutineContext: CoroutineContext = EmptyCoroutineContext,     concurrencyKind: ConcurrencyKind = CONCURRENT,     priority: EventPriority = EventPriority.MONITOR,     listeners: GroupMessageSubscribersBuilder.() -> R): R

通过 DSL 订阅来自所有 Bot 的所有群会话消息事件. DSL 语法查看 subscribeMessages.

Link copied to clipboard
fun <R> EventChannel<*>.subscribeGroupTempMessages(    coroutineContext: CoroutineContext = EmptyCoroutineContext,     concurrencyKind: ConcurrencyKind = CONCURRENT,     priority: EventPriority = EventPriority.MONITOR,     listeners: GroupTempMessageSubscribersBuilder.() -> R): R

通过 DSL 订阅来自所有 Bot 的所有 GroupTempMessageEvent. DSL 语法查看 subscribeMessages.

Link copied to clipboard
fun <R> EventChannel<*>.subscribeMessages(    coroutineContext: CoroutineContext = EmptyCoroutineContext,     concurrencyKind: ConcurrencyKind = CONCURRENT,     priority: EventPriority = EventPriority.MONITOR,     listeners: MessageEventSubscribersBuilder.() -> R): R

通过 DSL 订阅来自所有 Bot 的所有联系人的消息事件.

Link copied to clipboard
fun <R> EventChannel<*>.subscribeOtherClientMessages(    coroutineContext: CoroutineContext = EmptyCoroutineContext,     concurrencyKind: ConcurrencyKind = CONCURRENT,     priority: EventPriority = EventPriority.MONITOR,     listeners: OtherClientMessageSubscribersBuilder.() -> R): R

通过 DSL 订阅来自所有 Bot 的所有 OtherClient 消息事件. DSL 语法查看 subscribeMessages.

Link copied to clipboard
fun <R> EventChannel<*>.subscribeStrangerMessages(    coroutineContext: CoroutineContext = EmptyCoroutineContext,     concurrencyKind: ConcurrencyKind = CONCURRENT,     priority: EventPriority = EventPriority.MONITOR,     listeners: StrangerMessageSubscribersBuilder.() -> R): R

通过 DSL 订阅来自所有 Bot 的所有 Stranger 消息事件. DSL 语法查看 subscribeMessages.

Link copied to clipboard
fun <R> EventChannel<*>.subscribeUserMessages(    coroutineContext: CoroutineContext = EmptyCoroutineContext,     concurrencyKind: ConcurrencyKind = CONCURRENT,     priority: EventPriority = EventPriority.MONITOR,     listeners: UserMessageSubscribersBuilder.() -> R): R

通过 DSL 订阅来自所有 Bot 的所 User 消息事件. DSL 语法查看 subscribeMessages.

Link copied to clipboard
inline suspend fun <E : Event, R : Any> EventChannel<*>.syncFromEvent(priority: EventPriority = EventPriority.NORMAL, noinline mapper: suspend (E) -> R?): R

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

Link copied to clipboard
inline suspend fun <T : MessageEvent> T.whileSelectMessages(    timeoutMillis: Long = -1,     filterContext: Boolean = true,     priority: EventPriority = EventPriority.MONITOR,     crossinline selectBuilder: MessageSelectBuilder<T, Boolean>.() -> Unit)

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