From dc84bcb61191478b9dfa4dc12b893b32aa602b9b Mon Sep 17 00:00:00 2001 From: MrPowerGamerBR Date: Fri, 3 Jan 2025 15:59:44 -0300 Subject: [PATCH] Add "/premium" --- .../commands/UnleashedCommandManager.kt | 1 + .../vanilla/utils/PremiumCommand.kt | 67 +++++++++++++++++++ resources/languages/pt/commands/premium.yml | 5 ++ 3 files changed, 73 insertions(+) create mode 100644 loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/vanilla/utils/PremiumCommand.kt create mode 100644 resources/languages/pt/commands/premium.yml diff --git a/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/commands/UnleashedCommandManager.kt b/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/commands/UnleashedCommandManager.kt index 1dc7972a5d..0ca5886dec 100644 --- a/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/commands/UnleashedCommandManager.kt +++ b/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/commands/UnleashedCommandManager.kt @@ -313,6 +313,7 @@ class UnleashedCommandManager(val loritta: LorittaBot, val languageManager: Lang register(NotificationsCommand()) register(ChooseCommand()) register(TranslateCommand(loritta)) + register(PremiumCommand(loritta)) // ===[ ROLEPLAY ]=== register(RoleplayCommand.RoleplaySlashCommand(loritta)) diff --git a/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/vanilla/utils/PremiumCommand.kt b/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/vanilla/utils/PremiumCommand.kt new file mode 100644 index 0000000000..87b0057448 --- /dev/null +++ b/loritta-bot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/interactions/vanilla/utils/PremiumCommand.kt @@ -0,0 +1,67 @@ +package net.perfectdreams.loritta.morenitta.interactions.vanilla.utils + +import net.dv8tion.jda.api.interactions.IntegrationType +import net.perfectdreams.loritta.cinnamon.discord.interactions.commands.styled +import net.perfectdreams.loritta.cinnamon.pudding.tables.Payments +import net.perfectdreams.loritta.cinnamon.pudding.utils.PaymentReason +import net.perfectdreams.loritta.common.commands.CommandCategory +import net.perfectdreams.loritta.i18n.I18nKeysData +import net.perfectdreams.loritta.morenitta.LorittaBot +import net.perfectdreams.loritta.morenitta.dao.Payment +import net.perfectdreams.loritta.morenitta.interactions.UnleashedContext +import net.perfectdreams.loritta.morenitta.interactions.commands.* +import net.perfectdreams.loritta.morenitta.interactions.commands.options.OptionReference +import net.perfectdreams.loritta.morenitta.utils.DateUtils +import org.jetbrains.exposed.sql.and +import java.util.* + +class PremiumCommand(val m: LorittaBot) : SlashCommandDeclarationWrapper { + companion object { + private val I18N_PREFIX = I18nKeysData.Commands.Command.Premium + } + + override fun command() = slashCommand(I18N_PREFIX.Label, I18N_PREFIX.Description, CommandCategory.UTILS, UUID.fromString("8cfac679-16ed-4de0-8e81-ed05ab93ad05")) { + enableLegacyMessageSupport = true + + this.integrationTypes = listOf(IntegrationType.GUILD_INSTALL, IntegrationType.USER_INSTALL) + + executor = PremiumExecutor(m) + } + + class PremiumExecutor(val m: LorittaBot) : LorittaSlashCommandExecutor(), LorittaLegacyMessageCommandExecutor { + override suspend fun execute(context: UnleashedContext, args: SlashCommandArguments) { + context.deferChannelMessage(true) + val payments = m.transaction { + Payment.find { + (Payments.expiresAt greaterEq System.currentTimeMillis()) and + (Payments.reason eq PaymentReason.DONATION) and + (Payments.userId eq context.user.idLong) + }.toList() + } + + if (payments.isEmpty()) { + context.reply(true) { + styled(context.i18nContext.get(I18N_PREFIX.YouDontHaveLorittaPremium)) + } + return + } + + context.reply(true) { + for (payment in payments) { + if (payment.expiresAt == Long.MAX_VALUE) { + styled(context.i18nContext.get(I18N_PREFIX.PaymentPermanent(payment.money))) + } else { + styled(context.i18nContext.get(I18N_PREFIX.PaymentTemporary(payment.money, DateUtils.formatDateWithRelativeFromNowAndAbsoluteDifferenceWithDiscordMarkdown(payment.expiresAt!!)))) + } + } + } + } + + override suspend fun convertToInteractionsArguments( + context: LegacyMessageCommandContext, + args: List + ): Map, Any?>? { + return emptyMap() + } + } +} \ No newline at end of file diff --git a/resources/languages/pt/commands/premium.yml b/resources/languages/pt/commands/premium.yml new file mode 100644 index 0000000000..a56eddf791 --- /dev/null +++ b/resources/languages/pt/commands/premium.yml @@ -0,0 +1,5 @@ +label: "premium" +description: "Mostra informações sobre o seu plano ativo da Loritta" +youDontHaveLorittaPremium: "Você não tem planos premium ativos na Loritta!" +paymentPermanent: "Pagamento R$ {money,number,#.##} (permanente)" +paymentTemporary: "Pagamento R$ {money,number,#.##} expira em {date}" \ No newline at end of file