Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for switching anonymousChat settings #1522

Merged
merged 3 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion mirai-core-api/src/commonMain/kotlin/contact/Group.kt
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public interface GroupSettings {
/**
* 匿名聊天
*/
public val isAnonymousChatEnabled: Boolean
public var isAnonymousChatEnabled: Boolean
}

/**
Expand Down
11 changes: 9 additions & 2 deletions mirai-core/src/commonMain/kotlin/contact/GroupSettingsImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ internal object KnownPacketFactories {
// TroopManagement.GetGroupInfo,
TroopManagement.EditGroupNametag,
TroopManagement.Kick,
TroopManagement.SwitchAnonymousChat,
TroopEssenceMsgManager.SetEssence,
NudgePacket,
Heartbeat.Alive,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down