Skip to content

Commit

Permalink
Two other new commands that I forgot to include changes to
Browse files Browse the repository at this point in the history
  • Loading branch information
NovaFox161 committed Nov 21, 2024
1 parent 8b9c33f commit 9cac32b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import discord4j.core.`object`.command.ApplicationCommandInteractionOptionValue
import discord4j.core.`object`.entity.Message
import discord4j.rest.util.AllowedMentions
import kotlinx.coroutines.reactor.awaitSingle
import kotlinx.coroutines.reactor.awaitSingleOrNull
import org.dreamexposure.discal.client.commands.SlashCommand
import org.dreamexposure.discal.core.business.AnnouncementService
import org.dreamexposure.discal.core.business.CalendarService
import org.dreamexposure.discal.core.business.EmbedService
import org.dreamexposure.discal.core.business.PermissionService
import org.dreamexposure.discal.core.crypto.KeyGenerator
import org.dreamexposure.discal.core.enums.event.EventColor
import org.dreamexposure.discal.core.extensions.discord4j.getCalendar
import org.dreamexposure.discal.core.`object`.new.Announcement
import org.dreamexposure.discal.core.`object`.new.AnnouncementWizardState
import org.dreamexposure.discal.core.`object`.new.GuildSettings
Expand All @@ -26,6 +25,7 @@ class AnnouncementCommand(
private val announcementService: AnnouncementService,
private val permissionService: PermissionService,
private val embedService: EmbedService,
private val calendarService: CalendarService,
) : SlashCommand {
override val name = "announcement"
override val hasSubcommands = true
Expand Down Expand Up @@ -182,10 +182,7 @@ class AnnouncementCommand(
}

// Validate event actually exists
val calendarEvent = event.interaction.guild
.flatMap { it.getCalendar(announcement.calendarNumber) }
.flatMap { it.getEvent(eventId) }
.awaitSingleOrNull()
val calendarEvent = calendarService.getEvent(announcement.guildId, announcement.calendarNumber, eventId)
if (calendarEvent == null) {
return event.createFollowup(getCommonMsg("error.notFound.event", settings.locale))
.withEphemeral(ephemeral)
Expand All @@ -194,7 +191,7 @@ class AnnouncementCommand(
}

// Handle what format the ID is actually saved in
val idToSet = if (announcement.type == Announcement.Type.RECUR) calendarEvent.eventId.split("_")[0]
val idToSet = if (announcement.type == Announcement.Type.RECUR) calendarEvent.id.split("_")[0]
else eventId

val alteredWizard = existingWizard.copy(entity = announcement.copy(eventId = idToSet))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import discord4j.core.`object`.command.ApplicationCommandInteractionOption
import discord4j.core.`object`.command.ApplicationCommandInteractionOptionValue
import discord4j.core.`object`.entity.Message
import kotlinx.coroutines.reactor.awaitSingle
import kotlinx.coroutines.reactor.awaitSingleOrNull
import org.dreamexposure.discal.client.commands.SlashCommand
import org.dreamexposure.discal.core.business.CalendarService
import org.dreamexposure.discal.core.business.StaticMessageService
import org.dreamexposure.discal.core.extensions.discord4j.getCalendar
import org.dreamexposure.discal.core.extensions.discord4j.hasElevatedPermissions
import org.dreamexposure.discal.core.`object`.new.GuildSettings
import org.dreamexposure.discal.core.utils.getCommonMsg
Expand All @@ -17,6 +16,7 @@ import org.springframework.stereotype.Component
@Component
class DisplayCalendarCommand(
private val staticMessageService: StaticMessageService,
private val calendarService: CalendarService,
) : SlashCommand {
override val name = "displaycal"
override val hasSubcommands = true
Expand Down Expand Up @@ -49,7 +49,7 @@ class DisplayCalendarCommand(
.awaitSingle()

// Validate calendar exists
val calendar = event.interaction.guild.flatMap { it.getCalendar(calendarNumber) }.awaitSingleOrNull()
val calendar = calendarService.getCalendar(settings.guildId, calendarNumber)
if (calendar == null)
return event.createFollowup(getCommonMsg("error.notFound.calendar", settings.locale))
.withEphemeral(ephemeral)
Expand Down

0 comments on commit 9cac32b

Please sign in to comment.