Skip to content

Commit

Permalink
Add LoriCoolCards event upsell
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPowerGamerBR committed Oct 31, 2024
1 parent f064b72 commit fb83473
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ object Emotes {
val LoriPunch = DiscordEmote(731871119400894525L, "lori_fight", true)
val LoriSleeping = DiscordEmote(964701978091470919L, "lori_zz", false)
val LoriAngel = DiscordEmote(964701052324675622L, "lori_angel", false)
val LoriDemon = DiscordEmote(964699688429297664L, "lori_demon", false)
val LoriShining =
DiscordEmote(956403919590944778L, "lori_nem_ligo", false)
val LoriMegaphone =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class CommandMentions(private val registeredCommands: List<DiscordCommand>) {
val verifyMessageUrl = commandMention("verificarmensagem url")
val verifyMessageFile = commandMention("verificarmensagem arquivo")

val loriCoolCardsBuy = commandMention("figurittas comprar")
val loriCoolCardsStick = commandMention("figurittas colar")

/**
* Creates a command mention of [path]. If the command doesn't exist, an error will be thrown.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dev.minn.jda.ktx.messages.InlineMessage
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toInstant
import kotlinx.datetime.toKotlinLocalDateTime
import kotlinx.serialization.json.Json
import net.dv8tion.jda.api.entities.Guild
import net.dv8tion.jda.api.interactions.components.buttons.Button
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle
Expand All @@ -13,27 +14,32 @@ import net.perfectdreams.loritta.cinnamon.discord.interactions.commands.styled
import net.perfectdreams.loritta.cinnamon.emotes.Emotes
import net.perfectdreams.loritta.cinnamon.pudding.entities.PuddingUserProfile
import net.perfectdreams.loritta.cinnamon.pudding.tables.EconomyState
import net.perfectdreams.loritta.cinnamon.pudding.tables.loricoolcards.LoriCoolCardsEvents
import net.perfectdreams.loritta.common.utils.GACampaigns
import net.perfectdreams.loritta.i18n.I18nKeysData
import net.perfectdreams.loritta.morenitta.LorittaBot
import net.perfectdreams.loritta.morenitta.commands.CommandContext
import net.perfectdreams.loritta.morenitta.interactions.CommandContextCompat
import net.perfectdreams.loritta.morenitta.interactions.UnleashedContext
import net.perfectdreams.loritta.morenitta.loricoolcards.StickerAlbumTemplate
import net.perfectdreams.loritta.morenitta.platform.discord.legacy.commands.DiscordCommandContext
import net.perfectdreams.loritta.morenitta.reactionevents.ReactionEvent
import net.perfectdreams.loritta.morenitta.reactionevents.ReactionEventReward
import net.perfectdreams.loritta.morenitta.utils.Constants
import net.perfectdreams.loritta.morenitta.utils.extensions.toJDA
import net.perfectdreams.loritta.morenitta.website.routes.user.dashboard.ClaimedWebsiteCoupon
import net.perfectdreams.loritta.serializable.UserId
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.select
import java.time.DayOfWeek
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.ZoneId
import org.jetbrains.exposed.sql.selectAll
import java.time.*
import java.time.temporal.TemporalAdjusters
import java.util.*

object SonhosUtils {
private val UPSELL_LORICOOLCARDS_AFTER = ZonedDateTime.of(2024, 11, 1, 0, 0, 0, 0, Constants.LORITTA_TIMEZONE)
private val UPSELL_LORICOOLCARDS_AFTER_INSTANT = UPSELL_LORICOOLCARDS_AFTER.toInstant()

val DISABLED_ECONOMY_ID = UUID.fromString("3da6d95b-edb4-4ae9-aa56-4b13e91f3844")

val HANGLOOSE_EMOTES = listOf(
Expand Down Expand Up @@ -128,6 +134,109 @@ object SonhosUtils {
}
}

suspend fun createActiveLoriCoolCardsEventUpsellInformationIfNotNull(
loritta: LorittaBot,
i18nContext: I18nContext
): Button? {
val now = Instant.now()

// TODO: Remove this later!
if (now.isBefore(UPSELL_LORICOOLCARDS_AFTER_INSTANT))
return null

val activeLoriCoolCardsEvent = loritta.transaction {
LoriCoolCardsEvents.selectAll()
.where {
LoriCoolCardsEvents.startsAt lessEq now and (LoriCoolCardsEvents.endsAt greater now)
}
.firstOrNull()
}

val nowZDT = ZonedDateTime.ofInstant(now, Constants.LORITTA_TIMEZONE)
val lastDayOfTheMonth = nowZDT.with(TemporalAdjusters.lastDayOfMonth()).dayOfMonth

if (activeLoriCoolCardsEvent != null) {
// First 7 days
val notifyUser = 7 >= nowZDT.dayOfMonth || nowZDT.dayOfMonth >= lastDayOfTheMonth - 3
if (notifyUser) {
val template = Json.decodeFromString<StickerAlbumTemplate>(activeLoriCoolCardsEvent[LoriCoolCardsEvents.template])

return loritta.interactivityManager.button(
ButtonStyle.SECONDARY,
i18nContext.get(I18nKeysData.Commands.LoriCoolCardsEvent.EventStarted.ButtonLabel),
{
this.loriEmoji = Emotes.LoriCoolSticker
}
) { context ->
context.reply(true) {
styled(
i18nContext.get(
I18nKeysData.Commands.LoriCoolCardsEvent.EventStarted.EventUpsell1(
activeLoriCoolCardsEvent[LoriCoolCardsEvents.eventName],
)
),
Emotes.LoriCoolSticker
)

styled(
i18nContext.get(
I18nKeysData.Commands.LoriCoolCardsEvent.EventStarted.EventUpsell2(
SonhosUtils.getSonhosEmojiOfQuantity(template.sonhosReward),
template.sonhosReward,
TimeFormat.DATE_TIME_SHORT.format(activeLoriCoolCardsEvent[LoriCoolCardsEvents.endsAt])
)
),
Emotes.Sonhos3
)

styled(
i18nContext.get(
I18nKeysData.Commands.LoriCoolCardsEvent.EventStarted.EventUpsell3(
loritta.commandMentions.loriCoolCardsBuy,
loritta.commandMentions.loriCoolCardsStick,
"<https://discord.gg/loritta>"
)
),
Emotes.LoriLurk
)
}
}
}
} else if (nowZDT.dayOfMonth == 1 || nowZDT.dayOfMonth == lastDayOfTheMonth) {
return loritta.interactivityManager.button(
ButtonStyle.SECONDARY,
i18nContext.get(I18nKeysData.Commands.LoriCoolCardsEvent.PreEvent.ButtonLabel),
{
this.loriEmoji = Emotes.StickerRarityLegendary
}
) { context ->
context.reply(true) {
styled(
i18nContext.get(I18nKeysData.Commands.LoriCoolCardsEvent.PreEvent.EventUpsell1),
Emotes.LoriLurk
)

styled(
i18nContext.get(I18nKeysData.Commands.LoriCoolCardsEvent.PreEvent.EventUpsell2),
Emotes.StickerRarityLegendary
)

styled(
i18nContext.get(I18nKeysData.Commands.LoriCoolCardsEvent.PreEvent.EventUpsell3("<https://discord.gg/loritta>")),
Emotes.Sonhos3
)

styled(
i18nContext.get(I18nKeysData.Commands.LoriCoolCardsEvent.PreEvent.EventUpsell4),
Emotes.LoriDemon
)
}
}
}

return null
}

suspend fun InlineMessage<*>.appendUserHaventGotDailyTodayOrUpsellSonhosBundles(
loritta: LorittaBot,
i18nContext: I18nContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,11 @@ class EmojiFight(
}

if (entryPrice != null) {
val loriCoolCardsUpsellButton = SonhosUtils.createActiveLoriCoolCardsEventUpsellInformationIfNotNull(
loritta,
context.i18nContext
)

val tax = (realPrize - taxedRealPrize)

// If the tax == 0, then it means that the user is premium!
Expand Down Expand Up @@ -585,6 +590,9 @@ class EmojiFight(
ReactionEventsAttributes.getActiveEvent(Instant.now())
)?.let { buttons += it }

if (loriCoolCardsUpsellButton != null)
buttons.add(loriCoolCardsUpsellButton)

if (buttons.isNotEmpty()) {
buttons.chunked(5)
.forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,11 @@ class CoinFlipBetCommand(val loritta: LorittaBot) : SlashCommandDeclarationWrapp

val buttons = mutableListOf<Button>()

val loriCoolCardsUpsellButton = SonhosUtils.createActiveLoriCoolCardsEventUpsellInformationIfNotNull(
loritta,
context.i18nContext
)

appendCouponSonhosBundleUpsellInformationIfNotNull(
loritta,
context.i18nContext,
Expand All @@ -657,6 +662,9 @@ class CoinFlipBetCommand(val loritta: LorittaBot) : SlashCommandDeclarationWrapp
ReactionEventsAttributes.getActiveEvent(now)
)?.let { buttons += it }

if (loriCoolCardsUpsellButton != null)
buttons.add(loriCoolCardsUpsellButton)

if (buttons.isNotEmpty()) {
buttons.chunked(5)
.forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import kotlinx.datetime.TimeZone
import net.dv8tion.jda.api.interactions.IntegrationType
import net.dv8tion.jda.api.interactions.components.buttons.Button
import net.perfectdreams.loritta.cinnamon.discord.interactions.commands.styled
import net.perfectdreams.loritta.cinnamon.discord.utils.SonhosUtils
import net.perfectdreams.loritta.cinnamon.discord.utils.SonhosUtils.appendActiveReactionEventUpsellInformationIfNotNull
import net.perfectdreams.loritta.cinnamon.discord.utils.SonhosUtils.appendCouponSonhosBundleUpsellInformationIfNotNull
import net.perfectdreams.loritta.cinnamon.discord.utils.SonhosUtils.appendUserHaventGotDailyTodayOrUpsellSonhosBundles
Expand Down Expand Up @@ -150,6 +151,11 @@ class DailyCommand(val loritta: LorittaBot) : SlashCommandDeclarationWrapper {
} else null
}

val loriCoolCardsUpsellButton = SonhosUtils.createActiveLoriCoolCardsEventUpsellInformationIfNotNull(
loritta,
context.i18nContext
)

context.reply(true) {
styled(
context.i18nContext.get(I18N_PREFIX.DailyLink(url, "<t:${tomorrowAtMidnight.toInstant().toEpochMilli() / 1000}:t>")),
Expand Down Expand Up @@ -274,6 +280,9 @@ class DailyCommand(val loritta: LorittaBot) : SlashCommandDeclarationWrapper {
ReactionEventsAttributes.getActiveEvent(java.time.Instant.now())
)?.let { buttons += it }

if (loriCoolCardsUpsellButton != null)
buttons.add(loriCoolCardsUpsellButton)

if (buttons.isNotEmpty()) {
buttons.chunked(5)
.forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class LoriCoolCardsCommand(private val loritta: LorittaBot) : SlashCommandDeclar
}

subcommand(I18N_PREFIX.Rank.Label, I18N_PREFIX.Rank.Description, UUID.fromString("e4df802c-7c19-455e-80b6-35fe23ece398")) {
// Trade stickers
// Sticker ranks
executor = LoriCoolCardsRankExecutor(loritta, this@LoriCoolCardsCommand)
}
}
Expand Down
15 changes: 13 additions & 2 deletions resources/languages/pt/commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,19 @@ commands:
sonhosShopCouponCodeWithMaxUsesUpsell: "Psiu, está rolando descontos na minha lojinha de sonhos! Corra, pois o cupom só está disponível até {expiresAt} para os {maxUses,plural, =0 {# primeiros pagamentos} one {# primeiro pagamento} other {# primeiros pagamentos}} que usarem o cupom! **Cupom:** `{couponCode}` ({discountPercentage,number,#%} de desconto)"
activeReactionEvent:
buttonLabel: "Participe do Evento de Reações {eventName} da Loritta!"
eventUpsell: "Atualmente está acontecendo o evento de reações **{reactionEventName}** na Loritta! Participe do evento e ganhe até {sonhosEmoji} **{sonhosCount,plural, =0 {# sonhos} one {# sonho} other {# sonhos}}**, mas corra, pois o evento acabará {endsAt}! Para entrar no evento, use {eventJoinMention}, para ver as recompensas use {eventStatsMention} e, para criar os itens, use {eventInventoryMention}."

eventUpsell: "Atualmente está acontecendo o evento de reações **{reactionEventName}** na Loritta! Participe do evento e ganhe até {sonhosEmoji} **{sonhosCount,plural, =0 {# sonhos} one {# sonho} other {# sonhos}}**, mas corra, pois o evento acabará {endsAt}! Para entrar no evento, use {eventJoinMention}, para ver as recompensas, use {eventStatsMention} e, para criar os itens, use {eventInventoryMention}."
loriCoolCardsEvent:
preEvent:
buttonLabel: "Seja Imortalizado na Loritta!"
eventUpsell1: "Você já imaginou ter a sua jornada imortalizada na Loritta? Conquiste o seu espaço no alto escalão dos **Top 500 Sonhadores da Loritta** e imortalize o seu legado! Todo o mês um Álbum de Figurittas imortalizando as 500 pessoas mais ricas na Loritta do mês é lançado."
eventUpsell2: "Álbuns de Figurittas da Loritta são iguais a Álbuns de Figurinhas na vida real. Compre pacotinhos de figurinhas por sonhos, para depois colar as figurinhas no álbum e trocar figurinhas com outras pessoas. E completando o álbum você ganha sonhos, designs para o seu perfil, insígnias e muito mais!"
eventUpsell3: "Para você aparecer no álbum, basta você estar no **Top 500 Sonhadores** quando as figurittas forem geradas. Enquanto não tem uma data e horário específico para que elas sejam geradas, elas normalmente são geradas na parte da tarde no primeiro dia do mês. Para mais informações, entre no servidor da Loritta! {lorittaGuildInvite}"
eventUpsell4: "Mas eu dúvido que você vá conseguir chegar no **Top 500 Sonhadores**..."
eventStarted:
buttonLabel: "Participe do Evento de Figurittas da Loritta!"
eventUpsell1: "Atualmente está rolando o Álbum de Figurittas **{albumEventName}** na Loritta! Compre pacotinhos de figurinhas por sonhos, para depois colar as figurinhas no álbum e trocar as suas figurinhas repetidas com outras pessoas, igual colecionar um álbum na vida real. Infelizmente, a parte de ficar batendo bafo não tem... Afinal, você bateria como?"
eventUpsell2: "Se você conseguir completar o álbum, você ganhará {sonhosEmoji} **{sonhosCount,plural, =0 {# sonhos} one {# sonho} other {# sonhos}}**, designs para o seu perfil, insígnias, e muito mais! Mas corra, pois o álbum acabará {endsAt}! Será que você vai conseguir acabar o álbum a tempo?"
eventUpsell3: "Para comprar pacotinhos de figurinhas, use {buyStickersMention}, para colar as figurinhas, use {stickStickersMention}. Se você precisa encontrar outros Loritters para trocar figurinhas com eles, entre no servidor da Loritta! {lorittaGuildInvite}"
youAreLorittaBannedPermanent:
- "Você está **banido(a) permanentemente**! {loriHmpf}"
- ""
Expand Down

0 comments on commit fb83473

Please sign in to comment.