Commit 918ede1f authored by Him188's avatar Him188

Add `FriendDeleteEvent`, `FriendAddEvent`, also fix #216

parent 6af75c02
...@@ -56,6 +56,7 @@ internal fun Group.checkIsGroupImpl() { ...@@ -56,6 +56,7 @@ internal fun Group.checkIsGroupImpl() {
GroupImpl.checkIsInstance(this) GroupImpl.checkIsInstance(this)
} }
@OptIn(MiraiExperimentalAPI::class, LowLevelAPI::class)
@Suppress("PropertyName") @Suppress("PropertyName")
internal class GroupImpl( internal class GroupImpl(
bot: QQAndroidBot, override val coroutineContext: CoroutineContext, bot: QQAndroidBot, override val coroutineContext: CoroutineContext,
...@@ -70,44 +71,20 @@ internal class GroupImpl( ...@@ -70,44 +71,20 @@ internal class GroupImpl(
override val bot: QQAndroidBot by bot.unsafeWeakRef() override val bot: QQAndroidBot by bot.unsafeWeakRef()
@OptIn(LowLevelAPI::class)
val uin: Long = groupInfo.uin val uin: Long = groupInfo.uin
override lateinit var owner: Member override lateinit var owner: Member
@OptIn(MiraiExperimentalAPI::class) override lateinit var botAsMember: Member
override val botAsMember: Member by lazy {
newMember(object : MemberInfo {
override val nameCard: String
get() = bot.nick // TODO: 2020/2/21 机器人在群内的昵称获取
override val permission: MemberPermission
get() = botPermission
override val specialTitle: String
get() = "" // TODO: 2020/2/21 获取机器人在群里的头衔
override val muteTimestamp: Int
get() = botMuteRemaining
override val uin: Long
get() = bot.id
override val nick: String
get() = bot.nick
})
}
@OptIn(MiraiExperimentalAPI::class)
override lateinit var botPermission: MemberPermission override lateinit var botPermission: MemberPermission
var _botMuteTimestamp: Int = groupInfo.botMuteTimestamp // e.g. 600
override val botMuteRemaining: Int get() = botAsMember.muteTimeRemaining
override val botMuteRemaining: Int =
if (_botMuteTimestamp == 0 || _botMuteTimestamp == 0xFFFFFFFF.toInt()) {
0
} else {
_botMuteTimestamp - currentTimeSeconds.toInt() - bot.client.timeDifference.toInt()
}
override val members: ContactList<Member> = ContactList(members.mapNotNull { override val members: ContactList<Member> = ContactList(members.mapNotNull {
if (it.uin == bot.id) { if (it.uin == bot.id) {
botPermission = it.permission botAsMember = newMember(it)
if (it.permission == MemberPermission.OWNER) { if (it.permission == MemberPermission.OWNER) {
owner = botAsMember owner = botAsMember
} }
......
...@@ -109,7 +109,7 @@ internal class MemberImpl constructor( ...@@ -109,7 +109,7 @@ internal class MemberImpl constructor(
if (_muteTimestamp == 0 || _muteTimestamp == 0xFFFFFFFF.toInt()) { if (_muteTimestamp == 0 || _muteTimestamp == 0xFFFFFFFF.toInt()) {
0 0
} else { } else {
_muteTimestamp - currentTimeSeconds.toInt() - bot.client.timeDifference.toInt() (_muteTimestamp - currentTimeSeconds.toInt()).coerceAtLeast(0)
} }
override var nameCard: String override var nameCard: String
......
...@@ -255,10 +255,6 @@ internal class OfflineMessageSourceImplBySourceMsg( // from others' quotation ...@@ -255,10 +255,6 @@ internal class OfflineMessageSourceImplBySourceMsg( // from others' quotation
override val bot: Bot, override val bot: Bot,
groupIdOrZero: Long groupIdOrZero: Long
) : OfflineMessageSource(), MessageSourceImpl { ) : OfflineMessageSource(), MessageSourceImpl {
init {
println(delegate._miraiContentToString())
}
override val kind: Kind get() = if (delegate.srcMsg == null) Kind.GROUP else Kind.FRIEND override val kind: Kind get() = if (delegate.srcMsg == null) Kind.GROUP else Kind.FRIEND
private val isRecalled: AtomicBoolean = atomic(false) private val isRecalled: AtomicBoolean = atomic(false)
......
package net.mamoe.mirai.qqandroid.network.protocol.data.jce package net.mamoe.mirai.qqandroid.network.protocol.data.jce
import net.mamoe.mirai.qqandroid.utils.io.serialization.jce.JceId
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import net.mamoe.mirai.qqandroid.network.protocol.packet.EMPTY_BYTE_ARRAY
import net.mamoe.mirai.qqandroid.utils.io.JceStruct import net.mamoe.mirai.qqandroid.utils.io.JceStruct
import net.mamoe.mirai.qqandroid.utils.io.serialization.jce.JceId
@Serializable @Serializable
internal class AddGroup( internal class AddGroup(
...@@ -62,7 +63,7 @@ internal class MsgType0x210( ...@@ -62,7 +63,7 @@ internal class MsgType0x210(
@JceId(7) val stMsgInfo0x20: MsgType0x210SubMsgType0x20? = null, @JceId(7) val stMsgInfo0x20: MsgType0x210SubMsgType0x20? = null,
@JceId(8) val stMsgInfo0x1d: MsgType0x210SubMsgType0x1d? = null, @JceId(8) val stMsgInfo0x1d: MsgType0x210SubMsgType0x1d? = null,
@JceId(9) val stMsgInfo0x24: MsgType0x210SubMsgType0x24? = null, @JceId(9) val stMsgInfo0x24: MsgType0x210SubMsgType0x24? = null,
@JceId(10) val vProtobuf: ByteArray? = null @JceId(10) val vProtobuf: ByteArray = EMPTY_BYTE_ARRAY
) : JceStruct ) : JceStruct
@Serializable @Serializable
......
...@@ -74,7 +74,7 @@ internal class Vec0xd6b : ProtoBuf { ...@@ -74,7 +74,7 @@ internal class Vec0xd6b : ProtoBuf {
internal class MutualMarkData( internal class MutualMarkData(
@ProtoId(1) val frdUin: Long = 0L, @ProtoId(1) val frdUin: Long = 0L,
@ProtoId(2) val result: Int = 0 @ProtoId(2) val result: Int = 0
// @SerialId(11) val mutualmarkInfo: List<Mutualmark.MutualMark>? = null // @SerialId(11) val mutualmarkInfo: List<net.mamoe.mirai.qqandroid.network.protocol.data.proto.onlinePush0x210.Mutualmark.MutualMark>? = null
) : ProtoBuf ) : ProtoBuf
} }
......
package net.mamoe.mirai.qqandroid.network.protocol.packet.chat.receive.onlinePush0x210
import kotlinx.io.core.String
import net.mamoe.mirai.Bot
import net.mamoe.mirai.event.events.MemberCardChangeEvent
import net.mamoe.mirai.qqandroid.utils.io.serialization.loadAs
internal object OnlinePush0x210Factory {
// fun solve(msg: MsgType0x210, bot: Bot): Any? = when (msg.uSubMsgType) {
// 0x27L -> {
// val body = msg.vProtobuf?.loadAs(SubMsgType0x27.MsgBody.serializer())
// if (body?.msgModInfos != null) {
// body.msgModInfos.firstOrNull()?.msgModGroupMemberProfile?.run {
// val member = bot.groups.getOrNull(groupUin)?.getOrNull(uin)
// val new = msgGroupMemberProfileInfos?.firstOrNull()
// if (member != null && new?.value != null) {
// MemberCardChangeEvent(member.nameCard, String(new.value), member, member)
// }
// }
// } else null
// }
// else -> null
// }
}
\ No newline at end of file
...@@ -484,6 +484,39 @@ data class MemberUnmuteEvent( ...@@ -484,6 +484,39 @@ data class MemberUnmuteEvent(
// region 好友、群认证 // region 好友、群认证
/**
* 好友昵称改变事件. 目前仅支持解析 (来自 PC 端的修改).
*/
@SinceMirai("0.36.0")
data class FriendRemarkChangeEvent(
override val bot: Bot,
val friend: QQ,
val newName: String
) : BotEvent, Packet
/**
* 成功添加了一个新好友的事件
*/
@SinceMirai("0.36.0")
data class FriendAddEvent(
/**
* 新好友. 已经添加到 [Bot.friends]
*/
val friend: QQ
) : BotEvent, Packet {
override val bot: Bot get() = friend.bot
}
/**
* 好友已被删除的事件.
*/
@SinceMirai("0.36.0")
data class FriendDeleteEvent(
val friend: QQ
) : BotEvent, Packet {
override val bot: Bot get() = friend.bot
}
/** /**
* 一个账号请求添加机器人为好友的事件 * 一个账号请求添加机器人为好友的事件
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment