Skip to content

Commit

Permalink
support user banners (#352)
Browse files Browse the repository at this point in the history
  • Loading branch information
HopeBaron authored Jul 28, 2021
1 parent 5fc2f8d commit df81cb2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions common/src/main/kotlin/entity/DiscordUser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ data class DiscordUser(
val premiumType: Optional<UserPremium> = Optional.Missing(),
@SerialName("public_flags")
val publicFlags: Optional<UserFlags> = Optional.Missing(),
val banner: String? = null,
@SerialName("accent_color")
val accentColor: Int? = null
)

/**
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/kotlin/cache/data/UserData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import dev.kord.common.entity.UserFlags
import dev.kord.common.entity.optional.Optional
import dev.kord.common.entity.optional.OptionalBoolean
import dev.kord.gateway.DiscordInviteUser
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

private val WebhookData.nullableUserId get() = userId.value
Expand All @@ -20,6 +21,8 @@ data class UserData(
val avatar: String? = null,
val bot: OptionalBoolean = OptionalBoolean.Missing,
val publicFlags: Optional<UserFlags> = Optional.Missing(),
val banner: String? = null,
val accentColor: Int? = null
) {
companion object {

Expand All @@ -32,7 +35,7 @@ data class UserData(
}

fun from(entity: DiscordUser) = with(entity) {
UserData(id, username, discriminator, avatar, bot, publicFlags)
UserData(id, username, discriminator, avatar, bot, publicFlags, banner, accentColor)
}

fun from(entity: DiscordInviteUser) = with(entity) {
Expand Down
7 changes: 7 additions & 0 deletions core/src/main/kotlin/entity/User.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.kord.core.entity

import dev.kord.common.Color
import dev.kord.common.annotation.DeprecatedSinceKord
import dev.kord.common.entity.Snowflake
import dev.kord.common.entity.UserFlags
Expand Down Expand Up @@ -66,6 +67,12 @@ open class User(
*/
val isBot: Boolean get() = data.bot.discordBoolean

val accentColor: Color? get() = data.accentColor?.let { Color(it) }

fun getBannerUrl(format: Image.Format): String? =
data.banner?.let { "https://cdn.discordapp.com/banners/${id.asString}/$it.${format.extension}" }


override fun hashCode(): Int = id.hashCode()

override fun equals(other: Any?): Boolean = when (other) {
Expand Down

0 comments on commit df81cb2

Please sign in to comment.