-
-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Loritta's daily shop notifications to be relayed to guilds
- Loading branch information
1 parent
02e0dcb
commit 03c7f60
Showing
22 changed files
with
954 additions
and
16 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
...ams/loritta/common/utils/placeholders/DailyShopTrinketsNotificationMessagePlaceholders.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package net.perfectdreams.loritta.common.utils.placeholders | ||
|
||
import net.perfectdreams.loritta.i18n.I18nKeysData | ||
|
||
data object DailyShopTrinketsNotificationMessagePlaceholders : SectionPlaceholders<DailyShopTrinketsNotificationMessagePlaceholders.DailyShopTrinketsNotificationPlaceholder> { | ||
override val type = PlaceholderSectionType.DAILY_SHOP_TRINKETS_NOTIFICATION_MESSAGE | ||
|
||
sealed interface DailyShopTrinketsNotificationPlaceholder : MessagePlaceholder | ||
|
||
object DailyShopDateShortPlaceholder : GenericPlaceholders.GenericPlaceholder(null), DailyShopTrinketsNotificationPlaceholder { | ||
override val names = listOf(Placeholders.DAILY_SHOP_DATE_SHORT.toVisiblePlaceholder()) | ||
override val renderType = MessagePlaceholder.RenderType.TEXT | ||
} | ||
object GuildNamePlaceholder : GenericPlaceholders.GuildNamePlaceholder(I18nKeysData.Placeholders.Generic.GuildName), DailyShopTrinketsNotificationPlaceholder | ||
object GuildSizePlaceholder : GenericPlaceholders.GuildSizePlaceholder(I18nKeysData.Placeholders.Generic.GuildSize), DailyShopTrinketsNotificationPlaceholder | ||
object GuildIconUrlPlaceholder : GenericPlaceholders.GuildIconUrlPlaceholder(I18nKeysData.Placeholders.Generic.GuildIconUrl), DailyShopTrinketsNotificationPlaceholder | ||
|
||
override val placeholders = listOf<DailyShopTrinketsNotificationPlaceholder>( | ||
DailyShopDateShortPlaceholder, | ||
GuildNamePlaceholder, | ||
GuildSizePlaceholder, | ||
GuildIconUrlPlaceholder | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...tes/dashboard/configure/dailyshoptrinkets/ConfigureDailyShopTrinketsNotificationsRoute.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package net.perfectdreams.loritta.morenitta.website.routes.dashboard.configure.dailyshoptrinkets | ||
|
||
import io.ktor.server.application.* | ||
import net.dv8tion.jda.api.entities.Guild | ||
import net.perfectdreams.i18nhelper.core.I18nContext | ||
import net.perfectdreams.loritta.cinnamon.pudding.tables.servers.moduleconfigs.LorittaDailyShopNotificationsConfigs | ||
import net.perfectdreams.loritta.common.locale.BaseLocale | ||
import net.perfectdreams.loritta.common.utils.UserPremiumPlans | ||
import net.perfectdreams.loritta.morenitta.LorittaBot | ||
import net.perfectdreams.loritta.morenitta.dao.ServerConfig | ||
import net.perfectdreams.loritta.morenitta.website.routes.dashboard.RequiresGuildAuthLocalizedDashboardRoute | ||
import net.perfectdreams.loritta.morenitta.website.utils.extensions.respondHtml | ||
import net.perfectdreams.loritta.morenitta.website.views.dashboard.guild.dailyshoptrinkets.GuildDailyShopTrinketsNotificationsView | ||
import net.perfectdreams.loritta.serializable.ColorTheme | ||
import net.perfectdreams.loritta.serializable.config.GuildDailyShopTrinketsNotificationsConfig | ||
import net.perfectdreams.loritta.temmiewebsession.LorittaJsonWebSession | ||
import net.perfectdreams.temmiediscordauth.TemmieDiscordAuth | ||
import org.jetbrains.exposed.sql.selectAll | ||
|
||
class ConfigureDailyShopTrinketsNotificationsRoute(loritta: LorittaBot) : RequiresGuildAuthLocalizedDashboardRoute(loritta, "/configure/daily-shop-trinkets") { | ||
override suspend fun onDashboardGuildAuthenticatedRequest( | ||
call: ApplicationCall, | ||
locale: BaseLocale, | ||
i18nContext: I18nContext, | ||
discordAuth: TemmieDiscordAuth, | ||
userIdentification: LorittaJsonWebSession.UserIdentification, | ||
guild: Guild, | ||
serverConfig: ServerConfig, | ||
colorTheme: ColorTheme | ||
) { | ||
val databaseConfig = loritta.transaction { | ||
LorittaDailyShopNotificationsConfigs.selectAll() | ||
.where { | ||
LorittaDailyShopNotificationsConfigs.id eq guild.idLong | ||
} | ||
.firstOrNull() | ||
} | ||
|
||
val config = if (databaseConfig != null) { | ||
GuildDailyShopTrinketsNotificationsConfig( | ||
databaseConfig[LorittaDailyShopNotificationsConfigs.notifyShopTrinkets], | ||
databaseConfig[LorittaDailyShopNotificationsConfigs.shopTrinketsChannelId], | ||
databaseConfig[LorittaDailyShopNotificationsConfigs.shopTrinketsMessage], | ||
|
||
databaseConfig[LorittaDailyShopNotificationsConfigs.notifyNewTrinkets], | ||
databaseConfig[LorittaDailyShopNotificationsConfigs.newTrinketsChannelId], | ||
databaseConfig[LorittaDailyShopNotificationsConfigs.newTrinketsMessage], | ||
) | ||
} else { | ||
GuildDailyShopTrinketsNotificationsConfig( | ||
false, | ||
null, | ||
GuildDailyShopTrinketsNotificationsView.defaultShopTrinketsTemplate.content, | ||
|
||
false, | ||
null, | ||
GuildDailyShopTrinketsNotificationsView.defaultNewTrinketsTemplate.content | ||
) | ||
} | ||
|
||
call.respondHtml( | ||
GuildDailyShopTrinketsNotificationsView( | ||
loritta.newWebsite!!, | ||
i18nContext, | ||
locale, | ||
getPathWithoutLocale(call), | ||
loritta.getLegacyLocaleById(locale.id), | ||
userIdentification, | ||
UserPremiumPlans.getPlanFromValue(loritta.getActiveMoneyFromDonations(userIdentification.id.toLong())), | ||
colorTheme, | ||
guild, | ||
"daily_shop_trinkets", | ||
config | ||
).generateHtml() | ||
) | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
.../dashboard/configure/dailyshoptrinkets/PutConfigureDailyShopTrinketsNotificationsRoute.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package net.perfectdreams.loritta.morenitta.website.routes.dashboard.configure.dailyshoptrinkets | ||
|
||
import io.ktor.server.application.* | ||
import io.ktor.server.request.* | ||
import net.dv8tion.jda.api.entities.Guild | ||
import net.perfectdreams.i18nhelper.core.I18nContext | ||
import net.perfectdreams.loritta.cinnamon.pudding.tables.servers.moduleconfigs.LorittaDailyShopNotificationsConfigs | ||
import net.perfectdreams.loritta.common.locale.BaseLocale | ||
import net.perfectdreams.loritta.common.utils.UserPremiumPlans | ||
import net.perfectdreams.loritta.morenitta.LorittaBot | ||
import net.perfectdreams.loritta.morenitta.dao.ServerConfig | ||
import net.perfectdreams.loritta.morenitta.website.routes.dashboard.RequiresGuildAuthLocalizedDashboardRoute | ||
import net.perfectdreams.loritta.morenitta.website.utils.EmbeddedSpicyModalUtils.headerHXTrigger | ||
import net.perfectdreams.loritta.morenitta.website.utils.extensions.respondHtml | ||
import net.perfectdreams.loritta.morenitta.website.views.dashboard.guild.dailyshoptrinkets.GuildDailyShopTrinketsNotificationsView | ||
import net.perfectdreams.loritta.serializable.ColorTheme | ||
import net.perfectdreams.loritta.serializable.EmbeddedSpicyToast | ||
import net.perfectdreams.loritta.serializable.config.GuildDailyShopTrinketsNotificationsConfig | ||
import net.perfectdreams.loritta.temmiewebsession.LorittaJsonWebSession | ||
import net.perfectdreams.temmiediscordauth.TemmieDiscordAuth | ||
import org.jetbrains.exposed.sql.upsert | ||
|
||
class PutConfigureDailyShopTrinketsNotificationsRoute(loritta: LorittaBot) : RequiresGuildAuthLocalizedDashboardRoute(loritta, "/configure/daily-shop-trinkets") { | ||
override suspend fun onDashboardGuildAuthenticatedRequest( | ||
call: ApplicationCall, | ||
locale: BaseLocale, | ||
i18nContext: I18nContext, | ||
discordAuth: TemmieDiscordAuth, | ||
userIdentification: LorittaJsonWebSession.UserIdentification, | ||
guild: Guild, | ||
serverConfig: ServerConfig, | ||
colorTheme: ColorTheme | ||
) { | ||
val params = call.receiveParameters() | ||
|
||
val result = loritta.newSuspendedTransaction { | ||
LorittaDailyShopNotificationsConfigs.upsert(LorittaDailyShopNotificationsConfigs.id) { | ||
it[LorittaDailyShopNotificationsConfigs.id] = guild.idLong | ||
it[LorittaDailyShopNotificationsConfigs.notifyShopTrinkets] = params["notifyShopTrinkets"] == "on" | ||
it[LorittaDailyShopNotificationsConfigs.shopTrinketsChannelId] = params["shopTrinketsChannelId"]?.toLong() | ||
it[LorittaDailyShopNotificationsConfigs.shopTrinketsMessage] = params["shopTrinketsMessage"] | ||
|
||
it[LorittaDailyShopNotificationsConfigs.notifyNewTrinkets] = params["notifyNewTrinkets"] == "on" | ||
it[LorittaDailyShopNotificationsConfigs.newTrinketsChannelId] = params["newTrinketsChannelId"]?.toLong() | ||
it[LorittaDailyShopNotificationsConfigs.newTrinketsMessage] = params["newTrinketsMessage"] | ||
} | ||
} | ||
|
||
val config = GuildDailyShopTrinketsNotificationsConfig( | ||
result[LorittaDailyShopNotificationsConfigs.notifyShopTrinkets], | ||
result[LorittaDailyShopNotificationsConfigs.shopTrinketsChannelId], | ||
result[LorittaDailyShopNotificationsConfigs.shopTrinketsMessage], | ||
|
||
result[LorittaDailyShopNotificationsConfigs.notifyNewTrinkets], | ||
result[LorittaDailyShopNotificationsConfigs.newTrinketsChannelId], | ||
result[LorittaDailyShopNotificationsConfigs.newTrinketsMessage], | ||
) | ||
|
||
call.response.headerHXTrigger { | ||
playSoundEffect = "config-saved" | ||
showSpicyToast(EmbeddedSpicyToast.Type.SUCCESS, "Configuração salva!") | ||
} | ||
|
||
call.respondHtml( | ||
GuildDailyShopTrinketsNotificationsView( | ||
loritta.newWebsite!!, | ||
i18nContext, | ||
locale, | ||
getPathWithoutLocale(call), | ||
loritta.getLegacyLocaleById(locale.id), | ||
userIdentification, | ||
UserPremiumPlans.getPlanFromValue(loritta.getActiveMoneyFromDonations(userIdentification.id.toLong())), | ||
colorTheme, | ||
guild, | ||
"daily_shop_trinkets", | ||
config | ||
).generateHtml() | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.