Support Group Honor (Talkative Only) (#774)

* Support Group Honor (Talkative Only)

* Apply suggestions from code review

Co-authored-by: Him188 <Him188@mamoe.net>

* Replace Member with NormalMember

Co-authored-by: Him188 <Him188@mamoe.net>
This commit is contained in:
sandtechnology 2020-12-28 00:34:55 +08:00 committed by GitHub
parent 0198e3363a
commit 2b1fe9f27a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 73 additions and 0 deletions

View File

@ -17,6 +17,7 @@ import net.mamoe.kjbb.JvmBlockingBridge
import net.mamoe.mirai.Bot
import net.mamoe.mirai.Mirai
import net.mamoe.mirai.contact.*
import net.mamoe.mirai.data.GroupHonorType
import net.mamoe.mirai.event.AbstractEvent
import net.mamoe.mirai.event.BroadcastControllable
import net.mamoe.mirai.internal.network.Packet
@ -516,4 +517,53 @@ public data class MemberNudgedEvent @MiraiInternalApi constructor(
// endregion
// region 群荣誉
/**
* [Member] 荣誉改变时的事件, 目前只支持龙王
*/
@MiraiExperimentalApi
public sealed class MemberHonorChangeEvent : GroupMemberEvent, BotPassiveEvent, Packet, AbstractEvent() {
/**
* 改变荣誉的群成员
*/
public abstract override val member: NormalMember
/**
* 改变的荣誉类型
*/
public abstract val honorType: GroupHonorType
/**
* 获得荣誉时的事件
*/
public class Achieve(override val member: NormalMember, override val honorType: GroupHonorType) :
MemberHonorChangeEvent()
/**
* 失去荣誉时的事件
*/
public class Lose(override val member: NormalMember, override val honorType: GroupHonorType) :
MemberHonorChangeEvent()
}
/**
* [Group] 龙王改变时的事件
*/
public class GroupTalkativeChangeEvent(
/**
* 改变的群
*/
override val group: Group,
/**
* 当前龙王
*/
public val now: NormalMember,
/**
* 先前龙王
*/
public val previous: NormalMember
) : Packet, GroupEvent, BotPassiveEvent, AbstractEvent()
// endregion
// endregion

View File

@ -24,6 +24,9 @@ import net.mamoe.mirai.JavaFriendlyAPI
import net.mamoe.mirai.Mirai
import net.mamoe.mirai.contact.Friend
import net.mamoe.mirai.contact.Member
import net.mamoe.mirai.contact.NormalMember
import net.mamoe.mirai.data.FriendInfo
import net.mamoe.mirai.data.GroupHonorType
import net.mamoe.mirai.data.FriendInfoImpl
import net.mamoe.mirai.event.events.*
import net.mamoe.mirai.internal.QQAndroidBot
@ -266,6 +269,26 @@ private object Transformers732 : Map<Int, Lambda732> by mapOf(
}
return@lambda732 sequenceOf(MemberNudgedEvent(from, target, action, suffix))
}
//龙王
10093L, 1053L, 1054L -> {
var now: NormalMember = group.botAsMember
var previous: NormalMember? = null
grayTip.msgTemplParam.asSequence().map {
it.name.decodeToString() to it.value.decodeToString()
}.forEach { (key, value) ->
when (key) {
"uin" -> now = group[value.toLong()] ?: return@lambda732 emptySequence()
"uin_last" -> previous = group[value.toLong()] ?: return@lambda732 emptySequence()
}
}
return@lambda732 previous?.let {
sequenceOf(
GroupTalkativeChangeEvent(group, now, it),
MemberHonorChangeEvent.Lose(it, GroupHonorType.TALKATIVE),
MemberHonorChangeEvent.Achieve(now, GroupHonorType.TALKATIVE)
)
} ?: sequenceOf(MemberHonorChangeEvent.Achieve(now, GroupHonorType.TALKATIVE))
}
else -> {
bot.network.logger.debug {
"Unknown Transformers528 0x14 template\ntemplId=${grayTip?.templId}\nPermList=${grayTip?.msgTemplParam?._miraiContentToString()}"