abstract class Bot : CoroutineScope, LowLevelBotAPIAccessor, BotJavaFriendlyAPI, ContactOrBot
机器人对象. 一个机器人实例登录一个 QQ 账号. Mirai 为多账号设计, 可同时维护多个机器人.
注: Bot 为全协程实现, 没有其他任务时若不使用 join, 主线程将会退出.
See Also
<init> |
机器人对象. 一个机器人实例登录一个 QQ 账号. Mirai 为多账号设计, 可同时维护多个机器人. Bot() |
context |
abstract val context: Context |
friends |
机器人的好友列表. 与服务器同步更新 abstract val friends: ContactList<Friend> |
groups |
机器人加入的群列表. 与服务器同步更新 abstract val groups: ContactList<Group> |
id |
QQ 号码. 实际类型为 uint abstract val id: Long |
logger |
日志记录器 abstract val logger: MiraiLogger |
network |
网络模块. 此为内部 API: 它可能在任意时刻被改动. abstract val network: BotNetworkHandler |
nick |
昵称 abstract val nick: String |
selfQQ |
QQ.id 与 Bot.uin 相同的 _lowLevelNewFriend 实例 abstract val selfQQ: Friend |
selfQQDeprecated |
val |
uin |
abstract val |
acceptInvitedJoinGroupRequest |
接收邀请入群(需管理员权限) abstract suspend fun acceptInvitedJoinGroupRequest(event: BotInvitedJoinGroupRequestEvent): Unit |
acceptMemberJoinRequest |
通过加群验证(需管理员权限) abstract suspend fun acceptMemberJoinRequest(event: MemberJoinRequestEvent): Unit |
acceptNewFriendRequest |
通过好友验证 abstract suspend fun acceptNewFriendRequest(event: NewFriendRequestEvent): Unit |
addFriend |
添加一个好友 abstract suspend fun addFriend(id: Long, message: String? = null, remark: String? = null): AddFriendResult |
close |
关闭这个 Bot, 立即取消 Bot 的 kotlinx.coroutines.SupervisorJob.
之后 kotlinx.coroutines.isActive 将会返回 abstract fun close(cause: Throwable? = null): Unit |
constructMessageSource |
构造一个 OfflineMessageSource abstract fun constructMessageSource(kind: Kind, fromUin: Long, targetUin: Long, id: Int, time: Int, internalId: Int, originalMessage: MessageChain): OfflineMessageSource |
getFriend |
获取一个好友对象. fun getFriend(id: Long): Friend |
getFriendDeprecated |
fun |
getGroup |
获取一个机器人加入的群. fun getGroup(id: Long): Group |
ignoreInvitedJoinGroupRequest |
忽略邀请入群(需管理员权限) abstract suspend fun ignoreInvitedJoinGroupRequest(event: BotInvitedJoinGroupRequestEvent): Unit |
ignoreMemberJoinRequest |
忽略加群验证(需管理员权限) abstract suspend fun ignoreMemberJoinRequest(event: MemberJoinRequestEvent, blackList: Boolean = false): Unit |
login |
登录, 或重新登录. 这个函数总是关闭一切现有网路任务 (但不会关闭其他任务), 然后重新登录并重新缓存好友列表和群列表. abstract suspend fun login(): Unit |
openChannel |
获取图片下载链接并开始下载. abstract suspend fun |
queryImageUrl |
获取图片下载链接 abstract suspend fun queryImageUrl(image: Image): String |
recall |
撤回这条消息. 可撤回自己 2 分钟内发出的消息, 和任意时间的群成员的消息. abstract suspend fun recall(source: MessageSource): Unit |
rejectMemberJoinRequest |
拒绝加群验证(需管理员权限) abstract suspend fun rejectMemberJoinRequest(event: MemberJoinRequestEvent, blackList: Boolean = false): Unit |
rejectNewFriendRequest |
拒绝好友验证 abstract suspend fun rejectNewFriendRequest(event: NewFriendRequestEvent, blackList: Boolean = false): Unit |
toString |
fun toString(): String |
botInstances |
复制一份此时的 Bot 实例列表. val botInstances: List<Bot> |
instances |
复制一份此时的 Bot 实例列表. val |
forEachInstance |
遍历每一个 Bot 实例 fun forEachInstance(block: (Bot) -> Unit): Unit |
getInstance |
获取一个 Bot 实例, 找不到则 NoSuchElementException fun getInstance(qq: Long): Bot |
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? |
incoming |
打开一个来自指定 Bot 的指定事件的接收通道 fun <E : BotEvent> Bot.incoming(coroutineContext: CoroutineContext = EmptyCoroutineContext, concurrencyKind: ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT, capacity: Int = Channel.UNLIMITED): ReceiveChannel<E> |
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 |
在 Bot 的 CoroutineScope 下订阅所有 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 |
在 Bot 的 CoroutineScope 下订阅所有 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 |
在 Bot 的 CoroutineScope 下订阅所有 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 |
BotImpl |
abstract class BotImpl<N : BotNetworkHandler> : Bot, CoroutineScope |