From 0c530f60010d0ab38e7ea21683da2d0cf7f02378 Mon Sep 17 00:00:00 2001 From: lukellmann Date: Sat, 2 Sep 2023 04:54:19 +0200 Subject: [PATCH] Allow modifying GuildMemberFlags This was missing in #760. See https://github.com/discord/discord-api-docs/pull/5881 --- common/src/commonMain/kotlin/entity/Member.kt | 15 +++------------ .../commonMain/kotlin/cache/data/MemberData.kt | 5 +++++ core/src/commonMain/kotlin/entity/Member.kt | 4 ++++ .../kotlin/builder/member/MemberModifyBuilder.kt | 7 ++++++- .../kotlin/json/request/GuildRequests.kt | 3 ++- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/common/src/commonMain/kotlin/entity/Member.kt b/common/src/commonMain/kotlin/entity/Member.kt index a1f47a48522..a37a5dc6a98 100644 --- a/common/src/commonMain/kotlin/entity/Member.kt +++ b/common/src/commonMain/kotlin/entity/Member.kt @@ -23,10 +23,6 @@ import kotlinx.serialization.Serializable @Serializable public data class DiscordGuildMember( val user: Optional = Optional.Missing(), - /* - Don't trust the docs: - 2020-11-05 nick is only documented as nullable but can be missing through Gateway - */ val nick: Optional = Optional.Missing(), val roles: List, @SerialName("joined_at") @@ -46,10 +42,6 @@ public data class DiscordGuildMember( @Serializable public data class DiscordInteractionGuildMember( val user: Optional = Optional.Missing(), - /* - Don't trust the docs: - 2020-11-05 nick is only documented as nullable but can be missing through Gateway - */ val nick: Optional = Optional.Missing(), val roles: List, @SerialName("joined_at") @@ -57,6 +49,7 @@ public data class DiscordInteractionGuildMember( @SerialName("premium_since") val premiumSince: Optional = Optional.Missing(), val permissions: Permissions, + val flags: GuildMemberFlags, val pending: OptionalBoolean = OptionalBoolean.Missing, val avatar: Optional = Optional.Missing(), @SerialName("communication_disabled_until") @@ -67,10 +60,6 @@ public data class DiscordInteractionGuildMember( @Serializable public data class DiscordAddedGuildMember( val user: Optional = Optional.Missing(), - /* - Don't trust the docs: - 2020-11-05 nick is only documented as nullable but can be missing through Gateway - */ val nick: Optional = Optional.Missing(), val roles: List, @SerialName("joined_at") @@ -79,6 +68,7 @@ public data class DiscordAddedGuildMember( val premiumSince: Optional = Optional.Missing(), val deaf: Boolean, val mute: Boolean, + val flags: GuildMemberFlags, @SerialName("guild_id") val guildId: Snowflake, val pending: OptionalBoolean = OptionalBoolean.Missing, @@ -105,6 +95,7 @@ public data class DiscordUpdatedGuildMember( val joinedAt: Instant, @SerialName("premium_since") val premiumSince: Optional = Optional.Missing(), + val flags: GuildMemberFlags, val pending: OptionalBoolean = OptionalBoolean.Missing, val avatar: Optional = Optional.Missing(), @SerialName("communication_disabled_until") diff --git a/core/src/commonMain/kotlin/cache/data/MemberData.kt b/core/src/commonMain/kotlin/cache/data/MemberData.kt index a4fc752194f..4f99cf14e48 100644 --- a/core/src/commonMain/kotlin/cache/data/MemberData.kt +++ b/core/src/commonMain/kotlin/cache/data/MemberData.kt @@ -18,6 +18,7 @@ public data class MemberData( val roles: List, val joinedAt: Instant, val premiumSince: Optional = Optional.Missing(), + val flags: GuildMemberFlags, val pending: OptionalBoolean = OptionalBoolean.Missing, val avatar: Optional = Optional.Missing(), val communicationDisabledUntil: Optional = Optional.Missing() @@ -34,6 +35,7 @@ public data class MemberData( roles = roles, joinedAt = joinedAt, premiumSince = premiumSince, + flags = flags, pending = pending, avatar = avatar, communicationDisabledUntil = communicationDisabledUntil, @@ -50,6 +52,7 @@ public data class MemberData( roles = roles, joinedAt = joinedAt, premiumSince = premiumSince, + flags = flags, pending = pending, avatar = avatar, communicationDisabledUntil = communicationDisabledUntil, @@ -64,6 +67,7 @@ public data class MemberData( roles = roles, joinedAt = joinedAt, premiumSince = premiumSince, + flags = flags, pending = pending, avatar = avatar, communicationDisabledUntil = communicationDisabledUntil, @@ -78,6 +82,7 @@ public data class MemberData( roles = roles, joinedAt = joinedAt, premiumSince = premiumSince, + flags = flags, pending = pending, avatar = avatar, communicationDisabledUntil = communicationDisabledUntil, diff --git a/core/src/commonMain/kotlin/entity/Member.kt b/core/src/commonMain/kotlin/entity/Member.kt index bae2a891a18..64c2c4a5969 100644 --- a/core/src/commonMain/kotlin/entity/Member.kt +++ b/core/src/commonMain/kotlin/entity/Member.kt @@ -1,6 +1,7 @@ package dev.kord.core.entity import dev.kord.common.entity.ALL +import dev.kord.common.entity.GuildMemberFlags import dev.kord.common.entity.Permissions import dev.kord.common.entity.Snowflake import dev.kord.common.exception.RequestException @@ -97,6 +98,9 @@ public class Member( get() = if (roleIds.isEmpty()) emptyFlow() else supplier.getGuildRoles(guildId).filter { it.id in roleIds } + /** The [GuildMemberFlags] of this member. */ + public val flags: GuildMemberFlags get() = memberData.flags + /** * Whether the user has not yet passed the guild's Membership Screening requirements. */ diff --git a/rest/src/commonMain/kotlin/builder/member/MemberModifyBuilder.kt b/rest/src/commonMain/kotlin/builder/member/MemberModifyBuilder.kt index 3a2db2bdd07..d5a086de85f 100644 --- a/rest/src/commonMain/kotlin/builder/member/MemberModifyBuilder.kt +++ b/rest/src/commonMain/kotlin/builder/member/MemberModifyBuilder.kt @@ -1,6 +1,7 @@ package dev.kord.rest.builder.member import dev.kord.common.annotation.KordDsl +import dev.kord.common.entity.GuildMemberFlags import dev.kord.common.entity.Snowflake import dev.kord.common.entity.optional.Optional import dev.kord.common.entity.optional.OptionalBoolean @@ -32,12 +33,16 @@ public class MemberModifyBuilder : AuditRequestBuilder private var _roles: Optional?> = Optional.Missing() public var roles: MutableSet? by ::_roles.delegate() + private var _flags: Optional = Optional.Missing() + public var flags: GuildMemberFlags? by ::_flags.delegate() + override fun toRequest(): GuildMemberModifyRequest = GuildMemberModifyRequest( nick = _nickname, channelId = _voiceChannelId, mute = _muted, deaf = _deafened, roles = _roles, - communicationDisabledUntil = _communicationDisabledUntil + communicationDisabledUntil = _communicationDisabledUntil, + flags = _flags, ) } diff --git a/rest/src/commonMain/kotlin/json/request/GuildRequests.kt b/rest/src/commonMain/kotlin/json/request/GuildRequests.kt index d37265b15fd..06486269d29 100644 --- a/rest/src/commonMain/kotlin/json/request/GuildRequests.kt +++ b/rest/src/commonMain/kotlin/json/request/GuildRequests.kt @@ -126,7 +126,8 @@ public data class GuildMemberModifyRequest( @SerialName("channel_id") val channelId: OptionalSnowflake? = OptionalSnowflake.Missing, @SerialName("communication_disabled_until") - val communicationDisabledUntil: Optional = Optional.Missing() + val communicationDisabledUntil: Optional = Optional.Missing(), + val flags: Optional = Optional.Missing(), )