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 799251c
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 48 deletions.
50 changes: 28 additions & 22 deletions common/api/common.api

Large diffs are not rendered by default.

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
17 changes: 10 additions & 7 deletions core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -4181,23 +4181,25 @@ public final class dev/kord/core/cache/data/InviteWithMetadataData$Companion {

public final class dev/kord/core/cache/data/MemberData {
public static final field Companion Ldev/kord/core/cache/data/MemberData$Companion;
public synthetic fun <init> (ILdev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/optional/Optional;Ljava/util/List;Lkotlinx/datetime/Instant;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/optional/Optional;Ljava/util/List;Lkotlinx/datetime/Instant;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;)V
public synthetic fun <init> (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/optional/Optional;Ljava/util/List;Lkotlinx/datetime/Instant;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (ILdev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/optional/Optional;Ljava/util/List;Lkotlinx/datetime/Instant;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/GuildMemberFlags;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/optional/Optional;Ljava/util/List;Lkotlinx/datetime/Instant;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/GuildMemberFlags;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;)V
public synthetic fun <init> (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/optional/Optional;Ljava/util/List;Lkotlinx/datetime/Instant;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/GuildMemberFlags;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ldev/kord/common/entity/Snowflake;
public final fun component10 ()Ldev/kord/common/entity/optional/Optional;
public final fun component2 ()Ldev/kord/common/entity/Snowflake;
public final fun component3 ()Ldev/kord/common/entity/optional/Optional;
public final fun component4 ()Ljava/util/List;
public final fun component5 ()Lkotlinx/datetime/Instant;
public final fun component6 ()Ldev/kord/common/entity/optional/Optional;
public final fun component7 ()Ldev/kord/common/entity/optional/OptionalBoolean;
public final fun component8 ()Ldev/kord/common/entity/optional/Optional;
public final fun component7 ()Ldev/kord/common/entity/GuildMemberFlags;
public final fun component8 ()Ldev/kord/common/entity/optional/OptionalBoolean;
public final fun component9 ()Ldev/kord/common/entity/optional/Optional;
public final fun copy (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/optional/Optional;Ljava/util/List;Lkotlinx/datetime/Instant;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;)Ldev/kord/core/cache/data/MemberData;
public static synthetic fun copy$default (Ldev/kord/core/cache/data/MemberData;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/optional/Optional;Ljava/util/List;Lkotlinx/datetime/Instant;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;ILjava/lang/Object;)Ldev/kord/core/cache/data/MemberData;
public final fun copy (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/optional/Optional;Ljava/util/List;Lkotlinx/datetime/Instant;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/GuildMemberFlags;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;)Ldev/kord/core/cache/data/MemberData;
public static synthetic fun copy$default (Ldev/kord/core/cache/data/MemberData;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/optional/Optional;Ljava/util/List;Lkotlinx/datetime/Instant;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/GuildMemberFlags;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;ILjava/lang/Object;)Ldev/kord/core/cache/data/MemberData;
public fun equals (Ljava/lang/Object;)Z
public final fun getAvatar ()Ldev/kord/common/entity/optional/Optional;
public final fun getCommunicationDisabledUntil ()Ldev/kord/common/entity/optional/Optional;
public final fun getFlags ()Ldev/kord/common/entity/GuildMemberFlags;
public final fun getGuildId ()Ldev/kord/common/entity/Snowflake;
public final fun getJoinedAt ()Lkotlinx/datetime/Instant;
public final fun getNick ()Ldev/kord/common/entity/optional/Optional;
Expand Down Expand Up @@ -6611,6 +6613,7 @@ public final class dev/kord/core/entity/Member : dev/kord/core/entity/User, dev/
public final fun getCommunicationDisabledUntil ()Lkotlinx/datetime/Instant;
public final fun getDisplayName ()Ljava/lang/String;
public final fun getEffectiveName ()Ljava/lang/String;
public final fun getFlags ()Ldev/kord/common/entity/GuildMemberFlags;
public fun getGuild ()Ldev/kord/core/behavior/GuildBehavior;
public fun getGuild (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun getGuildId ()Ldev/kord/common/entity/Snowflake;
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
14 changes: 9 additions & 5 deletions rest/api/rest.api
Original file line number Diff line number Diff line change
Expand Up @@ -1833,13 +1833,15 @@ public final class dev/kord/rest/builder/member/MemberModifyBuilder : dev/kord/r
public fun <init> ()V
public final fun getCommunicationDisabledUntil ()Lkotlinx/datetime/Instant;
public final fun getDeafened ()Ljava/lang/Boolean;
public final fun getFlags ()Ldev/kord/common/entity/GuildMemberFlags;
public final fun getMuted ()Ljava/lang/Boolean;
public final fun getNickname ()Ljava/lang/String;
public fun getReason ()Ljava/lang/String;
public final fun getRoles ()Ljava/util/Set;
public final fun getVoiceChannelId ()Ldev/kord/common/entity/Snowflake;
public final fun setCommunicationDisabledUntil (Lkotlinx/datetime/Instant;)V
public final fun setDeafened (Ljava/lang/Boolean;)V
public final fun setFlags (Ldev/kord/common/entity/GuildMemberFlags;)V
public final fun setMuted (Ljava/lang/Boolean;)V
public final fun setNickname (Ljava/lang/String;)V
public fun setReason (Ljava/lang/String;)V
Expand Down Expand Up @@ -4087,21 +4089,23 @@ public final class dev/kord/rest/json/request/GuildMemberAddRequest$Companion {
public final class dev/kord/rest/json/request/GuildMemberModifyRequest {
public static final field Companion Ldev/kord/rest/json/request/GuildMemberModifyRequest$Companion;
public fun <init> ()V
public synthetic fun <init> (ILdev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> (Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;)V
public synthetic fun <init> (Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (ILdev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> (Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;)V
public synthetic fun <init> (Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ldev/kord/common/entity/optional/Optional;
public final fun component2 ()Ldev/kord/common/entity/optional/Optional;
public final fun component3 ()Ldev/kord/common/entity/optional/OptionalBoolean;
public final fun component4 ()Ldev/kord/common/entity/optional/OptionalBoolean;
public final fun component5 ()Ldev/kord/common/entity/optional/OptionalSnowflake;
public final fun component6 ()Ldev/kord/common/entity/optional/Optional;
public final fun copy (Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;)Ldev/kord/rest/json/request/GuildMemberModifyRequest;
public static synthetic fun copy$default (Ldev/kord/rest/json/request/GuildMemberModifyRequest;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;ILjava/lang/Object;)Ldev/kord/rest/json/request/GuildMemberModifyRequest;
public final fun component7 ()Ldev/kord/common/entity/optional/Optional;
public final fun copy (Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;)Ldev/kord/rest/json/request/GuildMemberModifyRequest;
public static synthetic fun copy$default (Ldev/kord/rest/json/request/GuildMemberModifyRequest;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalSnowflake;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;ILjava/lang/Object;)Ldev/kord/rest/json/request/GuildMemberModifyRequest;
public fun equals (Ljava/lang/Object;)Z
public final fun getChannelId ()Ldev/kord/common/entity/optional/OptionalSnowflake;
public final fun getCommunicationDisabledUntil ()Ldev/kord/common/entity/optional/Optional;
public final fun getDeaf ()Ldev/kord/common/entity/optional/OptionalBoolean;
public final fun getFlags ()Ldev/kord/common/entity/optional/Optional;
public final fun getMute ()Ldev/kord/common/entity/optional/OptionalBoolean;
public final fun getNick ()Ldev/kord/common/entity/optional/Optional;
public final fun getRoles ()Ldev/kord/common/entity/optional/Optional;
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 799251c

Please sign in to comment.