mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-06 11:39:14 +08:00
Misc improvements
This commit is contained in:
parent
cadbd7ff3a
commit
dc7d73f148
@ -542,7 +542,7 @@ internal class GroupImpl(
|
||||
@UseExperimental(MiraiExperimentalAPI::class)
|
||||
override fun Member(memberInfo: MemberInfo): Member {
|
||||
return MemberImpl(
|
||||
bot.QQ(memberInfo) as QQImpl,
|
||||
bot._lowLevelNewQQQQ(memberInfo) as QQImpl,
|
||||
this,
|
||||
this.coroutineContext,
|
||||
memberInfo
|
||||
|
@ -12,6 +12,7 @@ package net.mamoe.mirai.qqandroid
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.client.statement.HttpResponse
|
||||
import io.ktor.utils.io.ByteReadChannel
|
||||
import kotlinx.coroutines.CoroutineName
|
||||
import net.mamoe.mirai.BotAccount
|
||||
import net.mamoe.mirai.BotImpl
|
||||
import net.mamoe.mirai.LowLevelAPI
|
||||
@ -67,14 +68,21 @@ internal abstract class QQAndroidBotBase constructor(
|
||||
override val friends: ContactList<QQ> = ContactList(LockFreeLinkedList())
|
||||
|
||||
override val selfQQ: QQ by lazy {
|
||||
QQ(object : FriendInfo {
|
||||
@UseExperimental(LowLevelAPI::class)
|
||||
_lowLevelNewQQ(object : FriendInfo {
|
||||
override val uin: Long get() = this@QQAndroidBotBase.uin
|
||||
override val nick: String get() = this@QQAndroidBotBase.nick
|
||||
})
|
||||
}
|
||||
|
||||
override fun QQ(friendInfo: FriendInfo): QQ {
|
||||
return QQImpl(this as QQAndroidBot, coroutineContext, friendInfo.uin, friendInfo)
|
||||
@LowLevelAPI
|
||||
override fun _lowLevelNewQQ(friendInfo: FriendInfo): QQ {
|
||||
return QQImpl(
|
||||
this as QQAndroidBot,
|
||||
coroutineContext + CoroutineName("QQ(${friendInfo.uin}"),
|
||||
friendInfo.uin,
|
||||
friendInfo
|
||||
)
|
||||
}
|
||||
|
||||
override fun createNetworkHandler(coroutineContext: CoroutineContext): QQAndroidBotNetworkHandler {
|
||||
|
@ -24,5 +24,4 @@ internal actual class QQAndroidBot actual constructor(
|
||||
context: Context,
|
||||
account: BotAccount,
|
||||
configuration: BotConfiguration
|
||||
) : QQAndroidBotBase(context, account, configuration)
|
||||
|
||||
) : QQAndroidBotBase(context, account, configuration)
|
@ -4,10 +4,8 @@ package net.mamoe.mirai
|
||||
|
||||
import io.ktor.utils.io.ByteReadChannel
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
import net.mamoe.mirai.contact.*
|
||||
import net.mamoe.mirai.data.AddFriendResult
|
||||
import net.mamoe.mirai.data.FriendInfo
|
||||
import net.mamoe.mirai.message.MessageReceipt
|
||||
import net.mamoe.mirai.message.data.Image
|
||||
import net.mamoe.mirai.message.data.MessageChain
|
||||
@ -127,15 +125,6 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA
|
||||
?: throw NoSuchElementException("No such friend $id for bot ${this.uin}")
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造一个 [QQ] 对象. 它持有对 [Bot] 的弱引用([WeakRef]).
|
||||
*
|
||||
* [Bot] 无法管理这个对象, 但这个对象会以 [Bot] 的 [Job] 作为父 Job.
|
||||
* 因此, 当 [Bot] 被关闭后, 这个对象也会被关闭.
|
||||
*/
|
||||
@Suppress("FunctionName")
|
||||
actual abstract fun QQ(friendInfo: FriendInfo): QQ
|
||||
|
||||
/**
|
||||
* 机器人加入的群列表.
|
||||
*/
|
||||
|
@ -18,7 +18,6 @@ import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import net.mamoe.mirai.contact.*
|
||||
import net.mamoe.mirai.data.AddFriendResult
|
||||
import net.mamoe.mirai.data.FriendInfo
|
||||
import net.mamoe.mirai.message.MessageReceipt
|
||||
import net.mamoe.mirai.message.data.Image
|
||||
import net.mamoe.mirai.message.data.MessageChain
|
||||
@ -96,7 +95,7 @@ expect abstract class Bot() : CoroutineScope, LowLevelBotAPIAccessor {
|
||||
// region contacts
|
||||
|
||||
/**
|
||||
* [QQ.id] 与 [Bot.uin] 相同的 [QQ] 实例
|
||||
* [_lowLevelNewQQ.id] 与 [Bot.uin] 相同的 [_lowLevelNewQQ] 实例
|
||||
*/
|
||||
abstract val selfQQ: QQ
|
||||
|
||||
@ -136,14 +135,6 @@ expect abstract class Bot() : CoroutineScope, LowLevelBotAPIAccessor {
|
||||
*/
|
||||
fun getFriend(id: Long): QQ
|
||||
|
||||
/**
|
||||
* 构造一个 [QQ] 对象. 它持有对 [Bot] 的弱引用([WeakRef]).
|
||||
*
|
||||
* [Bot] 无法管理这个对象, 但这个对象会以 [Bot] 的 [Job] 作为父 Job.
|
||||
* 因此, 当 [Bot] 被关闭后, 这个对象也会被关闭.
|
||||
*/
|
||||
abstract fun QQ(friendInfo: FriendInfo): QQ
|
||||
|
||||
/**
|
||||
* 机器人加入的群列表.
|
||||
*/
|
||||
|
@ -9,11 +9,15 @@
|
||||
|
||||
package net.mamoe.mirai
|
||||
|
||||
import kotlinx.coroutines.Job
|
||||
import net.mamoe.mirai.contact.Group
|
||||
import net.mamoe.mirai.contact.QQ
|
||||
import net.mamoe.mirai.data.FriendInfo
|
||||
import net.mamoe.mirai.data.GroupInfo
|
||||
import net.mamoe.mirai.data.MemberInfo
|
||||
import net.mamoe.mirai.message.data.MessageSource
|
||||
import net.mamoe.mirai.utils.MiraiExperimentalAPI
|
||||
import net.mamoe.mirai.utils.WeakRef
|
||||
|
||||
/**
|
||||
* 标示这个 API 是低级的 API.
|
||||
@ -35,7 +39,16 @@ annotation class LowLevelAPI
|
||||
interface LowLevelBotAPIAccessor {
|
||||
|
||||
/**
|
||||
* 向服务器查询群列表. 返回值前 32 bits 为 uin, 后 32 bits 为 groupCode
|
||||
* 构造一个 [_lowLevelNewQQ] 对象. 它持有对 [Bot] 的弱引用([WeakRef]).
|
||||
*
|
||||
* [Bot] 无法管理这个对象, 但这个对象会以 [Bot] 的 [Job] 作为父 Job.
|
||||
* 因此, 当 [Bot] 被关闭后, 这个对象也会被关闭.
|
||||
*/
|
||||
@LowLevelAPI
|
||||
fun _lowLevelNewQQ(friendInfo: FriendInfo): QQ
|
||||
|
||||
/**
|
||||
* 向服务器查询群列表. 返回值高 32 bits 为 uin, 低 32 bits 为 groupCode
|
||||
*/
|
||||
@LowLevelAPI
|
||||
suspend fun _lowLevelQueryGroupList(): Sequence<Long>
|
||||
@ -72,4 +85,21 @@ interface LowLevelBotAPIAccessor {
|
||||
*/
|
||||
@LowLevelAPI
|
||||
suspend fun _lowLevelRecallGroupMessage(groupId: Long, messageId: Long)
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤回一条群里的消息. 可以是机器人发送也可以是其他群员发送.
|
||||
*/
|
||||
@Suppress("FunctionName")
|
||||
@MiraiExperimentalAPI
|
||||
@LowLevelAPI
|
||||
suspend fun LowLevelBotAPIAccessor._lowLevelRecallGroupMessage(
|
||||
groupId: Long,
|
||||
messageSequenceId: Int,
|
||||
messageRandom: Int
|
||||
) {
|
||||
this._lowLevelRecallGroupMessage(
|
||||
groupId,
|
||||
messageSequenceId.toLong().shl(32) or messageRandom.toLong().and(0xFFFFFFFFL)
|
||||
)
|
||||
}
|
@ -4,10 +4,8 @@ package net.mamoe.mirai
|
||||
|
||||
import io.ktor.utils.io.ByteReadChannel
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
import net.mamoe.mirai.contact.*
|
||||
import net.mamoe.mirai.data.AddFriendResult
|
||||
import net.mamoe.mirai.data.FriendInfo
|
||||
import net.mamoe.mirai.message.MessageReceipt
|
||||
import net.mamoe.mirai.message.data.Image
|
||||
import net.mamoe.mirai.message.data.MessageChain
|
||||
@ -137,15 +135,6 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA
|
||||
?: throw NoSuchElementException("No such friend $id for bot ${this.uin}")
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造一个 [QQ] 对象. 它持有对 [Bot] 的弱引用([WeakRef]).
|
||||
*
|
||||
* [Bot] 无法管理这个对象, 但这个对象会以 [Bot] 的 [Job] 作为父 Job.
|
||||
* 因此, 当 [Bot] 被关闭后, 这个对象也会被关闭.
|
||||
*/
|
||||
@Suppress("FunctionName")
|
||||
actual abstract fun QQ(friendInfo: FriendInfo): QQ
|
||||
|
||||
/**
|
||||
* 机器人加入的群列表.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user