mirai-core / net.mamoe.mirai / BotImpl

BotImpl

abstract class BotImpl<N : BotNetworkHandler> : Bot, CoroutineScope

Constructors

<init>

BotImpl(context: Context, configuration: BotConfiguration)

Properties

configuration

val configuration: BotConfiguration

context

Bot 运行的 Context.

open val context: Context

coroutineContext

val coroutineContext: CoroutineContext

logger

日志记录器

val logger: MiraiLogger

network

网络模块. 此为内部 API: 它可能在任意时刻被改动.

val network: N

uin

open val uin: Long

Functions

close

关闭这个 Bot, 立即取消 Botkotlinx.coroutines.SupervisorJob. 之后 kotlinx.coroutines.isActive 将会返回 false.

open fun close(cause: Throwable?): Unit

createNetworkHandler

abstract fun createNetworkHandler(coroutineContext: CoroutineContext): N

login

Exposed public API BotImpl.relogin && BotNetworkHandler.init

suspend fun login(): Unit

relogin

Close server connection, resend login packet, BUT DOESN'T BotNetworkHandler.init

abstract suspend fun relogin(cause: Throwable?): Unit

Companion Object Functions

forEachInstance

fun forEachInstance(block: (Bot) -> Unit): Unit

getInstance

fun getInstance(qq: Long): Bot

Extension Functions

alsoLogin

登录, 返回 this

suspend fun <B : Bot> B.alsoLogin(): B

buildMessageSource

构建一个 OfflineMessageSource

fun Bot.buildMessageSource(block: MessageSourceBuilder.() -> Unit): MessageSource

closeAndJoin

关闭这个 Bot, 停止一切相关活动. 所有引用都会被释放.

suspend fun Bot.closeAndJoin(cause: Throwable? = null): Unit

containsFriend

fun Bot.containsFriend(id: Long): Boolean

containsGroup

fun Bot.containsGroup(id: Long): Boolean

getFriendOrNull

fun Bot.getFriendOrNull(id: Long): Friend?

getGroupOrNull

fun Bot.getGroupOrNull(id: Long): Group?

join

挂起协程直到 Bot 下线.

suspend fun Bot.join(): Unit

recall

撤回这条消息.

suspend fun Bot.recall(message: MessageChain): Unit

recallIn

在一段时间后撤回这个消息源所指代的消息.

fun Bot.recallIn(source: MessageSource, millis: Long, coroutineContext: CoroutineContext = EmptyCoroutineContext): Job

在一段时间后撤回这条消息.

fun Bot.recallIn(message: MessageChain, millis: Long, coroutineContext: CoroutineContext = EmptyCoroutineContext): Job

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