Skip to content

Commit

Permalink
Fix ID tie breaker, show how much time the user took to finish the ev…
Browse files Browse the repository at this point in the history
…ent, show the event title in the rank command
  • Loading branch information
MrPowerGamerBR committed Oct 31, 2024
1 parent d63aee7 commit 14e76fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import net.perfectdreams.loritta.morenitta.interactions.vanilla.economy.SonhosCo
import net.perfectdreams.loritta.morenitta.reactionevents.ReactionEvent
import net.perfectdreams.loritta.morenitta.reactionevents.ReactionEventReward
import net.perfectdreams.loritta.morenitta.reactionevents.ReactionEventsAttributes
import net.perfectdreams.loritta.morenitta.utils.DateUtils
import net.perfectdreams.loritta.morenitta.utils.RankingGenerator
import net.perfectdreams.loritta.morenitta.utils.extensions.await
import net.perfectdreams.loritta.morenitta.utils.extensions.toJDA
Expand Down Expand Up @@ -721,6 +722,7 @@ class EventCommand(val loritta: LorittaBot) : SlashCommandDeclarationWrapper {
ReactionEventRankType.FINISHED_FIRST -> {
val totalCount = CraftedReactionEventItems
.innerJoin(ReactionEventPlayers)
.innerJoin(ReactionEventFinishedEventUsers)
.select(CraftedReactionEventItems.user)
.where {
CraftedReactionEventItems.event eq event.internalId and (ReactionEventPlayers.userId notInSubQuery UsersService.validBannedUsersList(System.currentTimeMillis()))
Expand All @@ -735,7 +737,7 @@ class EventCommand(val loritta: LorittaBot) : SlashCommandDeclarationWrapper {
.where {
CraftedReactionEventItems.event eq event.internalId and (ReactionEventPlayers.userId notInSubQuery UsersService.validBannedUsersList(System.currentTimeMillis()))
}
.groupBy(ReactionEventPlayers.userId)
.groupBy(ReactionEventPlayers.userId, ReactionEventPlayers.id)
.orderBy(minFinishedAtColumn to SortOrder.ASC, ReactionEventPlayers.id to SortOrder.ASC)
.limit(5, page * 5)
.toList()
Expand All @@ -760,7 +762,7 @@ class EventCommand(val loritta: LorittaBot) : SlashCommandDeclarationWrapper {
.where {
CraftedReactionEventItems.event eq event.internalId and (ReactionEventPlayers.userId notInSubQuery UsersService.validBannedUsersList(System.currentTimeMillis()))
}
.groupBy(ReactionEventPlayers.userId)
.groupBy(ReactionEventPlayers.userId, ReactionEventPlayers.id)
.orderBy(countColumn to SortOrder.DESC, minFinishedAtColumn to SortOrder.ASC, ReactionEventPlayers.id to SortOrder.ASC)
.limit(5, page * 5)
.toList()
Expand All @@ -778,15 +780,21 @@ class EventCommand(val loritta: LorittaBot) : SlashCommandDeclarationWrapper {
RankingGenerator.generateRanking(
loritta,
page * 5,
"Evento",
event.createEventTitle(context.i18nContext),
null,
profiles.map {
val presentesCount = it[countColumn]

RankingGenerator.UserRankInformation(
it[ReactionEventPlayers.userId]
,
event.createShortCraftedItemMessage(context.i18nContext, presentesCount.toInt())
it[ReactionEventPlayers.userId],
when (rankType) {
ReactionEventRankType.FINISHED_FIRST -> {
DateUtils.formatDateDiff(context.i18nContext, event.startsAt, it[minFinishedAtColumn]!!)
}
ReactionEventRankType.TOTAL_CRAFTED_ITEMS -> {
event.createShortCraftedItemMessage(context.i18nContext, presentesCount.toInt())
}
}
)
}
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ object DateUtils {
maxParts
)

fun formatDateDiff(i18nContext: I18nContext, fromEpochMilli: Instant, toEpochMilli: Instant, maxParts: Int = Int.MAX_VALUE) = formatDateDiff(
i18nContext,
LocalDateTime.ofInstant(fromEpochMilli, Constants.LORITTA_TIMEZONE),
LocalDateTime.ofInstant(toEpochMilli, Constants.LORITTA_TIMEZONE),
maxParts
)

fun formatDateDiff(i18nContext: I18nContext, argumentFromDateTime: LocalDateTime, argumentToDateTime: LocalDateTime, maxParts: Int = Int.MAX_VALUE): String {
// https://stackoverflow.com/a/59119149/7271796
val fromDateTime: LocalDateTime
Expand Down

0 comments on commit 14e76fb

Please sign in to comment.