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

Add avatar_decoration to user #852

Merged
merged 4 commits into from
Aug 3, 2023
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
12 changes: 7 additions & 5 deletions common/api/common.api
Original file line number Diff line number Diff line change
Expand Up @@ -5983,9 +5983,9 @@ public final class dev/kord/common/entity/DiscordUpdatedGuildMember$Companion {

public final class dev/kord/common/entity/DiscordUser {
public static final field Companion Ldev/kord/common/entity/DiscordUser$Companion;
public synthetic fun <init> (ILdev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;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/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ljava/lang/Integer;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;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/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ljava/lang/Integer;)V
public synthetic fun <init> (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;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/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ljava/lang/Integer;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (ILdev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;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/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ljava/lang/Integer;Ldev/kord/common/entity/optional/Optional;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;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/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ljava/lang/Integer;Ldev/kord/common/entity/optional/Optional;)V
public synthetic fun <init> (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;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/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ljava/lang/Integer;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/OptionalBoolean;
public final fun component11 ()Ldev/kord/common/entity/optional/Optional;
Expand All @@ -5994,6 +5994,7 @@ public final class dev/kord/common/entity/DiscordUser {
public final fun component14 ()Ldev/kord/common/entity/optional/Optional;
public final fun component15 ()Ljava/lang/String;
public final fun component16 ()Ljava/lang/Integer;
public final fun component17 ()Ldev/kord/common/entity/optional/Optional;
public final fun component2 ()Ljava/lang/String;
public final fun component3 ()Ldev/kord/common/entity/optional/Optional;
public final fun component4 ()Ldev/kord/common/entity/optional/Optional;
Expand All @@ -6002,11 +6003,12 @@ public final class dev/kord/common/entity/DiscordUser {
public final fun component7 ()Ldev/kord/common/entity/optional/OptionalBoolean;
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;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;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/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ljava/lang/Integer;)Ldev/kord/common/entity/DiscordUser;
public static synthetic fun copy$default (Ldev/kord/common/entity/DiscordUser;Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;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/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ljava/lang/Integer;ILjava/lang/Object;)Ldev/kord/common/entity/DiscordUser;
public final fun copy (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;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/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ljava/lang/Integer;Ldev/kord/common/entity/optional/Optional;)Ldev/kord/common/entity/DiscordUser;
public static synthetic fun copy$default (Ldev/kord/common/entity/DiscordUser;Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/OptionalBoolean;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/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ljava/lang/Integer;Ldev/kord/common/entity/optional/Optional;ILjava/lang/Object;)Ldev/kord/common/entity/DiscordUser;
public fun equals (Ljava/lang/Object;)Z
public final fun getAccentColor ()Ljava/lang/Integer;
public final fun getAvatar ()Ljava/lang/String;
public final fun getAvatarDecoration ()Ldev/kord/common/entity/optional/Optional;
public final fun getBanner ()Ljava/lang/String;
public final fun getBot ()Ldev/kord/common/entity/optional/OptionalBoolean;
public final fun getDiscriminator ()Ldev/kord/common/entity/optional/Optional;
Expand Down
7 changes: 6 additions & 1 deletion common/src/commonMain/kotlin/entity/DiscordUser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ import kotlin.contracts.contract
* @param flags The flags on a user's account. Unlike [publicFlags], these **are not** visible to other users.
* @param premiumType The type of Nitro subscription on a user's account.
* @param publicFlags The public flags on a user's account. Unlike [flags], these **are** visible ot other users.
* @param banner The user's banner hash.
* @param accentColor The user's banner color encoded as an integer representation of hexadecimal color code
* @param avatarDecoration The user's avatar decoration hash.
*/
@Serializable
public data class DiscordUser(
Expand Down Expand Up @@ -75,7 +78,9 @@ public data class DiscordUser(
val publicFlags: Optional<UserFlags> = Optional.Missing(),
val banner: String? = null,
@SerialName("accent_color")
val accentColor: Int? = null
val accentColor: Int? = null,
@SerialName("avatar_decoration")
val avatarDecoration: Optional<String?> = Optional.Missing(),
)

/**
Expand Down
15 changes: 10 additions & 5 deletions core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -5456,10 +5456,11 @@ public final class dev/kord/core/cache/data/ThreadMetadataData$Companion {

public final class dev/kord/core/cache/data/UserData {
public static final field Companion Ldev/kord/core/cache/data/UserData$Companion;
public synthetic fun <init> (ILdev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ljava/lang/Integer;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ljava/lang/Integer;)V
public synthetic fun <init> (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ljava/lang/Integer;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (ILdev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ljava/lang/Integer;Ldev/kord/common/entity/optional/Optional;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ljava/lang/Integer;Ldev/kord/common/entity/optional/Optional;)V
public synthetic fun <init> (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ljava/lang/Integer;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 ()Ljava/lang/String;
public final fun component3 ()Ldev/kord/common/entity/optional/Optional;
public final fun component4 ()Ldev/kord/common/entity/optional/Optional;
Expand All @@ -5468,11 +5469,12 @@ public final class dev/kord/core/cache/data/UserData {
public final fun component7 ()Ldev/kord/common/entity/optional/Optional;
public final fun component8 ()Ljava/lang/String;
public final fun component9 ()Ljava/lang/Integer;
public final fun copy (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ljava/lang/Integer;)Ldev/kord/core/cache/data/UserData;
public static synthetic fun copy$default (Ldev/kord/core/cache/data/UserData;Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ljava/lang/Integer;ILjava/lang/Object;)Ldev/kord/core/cache/data/UserData;
public final fun copy (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ljava/lang/Integer;Ldev/kord/common/entity/optional/Optional;)Ldev/kord/core/cache/data/UserData;
public static synthetic fun copy$default (Ldev/kord/core/cache/data/UserData;Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ldev/kord/common/entity/optional/OptionalBoolean;Ldev/kord/common/entity/optional/Optional;Ljava/lang/String;Ljava/lang/Integer;Ldev/kord/common/entity/optional/Optional;ILjava/lang/Object;)Ldev/kord/core/cache/data/UserData;
public fun equals (Ljava/lang/Object;)Z
public final fun getAccentColor ()Ljava/lang/Integer;
public final fun getAvatar ()Ljava/lang/String;
public final fun getAvatarDecoration ()Ldev/kord/common/entity/optional/Optional;
public final fun getBanner ()Ljava/lang/String;
public final fun getBot ()Ldev/kord/common/entity/optional/OptionalBoolean;
public final fun getDiscriminator ()Ldev/kord/common/entity/optional/Optional;
Expand Down Expand Up @@ -5794,6 +5796,7 @@ public final class dev/kord/core/entity/Asset$Companion {
public final fun stickerPackBanner (Ldev/kord/common/entity/Snowflake;Ldev/kord/core/Kord;)Ldev/kord/core/entity/Asset;
public final fun teamIcon (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/core/Kord;)Ldev/kord/core/entity/Asset;
public final fun userAvatar (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/core/Kord;)Ldev/kord/core/entity/Asset;
public final fun userAvatarDecoration (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/core/Kord;)Ldev/kord/core/entity/Asset;
public final fun userBanner (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/core/Kord;)Ldev/kord/core/entity/Asset;
}

Expand Down Expand Up @@ -7195,6 +7198,8 @@ public class dev/kord/core/entity/User : dev/kord/core/behavior/UserBehavior {
public final fun getAccentColor ()Ldev/kord/common/Color;
public final fun getAvatar ()Ldev/kord/core/entity/Asset;
public final synthetic fun getAvatar ()Ldev/kord/core/entity/Icon;
public final fun getAvatarDecoration ()Ldev/kord/core/entity/Asset;
public final fun getAvatarDecorationHash ()Ljava/lang/String;
public final fun getAvatarHash ()Ljava/lang/String;
public final fun getBanner ()Ldev/kord/core/entity/Asset;
public final fun getBannerHash ()Ljava/lang/String;
Expand Down
5 changes: 3 additions & 2 deletions core/src/commonMain/kotlin/cache/data/UserData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public data class UserData(
val bot: OptionalBoolean = OptionalBoolean.Missing,
val publicFlags: Optional<UserFlags> = Optional.Missing(),
val banner: String? = null,
val accentColor: Int? = null
val accentColor: Int? = null,
val avatarDecoration: Optional<String?> = Optional.Missing()
) {
public companion object {

Expand All @@ -40,7 +41,7 @@ public data class UserData(
}

public fun from(entity: DiscordUser): UserData = with(entity) {
UserData(id, username, @Suppress("DEPRECATION") discriminator, globalName, avatar, bot, publicFlags, banner, accentColor)
UserData(id, username, @Suppress("DEPRECATION") discriminator, globalName, avatar, bot, publicFlags, banner, accentColor, avatarDecoration)
}

public fun from(entity: DiscordOptionallyMemberUser): UserData = with(entity) {
Expand Down
4 changes: 4 additions & 0 deletions core/src/commonMain/kotlin/entity/Asset.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public class Asset private constructor(
public fun memberAvatar(guildId: Snowflake, userId: Snowflake, hash: String, kord: Kord): Asset =
Asset(hash.isAnimated, DiscordCdn.memberAvatar(guildId, userId, hash), kord)

// https://github.com/discord/discord-api-docs/pull/5723#issuecomment-1342674515
public fun userAvatarDecoration(userId: Snowflake, hash: String, kord: Kord): Asset =
Asset(hash.isAnimated, DiscordCdn.userAvatarDecoration(userId, hash), kord, recommendedFormat = PNG)

public fun applicationIcon(applicationId: Snowflake, hash: String, kord: Kord): Asset =
Asset(isAnimated = false, DiscordCdn.applicationIcon(applicationId, hash), kord)

Expand Down
4 changes: 4 additions & 0 deletions core/src/commonMain/kotlin/entity/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public open class User(
if (migratedToNewUsernameSystem) Asset.defaultUserAvatar(userId = id, kord)
else @Suppress("DEPRECATION") Asset.defaultUserAvatar(discriminator.toInt(), kord)

public val avatarDecorationHash: String? get() = data.avatarDecoration.value

public val avatarDecoration: Asset? get() = avatarDecorationHash?.let { Asset.userAvatarDecoration(data.id, it, kord) }

/**
* The username of this user.
*/
Expand Down
1 change: 1 addition & 0 deletions rest/api/rest.api
Original file line number Diff line number Diff line change
Expand Up @@ -6219,6 +6219,7 @@ public final class dev/kord/rest/route/DiscordCdn {
public final fun stickerPackBanner (Ldev/kord/common/entity/Snowflake;)Ldev/kord/rest/route/CdnUrl;
public final fun teamIcon (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;)Ldev/kord/rest/route/CdnUrl;
public final fun userAvatar (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;)Ldev/kord/rest/route/CdnUrl;
public final fun userAvatarDecoration (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;)Ldev/kord/rest/route/CdnUrl;
public final fun userBanner (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;)Ldev/kord/rest/route/CdnUrl;
}

Expand Down
3 changes: 3 additions & 0 deletions rest/src/commonMain/kotlin/route/DiscordCdn.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public object DiscordCdn {
public fun memberAvatar(guildId: Snowflake, userId: Snowflake, hash: String): CdnUrl =
CdnUrl("$BASE_URL/guilds/$guildId/users/$userId/avatars/$hash")

public fun userAvatarDecoration(userId: Snowflake, hash: String): CdnUrl =
CdnUrl("$BASE_URL/avatar-decorations/$userId/$hash")

public fun applicationIcon(applicationId: Snowflake, hash: String): CdnUrl =
CdnUrl("$BASE_URL/app-icons/$applicationId/$hash")

Expand Down