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

support user banners #352

Merged
merged 1 commit into from
Jul 28, 2021
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
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