Skip to content

Commit

Permalink
Allow modifying GuildMemberFlags
Browse files Browse the repository at this point in the history
This was missing in #760.

See discord/discord-api-docs#5881
  • Loading branch information
lukellmann committed Sep 2, 2023
1 parent 6749400 commit 0c530f6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
15 changes: 3 additions & 12 deletions common/src/commonMain/kotlin/entity/Member.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ import kotlinx.serialization.Serializable
@Serializable
public data class DiscordGuildMember(
val user: Optional<DiscordUser> = 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<String?> = Optional.Missing(),
val roles: List<Snowflake>,
@SerialName("joined_at")
Expand All @@ -46,17 +42,14 @@ public data class DiscordGuildMember(
@Serializable
public data class DiscordInteractionGuildMember(
val user: Optional<DiscordUser> = 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<String?> = Optional.Missing(),
val roles: List<Snowflake>,
@SerialName("joined_at")
val joinedAt: Instant,
@SerialName("premium_since")
val premiumSince: Optional<Instant?> = Optional.Missing(),
val permissions: Permissions,
val flags: GuildMemberFlags,
val pending: OptionalBoolean = OptionalBoolean.Missing,
val avatar: Optional<String?> = Optional.Missing(),
@SerialName("communication_disabled_until")
Expand All @@ -67,10 +60,6 @@ public data class DiscordInteractionGuildMember(
@Serializable
public data class DiscordAddedGuildMember(
val user: Optional<DiscordUser> = 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<String?> = Optional.Missing(),
val roles: List<Snowflake>,
@SerialName("joined_at")
Expand All @@ -79,6 +68,7 @@ public data class DiscordAddedGuildMember(
val premiumSince: Optional<Instant?> = Optional.Missing(),
val deaf: Boolean,
val mute: Boolean,
val flags: GuildMemberFlags,
@SerialName("guild_id")
val guildId: Snowflake,
val pending: OptionalBoolean = OptionalBoolean.Missing,
Expand All @@ -105,6 +95,7 @@ public data class DiscordUpdatedGuildMember(
val joinedAt: Instant,
@SerialName("premium_since")
val premiumSince: Optional<Instant?> = Optional.Missing(),
val flags: GuildMemberFlags,
val pending: OptionalBoolean = OptionalBoolean.Missing,
val avatar: Optional<String?> = Optional.Missing(),
@SerialName("communication_disabled_until")
Expand Down
5 changes: 5 additions & 0 deletions core/src/commonMain/kotlin/cache/data/MemberData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public data class MemberData(
val roles: List<Snowflake>,
val joinedAt: Instant,
val premiumSince: Optional<Instant?> = Optional.Missing(),
val flags: GuildMemberFlags,
val pending: OptionalBoolean = OptionalBoolean.Missing,
val avatar: Optional<String?> = Optional.Missing(),
val communicationDisabledUntil: Optional<Instant?> = Optional.Missing()
Expand All @@ -34,6 +35,7 @@ public data class MemberData(
roles = roles,
joinedAt = joinedAt,
premiumSince = premiumSince,
flags = flags,
pending = pending,
avatar = avatar,
communicationDisabledUntil = communicationDisabledUntil,
Expand All @@ -50,6 +52,7 @@ public data class MemberData(
roles = roles,
joinedAt = joinedAt,
premiumSince = premiumSince,
flags = flags,
pending = pending,
avatar = avatar,
communicationDisabledUntil = communicationDisabledUntil,
Expand All @@ -64,6 +67,7 @@ public data class MemberData(
roles = roles,
joinedAt = joinedAt,
premiumSince = premiumSince,
flags = flags,
pending = pending,
avatar = avatar,
communicationDisabledUntil = communicationDisabledUntil,
Expand All @@ -78,6 +82,7 @@ public data class MemberData(
roles = roles,
joinedAt = joinedAt,
premiumSince = premiumSince,
flags = flags,
pending = pending,
avatar = avatar,
communicationDisabledUntil = communicationDisabledUntil,
Expand Down
4 changes: 4 additions & 0 deletions core/src/commonMain/kotlin/entity/Member.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -32,12 +33,16 @@ public class MemberModifyBuilder : AuditRequestBuilder<GuildMemberModifyRequest>
private var _roles: Optional<MutableSet<Snowflake>?> = Optional.Missing()
public var roles: MutableSet<Snowflake>? by ::_roles.delegate()

private var _flags: Optional<GuildMemberFlags?> = 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,
)
}
3 changes: 2 additions & 1 deletion rest/src/commonMain/kotlin/json/request/GuildRequests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ public data class GuildMemberModifyRequest(
@SerialName("channel_id")
val channelId: OptionalSnowflake? = OptionalSnowflake.Missing,
@SerialName("communication_disabled_until")
val communicationDisabledUntil: Optional<Instant?> = Optional.Missing()
val communicationDisabledUntil: Optional<Instant?> = Optional.Missing(),
val flags: Optional<GuildMemberFlags?> = Optional.Missing(),
)


Expand Down

0 comments on commit 0c530f6

Please sign in to comment.