Skip to content

Commit

Permalink
Add TeamMemberRole (#876)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukellmann authored Sep 18, 2023
1 parent 3a2d1f9 commit a1eb5f7
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 42 deletions.
58 changes: 45 additions & 13 deletions common/api/common.api
Original file line number Diff line number Diff line change
Expand Up @@ -5898,18 +5898,20 @@ public final class dev/kord/common/entity/DiscordStickerPack$Companion {

public final class dev/kord/common/entity/DiscordTeam {
public static final field Companion Ldev/kord/common/entity/DiscordTeam$Companion;
public synthetic fun <init> (ILjava/lang/String;Ldev/kord/common/entity/Snowflake;Ljava/util/List;Ldev/kord/common/entity/Snowflake;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> (Ljava/lang/String;Ldev/kord/common/entity/Snowflake;Ljava/util/List;Ldev/kord/common/entity/Snowflake;)V
public synthetic fun <init> (ILjava/lang/String;Ldev/kord/common/entity/Snowflake;Ljava/util/List;Ljava/lang/String;Ldev/kord/common/entity/Snowflake;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> (Ljava/lang/String;Ldev/kord/common/entity/Snowflake;Ljava/util/List;Ljava/lang/String;Ldev/kord/common/entity/Snowflake;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Ldev/kord/common/entity/Snowflake;
public final fun component3 ()Ljava/util/List;
public final fun component4 ()Ldev/kord/common/entity/Snowflake;
public final fun copy (Ljava/lang/String;Ldev/kord/common/entity/Snowflake;Ljava/util/List;Ldev/kord/common/entity/Snowflake;)Ldev/kord/common/entity/DiscordTeam;
public static synthetic fun copy$default (Ldev/kord/common/entity/DiscordTeam;Ljava/lang/String;Ldev/kord/common/entity/Snowflake;Ljava/util/List;Ldev/kord/common/entity/Snowflake;ILjava/lang/Object;)Ldev/kord/common/entity/DiscordTeam;
public final fun component4 ()Ljava/lang/String;
public final fun component5 ()Ldev/kord/common/entity/Snowflake;
public final fun copy (Ljava/lang/String;Ldev/kord/common/entity/Snowflake;Ljava/util/List;Ljava/lang/String;Ldev/kord/common/entity/Snowflake;)Ldev/kord/common/entity/DiscordTeam;
public static synthetic fun copy$default (Ldev/kord/common/entity/DiscordTeam;Ljava/lang/String;Ldev/kord/common/entity/Snowflake;Ljava/util/List;Ljava/lang/String;Ldev/kord/common/entity/Snowflake;ILjava/lang/Object;)Ldev/kord/common/entity/DiscordTeam;
public fun equals (Ljava/lang/Object;)Z
public final fun getIcon ()Ljava/lang/String;
public final fun getId ()Ldev/kord/common/entity/Snowflake;
public final fun getMembers ()Ljava/util/List;
public final fun getName ()Ljava/lang/String;
public final fun getOwnerUserId ()Ldev/kord/common/entity/Snowflake;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
Expand All @@ -5933,17 +5935,17 @@ public final class dev/kord/common/entity/DiscordTeam$Companion {

public final class dev/kord/common/entity/DiscordTeamMember {
public static final field Companion Ldev/kord/common/entity/DiscordTeamMember$Companion;
public synthetic fun <init> (ILdev/kord/common/entity/TeamMembershipState;Ljava/util/List;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/DiscordUser;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> (Ldev/kord/common/entity/TeamMembershipState;Ljava/util/List;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/DiscordUser;)V
public synthetic fun <init> (ILdev/kord/common/entity/TeamMembershipState;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/DiscordUser;Ldev/kord/common/entity/TeamMemberRole;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> (Ldev/kord/common/entity/TeamMembershipState;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/DiscordUser;Ldev/kord/common/entity/TeamMemberRole;)V
public final fun component1 ()Ldev/kord/common/entity/TeamMembershipState;
public final fun component2 ()Ljava/util/List;
public final fun component3 ()Ldev/kord/common/entity/Snowflake;
public final fun component4 ()Ldev/kord/common/entity/DiscordUser;
public final fun copy (Ldev/kord/common/entity/TeamMembershipState;Ljava/util/List;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/DiscordUser;)Ldev/kord/common/entity/DiscordTeamMember;
public static synthetic fun copy$default (Ldev/kord/common/entity/DiscordTeamMember;Ldev/kord/common/entity/TeamMembershipState;Ljava/util/List;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/DiscordUser;ILjava/lang/Object;)Ldev/kord/common/entity/DiscordTeamMember;
public final fun component2 ()Ldev/kord/common/entity/Snowflake;
public final fun component3 ()Ldev/kord/common/entity/DiscordUser;
public final fun component4 ()Ldev/kord/common/entity/TeamMemberRole;
public final fun copy (Ldev/kord/common/entity/TeamMembershipState;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/DiscordUser;Ldev/kord/common/entity/TeamMemberRole;)Ldev/kord/common/entity/DiscordTeamMember;
public static synthetic fun copy$default (Ldev/kord/common/entity/DiscordTeamMember;Ldev/kord/common/entity/TeamMembershipState;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/DiscordUser;Ldev/kord/common/entity/TeamMemberRole;ILjava/lang/Object;)Ldev/kord/common/entity/DiscordTeamMember;
public fun equals (Ljava/lang/Object;)Z
public final fun getMembershipState ()Ldev/kord/common/entity/TeamMembershipState;
public final fun getPermissions ()Ljava/util/List;
public final fun getRole ()Ldev/kord/common/entity/TeamMemberRole;
public final fun getTeamId ()Ldev/kord/common/entity/Snowflake;
public final fun getUser ()Ldev/kord/common/entity/DiscordUser;
public fun hashCode ()I
Expand Down Expand Up @@ -8833,6 +8835,36 @@ public final class dev/kord/common/entity/SystemChannelFlags$NewCompanion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public abstract class dev/kord/common/entity/TeamMemberRole {
public static final field Companion Ldev/kord/common/entity/TeamMemberRole$Companion;
public synthetic fun <init> (Ljava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun equals (Ljava/lang/Object;)Z
public final fun getValue ()Ljava/lang/String;
public final fun hashCode ()I
public final fun toString ()Ljava/lang/String;
}

public final class dev/kord/common/entity/TeamMemberRole$Admin : dev/kord/common/entity/TeamMemberRole {
public static final field INSTANCE Ldev/kord/common/entity/TeamMemberRole$Admin;
}

public final class dev/kord/common/entity/TeamMemberRole$Companion {
public final fun from (Ljava/lang/String;)Ldev/kord/common/entity/TeamMemberRole;
public final fun getEntries ()Ljava/util/List;
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public final class dev/kord/common/entity/TeamMemberRole$Developer : dev/kord/common/entity/TeamMemberRole {
public static final field INSTANCE Ldev/kord/common/entity/TeamMemberRole$Developer;
}

public final class dev/kord/common/entity/TeamMemberRole$ReadOnly : dev/kord/common/entity/TeamMemberRole {
public static final field INSTANCE Ldev/kord/common/entity/TeamMemberRole$ReadOnly;
}

public final class dev/kord/common/entity/TeamMemberRole$Unknown : dev/kord/common/entity/TeamMemberRole {
}

public abstract class dev/kord/common/entity/TeamMembershipState {
public static final field Companion Ldev/kord/common/entity/TeamMembershipState$Companion;
public synthetic fun <init> (ILkotlin/jvm/internal/DefaultConstructorMarker;)V
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// THIS FILE IS AUTO-GENERATED, DO NOT EDIT!
@file:Suppress(names = arrayOf("IncorrectFormatting", "ReplaceArrayOfWithLiteral",
"SpellCheckingInspection", "GrazieInspection"))

package dev.kord.common.entity

import kotlin.LazyThreadSafetyMode.PUBLICATION
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

/**
* See [TeamMemberRole]s in the
* [Discord Developer Documentation](https://discord.com/developers/docs/topics/teams#team-member-roles).
*/
@Serializable(with = TeamMemberRole.Serializer::class)
public sealed class TeamMemberRole(
/**
* The raw value used by Discord.
*/
public val `value`: String,
) {
final override fun equals(other: Any?): Boolean = this === other ||
(other is TeamMemberRole && this.value == other.value)

final override fun hashCode(): Int = value.hashCode()

final override fun toString(): String =
if (this is Unknown) "TeamMemberRole.Unknown(value=$value)"
else "TeamMemberRole.${this::class.simpleName}"

/**
* An unknown [TeamMemberRole].
*
* This is used as a fallback for [TeamMemberRole]s that haven't been added to Kord yet.
*/
public class Unknown internal constructor(
`value`: String,
) : TeamMemberRole(value)

/**
* Admins have similar access as owners, except they cannot take destructive actions on the team
* or team-owned apps.
*/
public object Admin : TeamMemberRole("admin")

/**
* Developers can access information about team-owned apps, like the client secret or public
* key. They can also take limited actions on team-owned apps, like configuring interaction
* endpoints or resetting the bot token. Members with the Developer role _cannot_ manage the team
* or its members, or take destructive actions on team-owned apps.
*/
public object Developer : TeamMemberRole("developer")

/**
* Read-only members can access information about a team and any team-owned apps. Some examples
* include getting the IDs of applications and exporting payout records.
*/
public object ReadOnly : TeamMemberRole("read_only")

internal object Serializer : KSerializer<TeamMemberRole> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("dev.kord.common.entity.TeamMemberRole",
PrimitiveKind.STRING)

override fun serialize(encoder: Encoder, `value`: TeamMemberRole) {
encoder.encodeString(value.value)
}

override fun deserialize(decoder: Decoder): TeamMemberRole = from(decoder.decodeString())
}

public companion object {
/**
* A [List] of all known [TeamMemberRole]s.
*/
public val entries: List<TeamMemberRole> by lazy(mode = PUBLICATION) {
listOf(
Admin,
Developer,
ReadOnly,
)
}


/**
* Returns an instance of [TeamMemberRole] with [TeamMemberRole.value] equal to the
* specified [value].
*/
public fun from(`value`: String): TeamMemberRole = when (value) {
"admin" -> Admin
"developer" -> Developer
"read_only" -> ReadOnly
else -> Unknown(value)
}
}
}
36 changes: 29 additions & 7 deletions common/src/commonMain/kotlin/entity/Team.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
@file:Generate(
STRING_KORD_ENUM, name = "TeamMemberRole", unknownConstructorWasPublic = false,
docUrl = "https://discord.com/developers/docs/topics/teams#team-member-roles",
entries = [
Entry(
"Admin", stringValue = "admin",
kDoc = "Admins have similar access as owners, except they cannot take destructive actions on the team or " +
"team-owned apps.",
),
Entry(
"Developer", stringValue = "developer",
kDoc = "Developers can access information about team-owned apps, like the client secret or public key. " +
"They can also take limited actions on team-owned apps, like configuring interaction endpoints or " +
"resetting the bot token. Members with the Developer role _cannot_ manage the team or its members, " +
"or take destructive actions on team-owned apps.",
),
Entry(
"ReadOnly", stringValue = "read_only",
kDoc = "Read-only members can access information about a team and any team-owned apps. Some examples " +
"include getting the IDs of applications and exporting payout records.",
),
],
)

@file:Generate(
INT_KORD_ENUM, name = "TeamMembershipState",
docUrl = "https://discord.com/developers/docs/topics/teams#data-models-membership-state-enum",
Expand All @@ -11,8 +35,10 @@ package dev.kord.common.entity

import dev.kord.ksp.Generate
import dev.kord.ksp.Generate.EntityType.INT_KORD_ENUM
import dev.kord.ksp.Generate.EntityType.STRING_KORD_ENUM
import dev.kord.ksp.Generate.Entry
import kotlinx.serialization.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/**
* The raw developer team data gotten from the API.
Expand All @@ -22,6 +48,7 @@ public data class DiscordTeam(
val icon: String?,
val id: Snowflake,
val members: List<DiscordTeamMember>,
val name: String,
@SerialName("owner_user_id")
val ownerUserId: Snowflake,
)
Expand All @@ -37,12 +64,6 @@ public data class DiscordTeamMember(
*/
@SerialName("membership_state")
val membershipState: TeamMembershipState,
/**
* A collection of permissions granted to this member.
* At the moment, this collection will only have one element: `*`, meaning the member has all permissions.
* This is because right now there are no other permissions. Read mode [here](https://discord.com/developers/docs/topics/teams#data-models-team-members-object)
*/
val permissions: List<String>,
/**
* The unique ID that this member belongs to.
*/
Expand All @@ -52,4 +73,5 @@ public data class DiscordTeamMember(
* Partial user data containing only the ID, username, discriminator and avatar.
*/
val user: DiscordUser,
val role: TeamMemberRole,
)
29 changes: 21 additions & 8 deletions core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -5244,19 +5244,21 @@ public final class dev/kord/core/cache/data/StickerPackData$Companion {

public final class dev/kord/core/cache/data/TeamData {
public static final field Companion Ldev/kord/core/cache/data/TeamData$Companion;
public synthetic fun <init> (ILdev/kord/common/entity/Snowflake;Ljava/lang/String;Ljava/util/List;Ldev/kord/common/entity/Snowflake;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ljava/util/List;Ldev/kord/common/entity/Snowflake;)V
public synthetic fun <init> (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ljava/util/List;Ldev/kord/common/entity/Snowflake;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (ILdev/kord/common/entity/Snowflake;Ljava/lang/String;Ljava/util/List;Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ljava/util/List;Ldev/kord/common/entity/Snowflake;Ljava/lang/String;)V
public synthetic fun <init> (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ljava/util/List;Ldev/kord/common/entity/Snowflake;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ldev/kord/common/entity/Snowflake;
public final fun component2 ()Ljava/lang/String;
public final fun component3 ()Ljava/util/List;
public final fun component4 ()Ldev/kord/common/entity/Snowflake;
public final fun copy (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ljava/util/List;Ldev/kord/common/entity/Snowflake;)Ldev/kord/core/cache/data/TeamData;
public static synthetic fun copy$default (Ldev/kord/core/cache/data/TeamData;Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ljava/util/List;Ldev/kord/common/entity/Snowflake;ILjava/lang/Object;)Ldev/kord/core/cache/data/TeamData;
public final fun component5 ()Ljava/lang/String;
public final fun copy (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ljava/util/List;Ldev/kord/common/entity/Snowflake;Ljava/lang/String;)Ldev/kord/core/cache/data/TeamData;
public static synthetic fun copy$default (Ldev/kord/core/cache/data/TeamData;Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ljava/util/List;Ldev/kord/common/entity/Snowflake;Ljava/lang/String;ILjava/lang/Object;)Ldev/kord/core/cache/data/TeamData;
public fun equals (Ljava/lang/Object;)Z
public final fun getIcon ()Ljava/lang/String;
public final fun getId ()Ldev/kord/common/entity/Snowflake;
public final fun getMembers ()Ljava/util/List;
public final fun getName ()Ljava/lang/String;
public final fun getOwnerUserId ()Ldev/kord/common/entity/Snowflake;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
Expand All @@ -5281,12 +5283,21 @@ public final class dev/kord/core/cache/data/TeamData$Companion {

public final class dev/kord/core/cache/data/TeamMemberData {
public static final field Companion Ldev/kord/core/cache/data/TeamMemberData$Companion;
public synthetic fun <init> (ILdev/kord/common/entity/TeamMembershipState;Ljava/util/List;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> (Ldev/kord/common/entity/TeamMembershipState;Ljava/util/List;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;)V
public synthetic fun <init> (ILdev/kord/common/entity/TeamMembershipState;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/TeamMemberRole;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> (Ldev/kord/common/entity/TeamMembershipState;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/TeamMemberRole;)V
public final fun component1 ()Ldev/kord/common/entity/TeamMembershipState;
public final fun component2 ()Ldev/kord/common/entity/Snowflake;
public final fun component3 ()Ldev/kord/common/entity/Snowflake;
public final fun component4 ()Ldev/kord/common/entity/TeamMemberRole;
public final fun copy (Ldev/kord/common/entity/TeamMembershipState;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/TeamMemberRole;)Ldev/kord/core/cache/data/TeamMemberData;
public static synthetic fun copy$default (Ldev/kord/core/cache/data/TeamMemberData;Ldev/kord/common/entity/TeamMembershipState;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/TeamMemberRole;ILjava/lang/Object;)Ldev/kord/core/cache/data/TeamMemberData;
public fun equals (Ljava/lang/Object;)Z
public final fun getMembershipState ()Ldev/kord/common/entity/TeamMembershipState;
public final fun getPermissions ()Ljava/util/List;
public final fun getRole ()Ldev/kord/common/entity/TeamMemberRole;
public final fun getTeamId ()Ldev/kord/common/entity/Snowflake;
public final fun getUserId ()Ldev/kord/common/entity/Snowflake;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
public static final synthetic fun write$Self (Ldev/kord/core/cache/data/TeamMemberData;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V
}

Expand Down Expand Up @@ -7228,6 +7239,7 @@ public final class dev/kord/core/entity/Team : dev/kord/core/entity/KordEntity,
public fun getId ()Ldev/kord/common/entity/Snowflake;
public fun getKord ()Ldev/kord/core/Kord;
public final fun getMembers ()Ljava/util/List;
public final fun getName ()Ljava/lang/String;
public final fun getOwnerUserId ()Ldev/kord/common/entity/Snowflake;
public fun getSupplier ()Ldev/kord/core/supplier/EntitySupplier;
public final fun getUser (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
Expand All @@ -7243,6 +7255,7 @@ public final class dev/kord/core/entity/TeamMember {
public final fun getKord ()Ldev/kord/core/Kord;
public final fun getMembershipState ()Ldev/kord/common/entity/TeamMembershipState;
public final fun getPermissions ()Ljava/util/List;
public final fun getRole ()Ldev/kord/common/entity/TeamMemberRole;
public final fun getTeamId ()Ldev/kord/common/entity/Snowflake;
public final fun getUser (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun getUserId ()Ldev/kord/common/entity/Snowflake;
Expand Down
Loading

0 comments on commit a1eb5f7

Please sign in to comment.