Skip to content

Commit

Permalink
I'm bummed that I can't do this in a cleaner way
Browse files Browse the repository at this point in the history
  • Loading branch information
NovaFox161 committed Mar 12, 2024
1 parent 57dc352 commit 7ca110b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.dreamexposure.discal.core.extensions.discord4j.getCalendar
import org.dreamexposure.discal.core.extensions.discord4j.hasControlRole
import org.dreamexposure.discal.core.`object`.GuildSettings
import org.dreamexposure.discal.core.`object`.new.Announcement
import org.dreamexposure.discal.core.`object`.new.WizardState
import org.dreamexposure.discal.core.`object`.new.AnnouncementWizardState
import org.dreamexposure.discal.core.utils.getCommonMsg
import org.springframework.stereotype.Component
import kotlin.jvm.optionals.getOrNull
Expand Down Expand Up @@ -97,7 +97,7 @@ class AnnouncementCommand(
.awaitSingle()
}

val newWizard = WizardState(
val newWizard = AnnouncementWizardState(
guildId = settings.guildID,
userId = event.interaction.user.id,
editing = false,
Expand Down Expand Up @@ -495,7 +495,7 @@ class AnnouncementCommand(
val announcement = announcementService.getAnnouncement(settings.guildID, announcementId)
?: return event.followupEphemeral(getCommonMsg("error.notFound.announcement", settings)).awaitSingle()

val newWizard = WizardState(
val newWizard = AnnouncementWizardState(
guildId = settings.guildID,
userId = event.interaction.user.id,
editing = true,
Expand Down Expand Up @@ -531,7 +531,7 @@ class AnnouncementCommand(
val announcement = announcementService.getAnnouncement(settings.guildID, announcementId)
?: return event.followupEphemeral(getCommonMsg("error.notFound.announcement", settings)).awaitSingle()

val newWizard = WizardState(
val newWizard = AnnouncementWizardState(
guildId = settings.guildID,
userId = event.interaction.user.id,
editing = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import discord4j.rest.http.client.ClientException
import kotlinx.coroutines.reactor.awaitSingle
import kotlinx.coroutines.reactor.awaitSingleOrNull
import org.dreamexposure.discal.AnnouncementCache
import org.dreamexposure.discal.AnnouncementWizard
import org.dreamexposure.discal.AnnouncementWizardStateCache
import org.dreamexposure.discal.core.database.AnnouncementData
import org.dreamexposure.discal.core.database.AnnouncementRepository
Expand All @@ -16,6 +15,7 @@ import org.dreamexposure.discal.core.entities.Event
import org.dreamexposure.discal.core.extensions.discord4j.getCalendar
import org.dreamexposure.discal.core.logger.LOGGER
import org.dreamexposure.discal.core.`object`.new.Announcement
import org.dreamexposure.discal.core.`object`.new.AnnouncementWizardState
import org.springframework.beans.factory.BeanFactory
import org.springframework.beans.factory.getBean
import org.springframework.stereotype.Component
Expand Down Expand Up @@ -247,11 +247,11 @@ class AnnouncementService(
metricService.recordAnnouncementTaskDuration("guild", taskTimer.totalTimeMillis)
}

suspend fun getWizard(guildId: Snowflake, userId: Snowflake): AnnouncementWizard? {
suspend fun getWizard(guildId: Snowflake, userId: Snowflake): AnnouncementWizardState? {
return announcementWizardStateCache.get(guildId, userId)
}

suspend fun putWizard(state: AnnouncementWizard) {
suspend fun putWizard(state: AnnouncementWizardState) {
announcementWizardStateCache.put(state.guildId, state.userId, state)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ package org.dreamexposure.discal.core.`object`.new

import discord4j.common.util.Snowflake

data class WizardState<T>(
val guildId: Snowflake,
val userId: Snowflake,
val editing: Boolean,
val entity: T,
abstract class WizardState<T>(
open val guildId: Snowflake,
open val userId: Snowflake,
open val editing: Boolean,
open val entity: T,
)

data class AnnouncementWizardState(
override val guildId: Snowflake,
override val userId: Snowflake,
override val editing: Boolean,
override val entity: Announcement,
) : WizardState<Announcement>(guildId, userId, editing, entity)
4 changes: 1 addition & 3 deletions core/src/main/kotlin/org/dreamexposure/discal/typealiases.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ typealias CalendarCache = CacheRepository<Snowflake, Array<Calendar>>
typealias RsvpCache = CacheRepository<String, Rsvp>
typealias StaticMessageCache = CacheRepository<Snowflake, StaticMessage>
typealias AnnouncementCache = CacheRepository<Snowflake, Array<Announcement>>
typealias AnnouncementWizardStateCache = CacheRepository<Snowflake, AnnouncementWizard>

typealias AnnouncementWizard = WizardState<Announcement>
typealias AnnouncementWizardStateCache = CacheRepository<Snowflake, AnnouncementWizardState>

0 comments on commit 7ca110b

Please sign in to comment.