From 14e76fb7c5fa36b2f3e8da8dfe407429e5c8286c Mon Sep 17 00:00:00 2001 From: MrPowerGamerBR Date: Thu, 31 Oct 2024 12:04:14 -0300 Subject: [PATCH] Fix ID tie breaker, show how much time the user took to finish the event, show the event title in the rank command --- .../vanilla/reactionevents/EventCommand.kt | 20 +++++++++++++------ .../loritta/morenitta/utils/DateUtils.kt | 7 +++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/vanilla/reactionevents/EventCommand.kt b/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/vanilla/reactionevents/EventCommand.kt index 57df2dc466..53a45f1c94 100644 --- a/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/vanilla/reactionevents/EventCommand.kt +++ b/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/vanilla/reactionevents/EventCommand.kt @@ -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 @@ -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())) @@ -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() @@ -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() @@ -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()) + } + } ) } ) { diff --git a/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/utils/DateUtils.kt b/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/utils/DateUtils.kt index 68c8c7fc8e..6cd0ac3638 100644 --- a/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/utils/DateUtils.kt +++ b/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/utils/DateUtils.kt @@ -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