@@ -2,6 +2,7 @@ package org.dreamexposure.discal.core.business
22
33import discord4j.common.util.Snowflake
44import discord4j.core.DiscordClient
5+ import discord4j.core.`object`.component.LayoutComponent
56import discord4j.discordjson.json.MessageCreateRequest
67import discord4j.discordjson.json.MessageEditRequest
78import discord4j.rest.http.client.ClientException
@@ -24,9 +25,11 @@ import java.time.temporal.ChronoUnit
2425
2526@Component
2627class StaticMessageService (
28+ private val settingsService : GuildSettingsService ,
2729 private val staticMessageRepository : StaticMessageRepository ,
2830 private val staticMessageCache : StaticMessageCache ,
2931 private val calendarService : CalendarService ,
32+ private val rsvpService : RsvpService ,
3033 private val embedService : EmbedService ,
3134 private val componentService : ComponentService ,
3235 private val metricService : MetricService ,
@@ -81,12 +84,14 @@ class StaticMessageService(
8184 updateHour : Long
8285 ): StaticMessage {
8386 // Gather everything we need
87+ val settings = settingsService.getSettings(guildId)
8488 val calendar = calendarService.getCalendar(guildId, calendarNumber) ? : throw NotFoundException (" Calendar not found" )
8589 val channel = discordClient.getChannelById(channelId)
8690 val nextUpdate = ZonedDateTime .now(calendar.timezone)
8791 .truncatedTo(ChronoUnit .DAYS )
8892 .plusHours(updateHour + 24 )
8993 .toInstant()
94+ val additionalComponents = mutableListOf<LayoutComponent >()
9095
9196 val embed = when (type) {
9297 StaticMessage .Type .CALENDAR_OVERVIEW -> {
@@ -99,7 +104,16 @@ class StaticMessageService(
99104 }
100105 StaticMessage .Type .NEXT_EVENT -> {
101106 val event = calendarService.getUpcomingEvents(guildId, calendarNumber, 1 ).firstOrNull()
102- embedService.nextUpcomingEventEmbed(event, guildId, showUpdate = true )
107+ if (event != null ) additionalComponents.addAll(componentService.getEventRsvpComponents(event, settings))
108+
109+ embedService.nextUpcomingEventEmbed(event, null , settings, includeRsvp = false , showUpdate = true )
110+ }
111+ StaticMessage .Type .NEXT_EVENT_WITH_RSVP -> {
112+ val event = calendarService.getUpcomingEvents(guildId, calendarNumber, 1 ).firstOrNull()
113+ val rsvp = if (event == null ) null else rsvpService.getRsvp(guildId, event.id)
114+ if (event != null ) additionalComponents.addAll(componentService.getEventRsvpComponents(event, settings, true ))
115+
116+ embedService.nextUpcomingEventEmbed(event, rsvp, settings, includeRsvp = true , showUpdate = true )
103117 }
104118 }
105119
@@ -176,8 +190,10 @@ class StaticMessageService(
176190 }
177191
178192 val calendar = calendarService.getCalendar(guildId, old.calendarNumber) ? : throw NotFoundException (" Calendar not found" )
193+ val settings = settingsService.getSettings(guildId)
179194
180195 // Finally update the message
196+ val additionalComponents = mutableListOf<LayoutComponent >()
181197 val embed = when (old.type) {
182198 StaticMessage .Type .CALENDAR_OVERVIEW -> {
183199 val events = calendarService.getUpcomingEvents(guildId, old.calendarNumber, OVERVIEW_EVENT_COUNT , MAX_CUTOFF_DAYS )
@@ -189,7 +205,16 @@ class StaticMessageService(
189205 }
190206 StaticMessage .Type .NEXT_EVENT -> {
191207 val event = calendarService.getUpcomingEvents(guildId, old.calendarNumber, 1 ).firstOrNull()
192- embedService.nextUpcomingEventEmbed(event, guildId, showUpdate = true )
208+ if (event != null ) additionalComponents.addAll(componentService.getEventRsvpComponents(event, settings))
209+
210+ embedService.nextUpcomingEventEmbed(event, null , settings, includeRsvp = false , showUpdate = true )
211+ }
212+ StaticMessage .Type .NEXT_EVENT_WITH_RSVP -> {
213+ val event = calendarService.getUpcomingEvents(guildId, old.calendarNumber, 1 ).firstOrNull()
214+ val rsvp = if (event == null ) null else rsvpService.getRsvp(guildId, event.id)
215+ if (event != null ) additionalComponents.addAll(componentService.getEventRsvpComponents(event, settings, true ))
216+
217+ embedService.nextUpcomingEventEmbed(event, rsvp, settings, includeRsvp = true , showUpdate = true )
193218 }
194219 }
195220
@@ -229,6 +254,7 @@ class StaticMessageService(
229254
230255 val oldVersions = getStaticMessagesForCalendar(guildId, calendarNumber).filter { it.enabled }
231256 val calendar = calendarService.getCalendar(guildId, calendarNumber) ? : throw NotFoundException (" Calendar not found" )
257+ val settings = settingsService.getSettings(guildId)
232258
233259 oldVersions.forEach { old ->
234260 val existingData = discordClient.getMessageById(old.channelId, old.messageId)
@@ -271,6 +297,7 @@ class StaticMessageService(
271297 return @forEach
272298 }
273299
300+ val additionalComponents = mutableListOf<LayoutComponent >()
274301 val embed = when (old.type) {
275302 StaticMessage .Type .CALENDAR_OVERVIEW -> {
276303 val events = calendarService.getUpcomingEvents(guildId, calendarNumber, OVERVIEW_EVENT_COUNT )
@@ -282,7 +309,16 @@ class StaticMessageService(
282309 }
283310 StaticMessage .Type .NEXT_EVENT -> {
284311 val event = calendarService.getUpcomingEvents(guildId, calendarNumber, 1 ).firstOrNull()
285- embedService.nextUpcomingEventEmbed(event, guildId, showUpdate = true )
312+ if (event != null ) additionalComponents.addAll(componentService.getEventRsvpComponents(event, settings))
313+
314+ embedService.nextUpcomingEventEmbed(event, null , settings, includeRsvp = false , showUpdate = true )
315+ }
316+ StaticMessage .Type .NEXT_EVENT_WITH_RSVP -> {
317+ val event = calendarService.getUpcomingEvents(guildId, calendarNumber, 1 ).firstOrNull()
318+ val rsvp = if (event == null ) null else rsvpService.getRsvp(guildId, event.id)
319+ if (event != null ) additionalComponents.addAll(componentService.getEventRsvpComponents(event, settings, true ))
320+
321+ embedService.nextUpcomingEventEmbed(event, rsvp, settings, includeRsvp = true , showUpdate = true )
286322 }
287323 }
288324
0 commit comments