IMirai

Mirai API 接口. 是 Mirai API 与 Mirai 协议实现对接的接口.

获取实例

通常在引用 net.mamoe:mirai-core 模块后就可以通过 Mirai 获取到 IMirai 实例. 在 Kotlin 调用顶层定义 Mirai, 在 Java 调用 Mirai.getInstance().

使用 IMirai 的接口

IMirai 中的接口通常是稳定

手动提供实例

默认通过 _MiraiInstance.get 使用 java.util.ServiceLoader 寻找实例. 若某些环境下 java.util.ServiceLoader 不可用, 可在 Kotlin 手动设置实例:

@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") // 必要
net.mamoe.mirai._MiraiInstance.set(net.mamoe.mirai.internal.MiraiImpl())

但通常都可用自动获取而不需要手动设置.

稳定性

使用稳定

所有接口默认是可以稳定使用的. 但 LowLevelApiAccessor 中的方法默认是非常不稳定的.

继承不稳定

IMirai 可能会增加新的抽象属性或函数. 因此不适合被继承或实现.

See also

获取实例

Functions

Link copied to clipboard

接收邀请入群(需管理员权限)

Link copied to clipboard
abstract suspend fun acceptMemberJoinRequest(event: MemberJoinRequestEvent)

通过加群验证(需管理员权限)

Link copied to clipboard
abstract suspend fun acceptNewFriendRequest(event: NewFriendRequestEvent)

通过好友验证

Link copied to clipboard
abstract suspend fun broadcastEvent(event: Event)

广播一个事件. 由 Event.broadcast 调用.

Link copied to clipboard

使用 DSL 构建一个 OfflineMessageSource. 用法参考 MessageSourceBuilder.

Link copied to clipboard

使用 groupUin 计算 groupCode. 这两个值仅在 mirai 内部协议区分, 一般人使用时无需在意.

Link copied to clipboard
open fun calculateGroupUinByGroupCode(groupCode: Long): Long

使用 groupCode 计算 groupUin. 这两个值仅在 mirai 内部协议区分, 一般人使用时无需在意.

Link copied to clipboard
abstract fun constructMessageSource(botId: Long, kind: MessageSourceKind, fromId: Long, targetId: Long, ids: IntArray, time: Int, internalIds: IntArray, originalMessage: MessageChain): OfflineMessageSource

构造一个 OfflineMessageSource.

Link copied to clipboard
abstract fun createFileMessage(id: String, internalId: Int, name: String, size: Long): FileMessage

创建一个 FileMessage. namesize 只供本地使用, 发送消息时只会使用 idinternalId.

Link copied to clipboard
open fun createImage(imageId: String): Image

构造 Image. 请优先使用 Image.Factory.create.

Link copied to clipboard
abstract suspend fun downloadForwardMessage(bot: Bot, resourceId: String): List<ForwardMessage.Node>
Link copied to clipboard
abstract suspend fun downloadLongMessage(bot: Bot, resourceId: String): MessageChain
Link copied to clipboard
abstract suspend fun getGroupVoiceDownloadUrl(bot: Bot, md5: ByteArray, groupId: Long, dstUin: Long): String

查询语音的下载连接

Link copied to clipboard
abstract suspend fun getOnlineOtherClientsList(bot: Bot, mayIncludeSelf: Boolean = false): List<OtherClientInfo>

获取在线的 OtherClient 列表

Link copied to clipboard
abstract suspend fun getRawGroupList(bot: Bot): Sequence<Long>

向服务器查询群列表. 返回值高 32 bits 为 uin, 低 32 bits 为 groupCode

Link copied to clipboard
abstract suspend fun getRawGroupMemberList(bot: Bot, groupUin: Long, groupCode: Long, ownerId: Long): Sequence<MemberInfo>

向服务器查询群成员列表. 请优先使用 Bot.getGroup, Group.members 查看群成员.

Link copied to clipboard
open fun getUin(contactOrBot: ContactOrBot): Long

获取 uin.

Link copied to clipboard

忽略邀请入群(需管理员权限)

Link copied to clipboard
abstract suspend fun ignoreMemberJoinRequest(event: MemberJoinRequestEvent, blackList: Boolean = false)

忽略加群验证(需管理员权限)

Link copied to clipboard
abstract suspend fun muteAnonymousMember(bot: Bot, anonymousId: String, anonymousNick: String, groupId: Long, seconds: Int)

禁言一个匿名用户

Link copied to clipboard
abstract fun newFriend(bot: Bot, friendInfo: FriendInfo): Friend

构造一个 Friend 对象.

Link copied to clipboard
abstract fun newStranger(bot: Bot, strangerInfo: StrangerInfo): Stranger

构造一个 Stranger 对象.

Link copied to clipboard
abstract suspend fun queryImageUrl(bot: Bot, image: Image): String

获取图片下载链接

Link copied to clipboard
abstract suspend fun queryProfile(bot: Bot, targetId: Long): UserProfile

查询某个用户的信息

Link copied to clipboard
abstract suspend fun recallFriendMessageRaw(bot: Bot, targetId: Long, messageIds: IntArray, messageInternalIds: IntArray, time: Int): Boolean

撤回这条消息. 不会广播事件, 不会有安全性检查.

Link copied to clipboard
abstract suspend fun recallGroupMessageRaw(bot: Bot, groupCode: Long, messageIds: IntArray, messageInternalIds: IntArray): Boolean

撤回这条消息. 不会广播事件, 不会有安全性检查.

Link copied to clipboard
abstract suspend fun recallGroupTempMessageRaw(bot: Bot, groupUin: Long, targetId: Long, messageIds: IntArray, messageInternalIds: IntArray, time: Int): Boolean

撤回这条消息. 不会广播事件, 不会有安全性检查.

Link copied to clipboard
abstract suspend fun recallMessage(bot: Bot, source: MessageSource)

撤回这条消息. 可撤回自己 2 分钟内发出的消息, 和任意时间的群成员的消息.

Link copied to clipboard
inline suspend fun IMirai.recallMessage(bot: Bot, message: MessageChain)

撤回这条消息.

Link copied to clipboard
abstract suspend fun refreshKeys(bot: Bot)

主动刷新 keys, 如 SKey, PSKey 等.

Link copied to clipboard
abstract suspend fun rejectMemberJoinRequest(event: MemberJoinRequestEvent, blackList: Boolean = false, message: String = "")

拒绝加群验证(需管理员权限)

Link copied to clipboard
abstract suspend fun rejectNewFriendRequest(event: NewFriendRequestEvent, blackList: Boolean = false)

拒绝好友验证

Link copied to clipboard
abstract suspend fun sendNudge(bot: Bot, nudge: Nudge, receiver: Contact): Boolean

发送戳一戳消息

Link copied to clipboard
abstract suspend fun solveBotInvitedJoinGroupRequestEvent(bot: Bot, eventId: Long, invitorId: Long, groupId: Long, accept: Boolean)

处理被邀请加入一个群请求事件

Link copied to clipboard
abstract suspend fun solveMemberJoinRequestEvent(bot: Bot, eventId: Long, fromId: Long, fromNick: String, groupId: Long, accept: Boolean?, blackList: Boolean, message: String = "")

处理账号请求加入群事件

Link copied to clipboard
abstract suspend fun solveNewFriendRequestEvent(bot: Bot, eventId: Long, fromId: Long, fromNick: String, accept: Boolean, blackList: Boolean)

处理一个账号请求添加机器人为好友的事件

Properties

Link copied to clipboard
abstract val BotFactory: BotFactory

请优先使用 BotFactory.INSTANCE

Link copied to clipboard

Mirai 全局使用的 FileCacheStrategy.