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

Check if user is active when giving boost rewards #2381

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.perfectdreams.loritta.utils.daily

enum class DailyGuildMissingRequirement {
USER_NOT_MEMBER,
REQUIRES_MORE_TIME,
REQUIRES_MORE_XP
}
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,24 @@ class GetLoriDailyRewardRoute(loritta: LorittaDiscord) : RequiresAPIDiscordLogin
?: continue
val id = guild.id.toLong()

val jdaUser = lorittaShards.getUserById(userIdentification.id.toLong())
val jdaGuild = lorittaShards.getGuildById(id)

if (jdaUser?.let { jdaGuild?.isMember(it) } == false) {
failedDailyServersInfo.add(
jsonObject(
"guild" to jsonObject(
"name" to guild.name,
"iconUrl" to guild.icon,
"id" to guild.id
),
"type" to DailyGuildMissingRequirement.USER_NOT_MEMBER.toString(),
"multiplier" to getDailyMultiplier(donationValue)
)
)
continue
}

val xp = GuildProfile.find { (GuildProfiles.guildId eq id) and (GuildProfiles.userId eq userIdentification.id.toLong()) }.firstOrNull()?.xp
?: 0L

Expand All @@ -320,8 +338,8 @@ class GetLoriDailyRewardRoute(loritta: LorittaDiscord) : RequiresAPIDiscordLogin
"iconUrl" to guild.icon,
"id" to guild.id
),
"type" to DailyGuildMissingRequirement.REQUIRES_MORE_XP.toString(),
"data" to 500 - xp,
"type" to DailyGuildMissingRequirement.REQUIRES_MORE_XP.toString(),
"multiplier" to getDailyMultiplier(donationValue)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ object NitroBoostUtils {
logger.info { "Guild $guild has donation features enabled! Giving sonhos to $boosters" }

loritta.newSuspendedTransaction {
Profiles.update({ Profiles.id inList boosters.map { it.user.idLong } }) {
Profiles.update({ Profiles.id inList boosters.filter { guild.isMember(it.user) }.map { it.user.idLong } }) {
with(SqlExpressionBuilder) {
it.update(money, money + 2)
it.update(money, money + 4)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,10 @@ class DailyRoute(val m: SpicyMorenitta) : UpdateNavbarSizePostRender("/daily") {
DailyGuildMissingRequirement.REQUIRES_MORE_XP -> {
+"sendo mais ativo em "
}
DailyGuildMissingRequirement.USER_NOT_MEMBER -> {
+"ou entrando novamente em "
}
}

+failedGuild.guild.name
+"!"
}
Expand Down