From 52ba3f3597b69b00f7d9ea09517045e1c7f5ae8a Mon Sep 17 00:00:00 2001 From: MrPowerGamerBR Date: Thu, 17 Dec 2020 15:29:23 -0300 Subject: [PATCH 1/8] Add UserDonationKeys Table and DAO --- .../com/mrpowergamerbr/loritta/Loritta.kt | 3 ++- .../loritta/dao/UserDonationKey.kt | 22 +++++++++++++++++++ .../loritta/tables/UserDonationKeys.kt | 13 +++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 loritta-discord/src/main/java/com/mrpowergamerbr/loritta/dao/UserDonationKey.kt create mode 100644 loritta-discord/src/main/java/com/mrpowergamerbr/loritta/tables/UserDonationKeys.kt diff --git a/loritta-discord/src/main/java/com/mrpowergamerbr/loritta/Loritta.kt b/loritta-discord/src/main/java/com/mrpowergamerbr/loritta/Loritta.kt index 9d3b78873f..4d3785c680 100644 --- a/loritta-discord/src/main/java/com/mrpowergamerbr/loritta/Loritta.kt +++ b/loritta-discord/src/main/java/com/mrpowergamerbr/loritta/Loritta.kt @@ -337,7 +337,8 @@ class Loritta(discordConfig: GeneralDiscordConfig, discordInstanceConfig: Genera BannedUsers, ProfileDesigns, ProfileDesignsPayments, - DailyProfileShopItems + DailyProfileShopItems, + UserDonationKeys ) } } diff --git a/loritta-discord/src/main/java/com/mrpowergamerbr/loritta/dao/UserDonationKey.kt b/loritta-discord/src/main/java/com/mrpowergamerbr/loritta/dao/UserDonationKey.kt new file mode 100644 index 0000000000..3482682a3f --- /dev/null +++ b/loritta-discord/src/main/java/com/mrpowergamerbr/loritta/dao/UserDonationKey.kt @@ -0,0 +1,22 @@ +package com.mrpowergamerbr.loritta.dao + +import com.mrpowergamerbr.loritta.tables.Profiles +import com.mrpowergamerbr.loritta.tables.UserDonationKeys +import org.jetbrains.exposed.dao.LongEntity +import org.jetbrains.exposed.dao.LongEntityClass +import org.jetbrains.exposed.dao.id.EntityID + +class UserDonationKey(id: EntityID) : LongEntity(id) { + companion object : LongEntityClass(Profiles) + + var userId by UserDonationKeys.userId + var value by UserDonationKeys.value + var expiresAt by UserDonationKeys.expiresAt + var metadata by UserDonationKeys.metadata + val activeIn by UserDonationKey optionalReferencedOn UserDonationKeys.activeIn + + /** + * Returns if the key is still active + */ + fun isActive() = expiresAt >= System.currentTimeMillis() +} \ No newline at end of file diff --git a/loritta-discord/src/main/java/com/mrpowergamerbr/loritta/tables/UserDonationKeys.kt b/loritta-discord/src/main/java/com/mrpowergamerbr/loritta/tables/UserDonationKeys.kt new file mode 100644 index 0000000000..f11691cb5a --- /dev/null +++ b/loritta-discord/src/main/java/com/mrpowergamerbr/loritta/tables/UserDonationKeys.kt @@ -0,0 +1,13 @@ +package com.mrpowergamerbr.loritta.tables + +import com.mrpowergamerbr.loritta.utils.exposed.rawJsonb +import com.mrpowergamerbr.loritta.utils.gson +import org.jetbrains.exposed.dao.id.LongIdTable + +object UserDonationKeys : LongIdTable() { + val activeIn = optReference("active_in", Profiles) + val userId = long("user") + val value = double("value") + val expiresAt = long("expires_at") + val metadata = rawJsonb("metadata", gson).nullable() +} \ No newline at end of file From 8294d31e0f11d74eb97c0c5148d1d7d972661cbe Mon Sep 17 00:00:00 2001 From: MrPowerGamerBR Date: Thu, 17 Dec 2020 15:34:28 -0300 Subject: [PATCH 2/8] Load donation value from the UserDonationKeys table instead of loading from the payments --- .../loritta/platform/discord/LorittaDiscord.kt | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/loritta-discord/src/main/java/net/perfectdreams/loritta/platform/discord/LorittaDiscord.kt b/loritta-discord/src/main/java/net/perfectdreams/loritta/platform/discord/LorittaDiscord.kt index 0b4ab2c4b1..31633f420b 100644 --- a/loritta-discord/src/main/java/net/perfectdreams/loritta/platform/discord/LorittaDiscord.kt +++ b/loritta-discord/src/main/java/net/perfectdreams/loritta/platform/discord/LorittaDiscord.kt @@ -11,6 +11,7 @@ import com.mrpowergamerbr.loritta.commands.vanilla.magic.* import com.mrpowergamerbr.loritta.dao.* import com.mrpowergamerbr.loritta.network.Databases import com.mrpowergamerbr.loritta.profile.ProfileDesignManager +import com.mrpowergamerbr.loritta.tables.UserDonationKeys import com.mrpowergamerbr.loritta.utils.Constants import com.mrpowergamerbr.loritta.utils.config.* import com.mrpowergamerbr.loritta.utils.locale.* @@ -32,7 +33,6 @@ import net.perfectdreams.loritta.commands.vanilla.administration.* import net.perfectdreams.loritta.commands.vanilla.economy.* import net.perfectdreams.loritta.commands.vanilla.magic.* import net.perfectdreams.loritta.commands.vanilla.social.* -import net.perfectdreams.loritta.dao.Payment import net.perfectdreams.loritta.platform.discord.commands.DiscordCommandMap import net.perfectdreams.loritta.platform.discord.plugin.JVMPluginManager import net.perfectdreams.loritta.platform.discord.utils.* @@ -41,7 +41,6 @@ import net.perfectdreams.loritta.utils.* import net.perfectdreams.loritta.utils.config.* import net.perfectdreams.loritta.utils.extensions.readImage import net.perfectdreams.loritta.utils.locale.DebugLocales -import net.perfectdreams.loritta.utils.payments.PaymentReason import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.transactions.transaction import java.awt.image.BufferedImage @@ -701,11 +700,9 @@ abstract class LorittaDiscord(var discordConfig: GeneralDiscordConfig, var disco } fun _getActiveMoneyFromDonations(userId: Long): Double { - return Payment.find { - (Payments.expiresAt greaterEq System.currentTimeMillis()) and - (Payments.reason eq PaymentReason.DONATION) and - (Payments.userId eq userId) - }.sumByDouble { it.money.toDouble() } + return UserDonationKey.find { UserDonationKeys.activeIn eq userId and (UserDonationKeys.expiresAt greaterEq System.currentTimeMillis()) } + .toList() + .sumByDouble { it.value } } fun launchMessageJob(event: Event, block: suspend CoroutineScope.() -> Unit) { From cfb1d6116bb4cd0ed6323318736464f7c542a851 Mon Sep 17 00:00:00 2001 From: MrPowerGamerBR Date: Thu, 17 Dec 2020 15:36:25 -0300 Subject: [PATCH 3/8] Delete user donation keys when deleting the user's data --- .../website/routes/api/v1/user/PostDeleteDataRoute.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/loritta-discord/src/main/java/net/perfectdreams/loritta/website/routes/api/v1/user/PostDeleteDataRoute.kt b/loritta-discord/src/main/java/net/perfectdreams/loritta/website/routes/api/v1/user/PostDeleteDataRoute.kt index 5bf591bb70..6cd71b54fd 100644 --- a/loritta-discord/src/main/java/net/perfectdreams/loritta/website/routes/api/v1/user/PostDeleteDataRoute.kt +++ b/loritta-discord/src/main/java/net/perfectdreams/loritta/website/routes/api/v1/user/PostDeleteDataRoute.kt @@ -11,6 +11,7 @@ import com.mrpowergamerbr.loritta.tables.Reminders import com.mrpowergamerbr.loritta.tables.Reputations import com.mrpowergamerbr.loritta.tables.ShipEffects import com.mrpowergamerbr.loritta.tables.StoredMessages +import com.mrpowergamerbr.loritta.tables.UserDonationKeys import com.mrpowergamerbr.loritta.utils.Constants import io.ktor.application.* import io.ktor.sessions.* @@ -44,11 +45,16 @@ class PostDeleteDataRoute(loritta: LorittaDiscord) : RequiresAPIDiscordLoginRout Dailies.receivedById eq userId } - logger.info { "Deleting $userId's donation keys..." } + logger.info { "Deleting $userId's server donation keys..." } DonationKeys.deleteWhere { DonationKeys.userId eq userId } + logger.info { "Deleting $userId's user donation keys..." } + UserDonationKeys.deleteWhere { + UserDonationKeys.userId eq userId + } + logger.info { "Deleting $userId's guild profiles..." } GuildProfiles.deleteWhere { GuildProfiles.userId eq userId From 625d47f8ec5c3d6dad58dbb34806641b387d8eb8 Mon Sep 17 00:00:00 2001 From: MrPowerGamerBR Date: Thu, 17 Dec 2020 15:48:42 -0300 Subject: [PATCH 4/8] UserDonationKeysTransformer -> GuildDonationKeysTransformer Because that would get very confusing after a while --- .../loritta/website/utils/config/types/ConfigTransformers.kt | 2 +- ...tionKeysTransformer.kt => GuildDonationKeysTransformer.kt} | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename loritta-discord/src/main/java/net/perfectdreams/loritta/website/utils/config/types/{UserDonationKeysTransformer.kt => GuildDonationKeysTransformer.kt} (97%) diff --git a/loritta-discord/src/main/java/net/perfectdreams/loritta/website/utils/config/types/ConfigTransformers.kt b/loritta-discord/src/main/java/net/perfectdreams/loritta/website/utils/config/types/ConfigTransformers.kt index e83ab53b68..2212fea03a 100644 --- a/loritta-discord/src/main/java/net/perfectdreams/loritta/website/utils/config/types/ConfigTransformers.kt +++ b/loritta-discord/src/main/java/net/perfectdreams/loritta/website/utils/config/types/ConfigTransformers.kt @@ -12,7 +12,7 @@ object ConfigTransformers { TwitchConfigTransformer, TwitterConfigTransformer, TextChannelsTransformer, - UserDonationKeysTransformer, + GuildDonationKeysTransformer, ActiveDonationKeysTransformer, GuildInfoTransformer, GeneralConfigTransformer, diff --git a/loritta-discord/src/main/java/net/perfectdreams/loritta/website/utils/config/types/UserDonationKeysTransformer.kt b/loritta-discord/src/main/java/net/perfectdreams/loritta/website/utils/config/types/GuildDonationKeysTransformer.kt similarity index 97% rename from loritta-discord/src/main/java/net/perfectdreams/loritta/website/utils/config/types/UserDonationKeysTransformer.kt rename to loritta-discord/src/main/java/net/perfectdreams/loritta/website/utils/config/types/GuildDonationKeysTransformer.kt index cf89f508f7..ce5c3bca9b 100644 --- a/loritta-discord/src/main/java/net/perfectdreams/loritta/website/utils/config/types/UserDonationKeysTransformer.kt +++ b/loritta-discord/src/main/java/net/perfectdreams/loritta/website/utils/config/types/GuildDonationKeysTransformer.kt @@ -7,7 +7,6 @@ import com.google.gson.JsonObject import com.mrpowergamerbr.loritta.dao.DonationKey import com.mrpowergamerbr.loritta.dao.ServerConfig import com.mrpowergamerbr.loritta.tables.DonationKeys -import net.perfectdreams.loritta.website.utils.WebsiteUtils import com.mrpowergamerbr.loritta.utils.loritta import com.mrpowergamerbr.loritta.utils.lorittaShards import kotlinx.coroutines.GlobalScope @@ -15,9 +14,10 @@ import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll import net.dv8tion.jda.api.entities.Guild import net.perfectdreams.loritta.website.session.LorittaJsonWebSession +import net.perfectdreams.loritta.website.utils.WebsiteUtils import org.jetbrains.exposed.sql.and -object UserDonationKeysTransformer : ConfigTransformer { +object GuildDonationKeysTransformer : ConfigTransformer { override val payloadType: String = "userkeys" override val configKey: String = "donationKeys" From b0e32cc2b7eaa9c8084c87da0f349bfdc4e3d59b Mon Sep 17 00:00:00 2001 From: MrPowerGamerBR Date: Thu, 17 Dec 2020 15:54:17 -0300 Subject: [PATCH 5/8] Add a way to query the user's donation keys --- .../routes/api/v1/user/GetSelfInfoRoute.kt | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/loritta-discord/src/main/java/net/perfectdreams/loritta/website/routes/api/v1/user/GetSelfInfoRoute.kt b/loritta-discord/src/main/java/net/perfectdreams/loritta/website/routes/api/v1/user/GetSelfInfoRoute.kt index 38fb091908..bac0f52c00 100644 --- a/loritta-discord/src/main/java/net/perfectdreams/loritta/website/routes/api/v1/user/GetSelfInfoRoute.kt +++ b/loritta-discord/src/main/java/net/perfectdreams/loritta/website/routes/api/v1/user/GetSelfInfoRoute.kt @@ -7,7 +7,11 @@ import com.google.gson.JsonParser import com.mrpowergamerbr.loritta.Loritta import com.mrpowergamerbr.loritta.dao.Background import com.mrpowergamerbr.loritta.dao.ProfileDesign +import com.mrpowergamerbr.loritta.dao.UserDonationKey +import com.mrpowergamerbr.loritta.tables.DonationKeys +import com.mrpowergamerbr.loritta.tables.UserDonationKeys import com.mrpowergamerbr.loritta.utils.Constants +import com.mrpowergamerbr.loritta.utils.lorittaShards import com.mrpowergamerbr.loritta.utils.networkbans.ApplyBansTask import com.mrpowergamerbr.loritta.website.LoriWebCode import com.mrpowergamerbr.loritta.website.WebsiteAPIException @@ -18,7 +22,11 @@ import kotlinx.serialization.json.Json import mu.KotlinLogging import net.perfectdreams.loritta.platform.discord.LorittaDiscord import net.perfectdreams.loritta.serializable.UserIdentification -import net.perfectdreams.loritta.tables.* +import net.perfectdreams.loritta.tables.BackgroundPayments +import net.perfectdreams.loritta.tables.Backgrounds +import net.perfectdreams.loritta.tables.BannedIps +import net.perfectdreams.loritta.tables.ProfileDesigns +import net.perfectdreams.loritta.tables.ProfileDesignsPayments import net.perfectdreams.loritta.website.routes.BaseRoute import net.perfectdreams.loritta.website.session.LorittaJsonWebSession import net.perfectdreams.loritta.website.utils.WebsiteUtils @@ -26,10 +34,7 @@ import net.perfectdreams.loritta.website.utils.extensions.respondJson import net.perfectdreams.loritta.website.utils.extensions.trueIp import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.select -import kotlin.collections.firstOrNull -import kotlin.collections.map import kotlin.collections.set -import kotlin.collections.toSet class GetSelfInfoRoute(loritta: LorittaDiscord) : BaseRoute(loritta, "/api/v1/users/@me/{sections?}") { companion object { @@ -118,6 +123,23 @@ class GetSelfInfoRoute(loritta: LorittaDiscord) : BaseRoute(loritta, "/api/v1/us ) } + if ("userdonationkeys" in sections) { + val userDonationKeys = loritta.newSuspendedTransaction { + UserDonationKey.find { UserDonationKeys.userId eq userIdentification.id.toLong() and (DonationKeys.expiresAt greaterEq System.currentTimeMillis()) } + .toList() + } + + payload["userDonationKeys"] = userDonationKeys.map { + jsonObject( + "id" to it.id.value, + "value" to it.value, + "expiresAt" to it.expiresAt, + "user" to WebsiteUtils.transformToJson(lorittaShards.retrieveUserById(it.userId)!!), + "activeIn" to loritta.newSuspendedTransaction { it.activeIn } + ) + }.toJsonArray() + } + if ("settings" in sections) { val settings = loritta.newSuspendedTransaction { profile.settings From 4f87a85f2cc2d19656c52d03edc4abca808c123f Mon Sep 17 00:00:00 2001 From: MrPowerGamerBR Date: Thu, 17 Dec 2020 15:57:29 -0300 Subject: [PATCH 6/8] Add "generate_user_key" debug command --- .../magic/LoriServerListConfigCommand.kt | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/loritta-discord/src/main/java/com/mrpowergamerbr/loritta/commands/vanilla/magic/LoriServerListConfigCommand.kt b/loritta-discord/src/main/java/com/mrpowergamerbr/loritta/commands/vanilla/magic/LoriServerListConfigCommand.kt index 3cce700022..3d9abaaf43 100644 --- a/loritta-discord/src/main/java/com/mrpowergamerbr/loritta/commands/vanilla/magic/LoriServerListConfigCommand.kt +++ b/loritta-discord/src/main/java/com/mrpowergamerbr/loritta/commands/vanilla/magic/LoriServerListConfigCommand.kt @@ -9,11 +9,17 @@ import com.mrpowergamerbr.loritta.commands.AbstractCommand import com.mrpowergamerbr.loritta.commands.CommandContext import com.mrpowergamerbr.loritta.dao.DonationKey import com.mrpowergamerbr.loritta.dao.GuildProfile +import com.mrpowergamerbr.loritta.dao.UserDonationKey import com.mrpowergamerbr.loritta.network.Databases import com.mrpowergamerbr.loritta.tables.GuildProfiles import com.mrpowergamerbr.loritta.tables.Profiles -import com.mrpowergamerbr.loritta.utils.* +import com.mrpowergamerbr.loritta.utils.Constants +import com.mrpowergamerbr.loritta.utils.LorittaShards +import com.mrpowergamerbr.loritta.utils.gson import com.mrpowergamerbr.loritta.utils.locale.BaseLocale +import com.mrpowergamerbr.loritta.utils.loritta +import com.mrpowergamerbr.loritta.utils.lorittaShards +import com.mrpowergamerbr.loritta.utils.lorittaSupervisor import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll @@ -26,8 +32,12 @@ import net.perfectdreams.loritta.utils.ClusterOfflineException import net.perfectdreams.loritta.utils.payments.PaymentGateway import net.perfectdreams.loritta.utils.payments.PaymentReason import org.jetbrains.exposed.dao.id.EntityID -import org.jetbrains.exposed.sql.* +import org.jetbrains.exposed.sql.SqlExpressionBuilder +import org.jetbrains.exposed.sql.and +import org.jetbrains.exposed.sql.deleteWhere +import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.transactions.transaction +import org.jetbrains.exposed.sql.update class LoriServerListConfigCommand : AbstractCommand("lslc", category = CommandCategory.MAGIC) { override fun getDescription(locale: BaseLocale): String { @@ -187,7 +197,7 @@ class LoriServerListConfigCommand : AbstractCommand("lslc", category = CommandCa return } - if (arg0 == "generate_key" && arg1 != null && arg2 != null) { + if (arg0 == "generate_guild_key" && arg1 != null && arg2 != null) { transaction(Databases.loritta) { DonationKey.new { this.userId = arg1.toLong() @@ -198,12 +208,29 @@ class LoriServerListConfigCommand : AbstractCommand("lslc", category = CommandCa context.reply( LorittaReply( - "Key criada com sucesso!" + "Guild Key criada com sucesso!" ) ) return } + if (arg0 == "generate_user_key" && arg1 != null && arg2 != null) { + transaction(Databases.loritta) { + UserDonationKey.new { + this.userId = arg1.toLong() + this.expiresAt = System.currentTimeMillis() + 2_764_800_000 + this.value = arg2.toDouble() + } + } + + context.reply( + LorittaReply( + "User Key criada com sucesso!" + ) + ) + return + } + if (arg0 == "inspect_donations" && arg1 != null) { val id = arg1.toLong() From 141f6e54996a4ba5a3a744e26a59b9754269b914 Mon Sep 17 00:00:00 2001 From: MrPowerGamerBR Date: Thu, 17 Dec 2020 16:29:51 -0300 Subject: [PATCH 7/8] Smol fixes --- .../java/com/mrpowergamerbr/loritta/dao/UserDonationKey.kt | 5 ++--- .../loritta/website/routes/api/v1/user/GetSelfInfoRoute.kt | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/loritta-discord/src/main/java/com/mrpowergamerbr/loritta/dao/UserDonationKey.kt b/loritta-discord/src/main/java/com/mrpowergamerbr/loritta/dao/UserDonationKey.kt index 3482682a3f..e09077ee8b 100644 --- a/loritta-discord/src/main/java/com/mrpowergamerbr/loritta/dao/UserDonationKey.kt +++ b/loritta-discord/src/main/java/com/mrpowergamerbr/loritta/dao/UserDonationKey.kt @@ -1,19 +1,18 @@ package com.mrpowergamerbr.loritta.dao -import com.mrpowergamerbr.loritta.tables.Profiles import com.mrpowergamerbr.loritta.tables.UserDonationKeys import org.jetbrains.exposed.dao.LongEntity import org.jetbrains.exposed.dao.LongEntityClass import org.jetbrains.exposed.dao.id.EntityID class UserDonationKey(id: EntityID) : LongEntity(id) { - companion object : LongEntityClass(Profiles) + companion object : LongEntityClass(UserDonationKeys) var userId by UserDonationKeys.userId var value by UserDonationKeys.value var expiresAt by UserDonationKeys.expiresAt var metadata by UserDonationKeys.metadata - val activeIn by UserDonationKey optionalReferencedOn UserDonationKeys.activeIn + val activeIn by Profile optionalReferencedOn UserDonationKeys.activeIn /** * Returns if the key is still active diff --git a/loritta-discord/src/main/java/net/perfectdreams/loritta/website/routes/api/v1/user/GetSelfInfoRoute.kt b/loritta-discord/src/main/java/net/perfectdreams/loritta/website/routes/api/v1/user/GetSelfInfoRoute.kt index bac0f52c00..5c42a9fef8 100644 --- a/loritta-discord/src/main/java/net/perfectdreams/loritta/website/routes/api/v1/user/GetSelfInfoRoute.kt +++ b/loritta-discord/src/main/java/net/perfectdreams/loritta/website/routes/api/v1/user/GetSelfInfoRoute.kt @@ -8,7 +8,6 @@ import com.mrpowergamerbr.loritta.Loritta import com.mrpowergamerbr.loritta.dao.Background import com.mrpowergamerbr.loritta.dao.ProfileDesign import com.mrpowergamerbr.loritta.dao.UserDonationKey -import com.mrpowergamerbr.loritta.tables.DonationKeys import com.mrpowergamerbr.loritta.tables.UserDonationKeys import com.mrpowergamerbr.loritta.utils.Constants import com.mrpowergamerbr.loritta.utils.lorittaShards @@ -125,7 +124,7 @@ class GetSelfInfoRoute(loritta: LorittaDiscord) : BaseRoute(loritta, "/api/v1/us if ("userdonationkeys" in sections) { val userDonationKeys = loritta.newSuspendedTransaction { - UserDonationKey.find { UserDonationKeys.userId eq userIdentification.id.toLong() and (DonationKeys.expiresAt greaterEq System.currentTimeMillis()) } + UserDonationKey.find { UserDonationKeys.userId eq userIdentification.id.toLong() and (UserDonationKeys.expiresAt greaterEq System.currentTimeMillis()) } .toList() } From bf8f495f9b0e64f01dd51b6c22dc39cebb4724b9 Mon Sep 17 00:00:00 2001 From: MrPowerGamerBR Date: Thu, 17 Dec 2020 16:30:31 -0300 Subject: [PATCH 8/8] Remove PremiumKeyPayload Unused, not really related to this PR but still --- .../api/config/types/PremiumKeyPayload.kt | 47 ------------------- .../api/v1/guild/PatchServerConfigRoute.kt | 22 +++++++-- 2 files changed, 17 insertions(+), 52 deletions(-) delete mode 100644 loritta-discord/src/main/java/com/mrpowergamerbr/loritta/website/views/subviews/api/config/types/PremiumKeyPayload.kt diff --git a/loritta-discord/src/main/java/com/mrpowergamerbr/loritta/website/views/subviews/api/config/types/PremiumKeyPayload.kt b/loritta-discord/src/main/java/com/mrpowergamerbr/loritta/website/views/subviews/api/config/types/PremiumKeyPayload.kt deleted file mode 100644 index 5c6afabf38..0000000000 --- a/loritta-discord/src/main/java/com/mrpowergamerbr/loritta/website/views/subviews/api/config/types/PremiumKeyPayload.kt +++ /dev/null @@ -1,47 +0,0 @@ -package com.mrpowergamerbr.loritta.website.views.subviews.api.config.types - -import com.github.salomonbrys.kotson.string -import com.google.gson.JsonObject -import com.mrpowergamerbr.loritta.dao.DonationKey -import com.mrpowergamerbr.loritta.dao.ServerConfig -import com.mrpowergamerbr.loritta.network.Databases -import net.perfectdreams.loritta.website.utils.WebsiteUtils -import com.mrpowergamerbr.loritta.website.LoriWebCode -import com.mrpowergamerbr.loritta.website.WebsiteAPIException -import io.ktor.http.HttpStatusCode -import net.dv8tion.jda.api.entities.Guild -import net.perfectdreams.loritta.website.session.LorittaJsonWebSession -import org.jetbrains.exposed.sql.transactions.transaction - -class PremiumKeyPayload : ConfigPayloadType("premium") { - override fun process(payload: JsonObject, userIdentification: LorittaJsonWebSession.UserIdentification, serverConfig: ServerConfig, guild: Guild) { - val keyId = payload["keyId"].string - - val donationKey = transaction(Databases.loritta) { - DonationKey.findById(keyId.toLong()) - } ?: throw WebsiteAPIException(HttpStatusCode.Forbidden, - WebsiteUtils.createErrorPayload( - LoriWebCode.FORBIDDEN, - "loritta.errors.keyDoesntExist" - ) - ) - - if (donationKey.userId != userIdentification.id.toLong()) - throw WebsiteAPIException(HttpStatusCode.Forbidden, - WebsiteUtils.createErrorPayload( - LoriWebCode.FORBIDDEN, - "loritta.errors.tryingToApplyKeyOfAnotherUser" - ) - ) - - /* transaction(Databases.loritta) { - // Desativar a key em outros servidores - ServerConfigs.update({ ServerConfigs.donationKey eq donationKey.id }) { - it[ServerConfigs.donationKey] = null - } - - // Atualizar a key atual - serverConfig.donationKey = donationKey - } */ - } -} \ No newline at end of file diff --git a/loritta-discord/src/main/java/net/perfectdreams/loritta/website/routes/api/v1/guild/PatchServerConfigRoute.kt b/loritta-discord/src/main/java/net/perfectdreams/loritta/website/routes/api/v1/guild/PatchServerConfigRoute.kt index d6dd9446df..506ee7f342 100644 --- a/loritta-discord/src/main/java/net/perfectdreams/loritta/website/routes/api/v1/guild/PatchServerConfigRoute.kt +++ b/loritta-discord/src/main/java/net/perfectdreams/loritta/website/routes/api/v1/guild/PatchServerConfigRoute.kt @@ -8,10 +8,23 @@ import com.google.gson.JsonParser import com.mrpowergamerbr.loritta.dao.ServerConfig import com.mrpowergamerbr.loritta.website.LoriWebCode import com.mrpowergamerbr.loritta.website.WebsiteAPIException -import com.mrpowergamerbr.loritta.website.views.subviews.api.config.types.* -import io.ktor.application.ApplicationCall -import io.ktor.http.HttpStatusCode -import io.ktor.request.receiveText +import com.mrpowergamerbr.loritta.website.views.subviews.api.config.types.AutorolePayload +import com.mrpowergamerbr.loritta.website.views.subviews.api.config.types.CustomBadgePayload +import com.mrpowergamerbr.loritta.website.views.subviews.api.config.types.DailyMultiplierPayload +import com.mrpowergamerbr.loritta.website.views.subviews.api.config.types.EconomyPayload +import com.mrpowergamerbr.loritta.website.views.subviews.api.config.types.GeneralConfigPayload +import com.mrpowergamerbr.loritta.website.views.subviews.api.config.types.LevelPayload +import com.mrpowergamerbr.loritta.website.views.subviews.api.config.types.MiscellaneousPayload +import com.mrpowergamerbr.loritta.website.views.subviews.api.config.types.ModerationPayload +import com.mrpowergamerbr.loritta.website.views.subviews.api.config.types.ResetXpPayload +import com.mrpowergamerbr.loritta.website.views.subviews.api.config.types.RssFeedsPayload +import com.mrpowergamerbr.loritta.website.views.subviews.api.config.types.TimersPayload +import com.mrpowergamerbr.loritta.website.views.subviews.api.config.types.TwitchPayload +import com.mrpowergamerbr.loritta.website.views.subviews.api.config.types.TwitterPayload +import com.mrpowergamerbr.loritta.website.views.subviews.api.config.types.YouTubePayload +import io.ktor.application.* +import io.ktor.http.* +import io.ktor.request.* import net.dv8tion.jda.api.entities.Guild import net.perfectdreams.loritta.platform.discord.LorittaDiscord import net.perfectdreams.loritta.utils.ActionType @@ -63,7 +76,6 @@ class PatchServerConfigRoute(loritta: LorittaDiscord) : RequiresAPIGuildAuthRout "miscellaneous" to MiscellaneousPayload::class.java, "economy" to EconomyPayload::class.java, "timers" to TimersPayload::class.java, - "premium" to PremiumKeyPayload::class.java, "badge" to CustomBadgePayload::class.java, "daily_multiplier" to DailyMultiplierPayload::class.java, "level" to LevelPayload::class.java,