Support for switching anonymousChat settings (#1522)

* Support for switching anonymousChat settings

* apiDump

* Applied suggestion from him188
This commit is contained in:
sandtechnology 2021-09-27 22:39:01 +08:00 committed by GitHub
parent 66766dd4da
commit c09f8ab192
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 54 additions and 4 deletions

View File

@ -392,6 +392,7 @@ public abstract interface class net/mamoe/mirai/contact/GroupSettings {
public abstract fun isAutoApproveEnabled ()Z
public abstract fun isMuteAll ()Z
public abstract fun setAllowMemberInvite (Z)V
public abstract fun setAnonymousChatEnabled (Z)V
public abstract fun setEntranceAnnouncement (Ljava/lang/String;)V
public abstract fun setMuteAll (Z)V
}

View File

@ -392,6 +392,7 @@ public abstract interface class net/mamoe/mirai/contact/GroupSettings {
public abstract fun isAutoApproveEnabled ()Z
public abstract fun isMuteAll ()Z
public abstract fun setAllowMemberInvite (Z)V
public abstract fun setAnonymousChatEnabled (Z)V
public abstract fun setEntranceAnnouncement (Ljava/lang/String;)V
public abstract fun setMuteAll (Z)V
}

View File

@ -273,7 +273,7 @@ public interface GroupSettings {
/**
* 匿名聊天
*/
public val isAnonymousChatEnabled: Boolean
public var isAnonymousChatEnabled: Boolean
}
/**

View File

@ -23,6 +23,8 @@ import net.mamoe.mirai.event.events.GroupNameChangeEvent
import net.mamoe.mirai.internal.network.QQAndroidClient
import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacket
import net.mamoe.mirai.internal.network.protocol.packet.chat.TroopManagement.GroupOperation
import net.mamoe.mirai.internal.network.protocol.packet.chat.TroopManagement.SwitchAnonymousChat
import net.mamoe.mirai.internal.network.protocol.packet.sendAndExpect
@Suppress("SetterBackingFieldAssignment")
internal class GroupSettingsImpl(
@ -91,9 +93,14 @@ internal class GroupSettingsImpl(
@Deprecated("Don't use public var internally", level = DeprecationLevel.HIDDEN)
override var isAnonymousChatEnabled: Boolean
get() = isAnonymousChatEnabledField
@Suppress("UNUSED_PARAMETER")
set(newValue) {
throw UnsupportedOperationException()
group.run {
checkBotPermission(MemberPermission.ADMINISTRATOR)
launch {
//Handle it in NoticePipelineContext#processAllowAnonymousChat
SwitchAnonymousChat(bot.client, id, newValue).sendAndExpect(bot.network)
}
}
}
@Deprecated("Don't use public var internally", level = DeprecationLevel.HIDDEN)

View File

@ -35,7 +35,7 @@ internal data class GroupInfoImpl(
memo = stTroopNum.groupMemo,
name = stTroopNum.groupName,
allowMemberInvite = stTroopNum.dwGroupFlagExt?.and(0x000000c0) != 0L,
allowAnonymousChat = stTroopNum.dwGroupFlagExt?.and(0x40000000) == 0L,
allowAnonymousChat = stTroopNum.dwGroupFlagExt?.and(0x40000000) != 0L,
autoApprove = stTroopNum.dwGroupFlagExt3?.and(0x00100000) == 0L,
confessTalk = stTroopNum.dwGroupFlagExt3?.and(0x00002000) == 0L,
muteAll = stTroopNum.dwShutUpTimestamp != 0L,

View File

@ -154,6 +154,7 @@ internal object KnownPacketFactories {
// TroopManagement.GetGroupInfo,
TroopManagement.EditGroupNametag,
TroopManagement.Kick,
TroopManagement.SwitchAnonymousChat,
TroopEssenceMsgManager.SetEssence,
NudgePacket,
Heartbeat.Alive,

View File

@ -218,6 +218,46 @@ internal class TroopManagement {
}
internal object SwitchAnonymousChat : OutgoingPacketFactory<SwitchAnonymousChat.Response>("OidbSvc.0x568_22") {
override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): Response {
val ret = this.readBytes()
.loadAs(OidbSso.OIDBSSOPkg.serializer()).result
return Response(
ret == 0
)
}
class Response(
val success: Boolean
) : Packet {
override fun toString(): String = "TroopManagement.SwitchAnonymousChat.Response($success)"
}
operator fun invoke(
client: QQAndroidClient,
groupCode: Long,
switch: Boolean
) = buildOutgoingUniPacket(client) {
writeProtoBuf(
OidbSso.OIDBSSOPkg.serializer(),
OidbSso.OIDBSSOPkg(
command = 1384,
serviceType = 22,
result = 0,
bodybuffer = buildPacket {
writeInt(groupCode.toInt())
if (switch) {
writeByte(1)
} else {
writeByte(0)
}
}.readBytes()
)
)
}
}
internal object GroupOperation : OutgoingPacketFactory<GroupOperation.Response>("OidbSvc.0x89a_0") {
override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): Response = Response