Skip to content

Commit

Permalink
Use the background used for the default layout when generating the rank
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPowerGamerBR committed Nov 16, 2024
1 parent ac9f625 commit 79a63b4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ class ProfileDesignManager(val loritta: LorittaBot) {
* @param id the user's ID
* @return the background image
*/
suspend fun getUserProfileBackground(id: Long) = getUserProfileBackground(loritta.getOrCreateLorittaProfile(id))
suspend fun getUserProfileBackground(id: Long, profileDesignInternalNameOverride: String? = null) = getUserProfileBackground(loritta.getOrCreateLorittaProfile(id), profileDesignInternalNameOverride)

/**
* Gets an user's profile background image or, if the user has a custom background, loads the custom background.
Expand All @@ -526,8 +526,8 @@ class ProfileDesignManager(val loritta: LorittaBot) {
* @param background the user's background
* @return the background image
*/
suspend fun getUserProfileBackground(profile: PuddingUserProfile): BufferedImage {
val backgroundUrl = getUserProfileBackgroundUrl(profile)
suspend fun getUserProfileBackground(profile: PuddingUserProfile, profileDesignInternalNameOverride: String? = null): BufferedImage {
val backgroundUrl = getUserProfileBackgroundUrl(profile, profileDesignInternalNameOverride)
val response = loritta.http.get(backgroundUrl) {
userAgent(loritta.lorittaCluster.getUserAgent(this@ProfileDesignManager.loritta))
}
Expand All @@ -546,8 +546,8 @@ class ProfileDesignManager(val loritta: LorittaBot) {
* @param background the user's background
* @return the background image
*/
suspend fun getUserProfileBackground(profile: Profile): BufferedImage {
val backgroundUrl = getUserProfileBackgroundUrl(profile)
suspend fun getUserProfileBackground(profile: Profile, profileDesignInternalNameOverride: String? = null): BufferedImage {
val backgroundUrl = getUserProfileBackgroundUrl(profile, profileDesignInternalNameOverride)
val response = loritta.http.get(backgroundUrl) {
userAgent(loritta.lorittaCluster.getUserAgent(this@ProfileDesignManager.loritta))
}
Expand All @@ -567,8 +567,8 @@ class ProfileDesignManager(val loritta: LorittaBot) {
* @param profileCreator the profile creator being used, overrides the [ProfileSettings.activeProfileDesign] option
* @return the background image
*/
suspend fun getUserProfileBackground(profile: Profile, profileCreator: ProfileCreator): BufferedImage {
val backgroundUrl = getUserProfileBackgroundUrl(profile, profileCreator)
suspend fun getUserProfileBackground(profile: Profile, profileCreator: ProfileCreator, profileDesignInternalNameOverride: String? = null): BufferedImage {
val backgroundUrl = getUserProfileBackgroundUrl(profile, profileCreator, profileDesignInternalNameOverride)
val response = loritta.http.get(backgroundUrl) {
userAgent(loritta.lorittaCluster.getUserAgent(this@ProfileDesignManager.loritta))
}
Expand All @@ -594,7 +594,7 @@ class ProfileDesignManager(val loritta: LorittaBot) {
* @param profile the user's profile
* @return the background image
*/
suspend fun getUserProfileBackgroundUrl(profile: Profile): String {
suspend fun getUserProfileBackgroundUrl(profile: Profile, profileDesignInternalNameOverride: String? = null): String {
// This is bad
val (settingsId, activeProfileDesignInternalName, activeBackgroundInternalName) = loritta.newSuspendedTransaction {
val settingsId = profile.settings.id.value
Expand All @@ -604,7 +604,7 @@ class ProfileDesignManager(val loritta: LorittaBot) {
Triple(settingsId, activeProfileDesignInternalName, activeBackgroundInternalName)
}

return getUserProfileBackgroundUrl(profile.userId, settingsId, activeProfileDesignInternalName ?: ProfileDesign.DEFAULT_PROFILE_DESIGN_ID, activeBackgroundInternalName ?: Background.DEFAULT_BACKGROUND_ID)
return getUserProfileBackgroundUrl(profile.userId, settingsId, profileDesignInternalNameOverride ?: activeProfileDesignInternalName ?: ProfileDesign.DEFAULT_PROFILE_DESIGN_ID, activeBackgroundInternalName ?: Background.DEFAULT_BACKGROUND_ID)
}

/**
Expand All @@ -616,7 +616,7 @@ class ProfileDesignManager(val loritta: LorittaBot) {
* @param profileCreator the profile creator being used, overrides the [ProfileSettings.activeProfileDesign] option
* @return the background image
*/
suspend fun getUserProfileBackgroundUrl(profile: Profile, profileCreator: ProfileCreator): String {
suspend fun getUserProfileBackgroundUrl(profile: Profile, profileCreator: ProfileCreator, profileDesignInternalNameOverride: String? = null): String {
// This is bad
val (settingsId, _, activeBackgroundInternalName) = loritta.newSuspendedTransaction {
val settingsId = profile.settings.id.value
Expand All @@ -626,7 +626,7 @@ class ProfileDesignManager(val loritta: LorittaBot) {
Triple(settingsId, activeProfileDesignInternalName, activeBackgroundInternalName)
}

return getUserProfileBackgroundUrl(profile.userId, settingsId, profileCreator.internalName, activeBackgroundInternalName ?: Background.DEFAULT_BACKGROUND_ID)
return getUserProfileBackgroundUrl(profile.userId, settingsId, profileCreator.internalName, profileDesignInternalNameOverride ?: activeBackgroundInternalName ?: Background.DEFAULT_BACKGROUND_ID)
}

/**
Expand All @@ -637,12 +637,11 @@ class ProfileDesignManager(val loritta: LorittaBot) {
* @param profile the user's profile
* @return the background image
*/
suspend fun getUserProfileBackgroundUrl(profile: PuddingUserProfile): String {
suspend fun getUserProfileBackgroundUrl(profile: PuddingUserProfile, profileDesignInternalNameOverride: String? = null): String {
val profileSettings = profile.getProfileSettings()
val activeProfileDesignInternalName = profileSettings.activeProfileDesign
val activeBackgroundInternalName = profileSettings.activeBackground
// TODO: Fix default profile design ID
return getUserProfileBackgroundUrl(profile.id.value.toLong(), profileSettings.id, activeProfileDesignInternalName ?: ProfileDesign.DEFAULT_PROFILE_DESIGN_ID, activeBackgroundInternalName ?: Background.DEFAULT_BACKGROUND_ID)
return getUserProfileBackgroundUrl(profile.id.value.toLong(), profileSettings.id, profileDesignInternalNameOverride ?: activeProfileDesignInternalName ?: ProfileDesign.DEFAULT_PROFILE_DESIGN_ID, activeBackgroundInternalName ?: Background.DEFAULT_BACKGROUND_ID)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.perfectdreams.loritta.morenitta.utils
import net.perfectdreams.loritta.cinnamon.discord.utils.images.*
import net.perfectdreams.loritta.cinnamon.discord.utils.images.ImageUtils
import net.perfectdreams.loritta.morenitta.LorittaBot
import net.perfectdreams.loritta.morenitta.dao.ProfileDesign
import java.awt.Color
import java.awt.Graphics2D
import java.awt.Rectangle
Expand Down Expand Up @@ -56,7 +57,7 @@ object RankingGenerator {
val member = loritta.lorittaShards.retrieveUserInfoById(profile.userId) ?: onNullUser?.invoke(profile.userId)

if (member != null) {
val rankBackground = loritta.profileDesignManager.getUserProfileBackground(member.id)
val rankBackground = loritta.profileDesignManager.getUserProfileBackground(member.id, ProfileDesign.DEFAULT_PROFILE_DESIGN_ID)
graphics.drawImage(rankBackground.getResizedInstance(800, 600, InterpolationType.BILINEAR)
.getSubimage(0, idx * 104, 800, 106), 0, currentY, null)

Expand Down

0 comments on commit 79a63b4

Please sign in to comment.