mirror of
https://github.com/DreamExposure/DisCal-Discord-Bot.git
synced 2026-05-08 02:10:05 -05:00
Handle 403 on message update
This commit is contained in:
+17
-13
@@ -7,6 +7,7 @@ import discord4j.core.`object`.entity.Member
|
||||
import discord4j.core.`object`.entity.Message
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent
|
||||
import discord4j.core.spec.MessageCreateSpec
|
||||
import discord4j.rest.http.client.ClientException
|
||||
import org.dreamexposure.discal.client.message.embed.CalendarEmbed
|
||||
import org.dreamexposure.discal.core.`object`.GuildSettings
|
||||
import org.dreamexposure.discal.core.`object`.StaticMessage
|
||||
@@ -96,20 +97,23 @@ class DisplayCalendarCommand : SlashCommand {
|
||||
DatabaseManager.getStaticMessage(settings.guildID, messageId)
|
||||
.filter { it.type == StaticMessage.Type.CALENDAR_OVERVIEW }
|
||||
.flatMap { static ->
|
||||
event.client.getMessageById(static.channelId, static.messageId).flatMap { msg ->
|
||||
val gMono = event.interaction.guild.cache()
|
||||
val cMono = gMono.flatMap { it.getCalendar(static.calendarNumber) }
|
||||
event.client.getMessageById(static.channelId, static.messageId)
|
||||
.onErrorResume(ClientException.isStatusCode(403, 404)) {
|
||||
Mono.empty()
|
||||
}.flatMap { msg ->
|
||||
val gMono = event.interaction.guild.cache()
|
||||
val cMono = gMono.flatMap { it.getCalendar(static.calendarNumber) }
|
||||
|
||||
Mono.zip(gMono, cMono).flatMap(TupleUtils.function { guild, calendar ->
|
||||
CalendarEmbed.overview(guild, settings, calendar, true)
|
||||
.flatMap { msg.edit().withEmbedsOrNull(listOf(it)) }
|
||||
.flatMap {
|
||||
DatabaseManager.updateStaticMessage(
|
||||
static.copy(lastUpdate = Instant.now())
|
||||
)
|
||||
}.then(event.followupEphemeral(getCommonMsg("success.generic", settings)))
|
||||
})
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.notFound.message", settings)))
|
||||
Mono.zip(gMono, cMono).flatMap(TupleUtils.function { guild, calendar ->
|
||||
CalendarEmbed.overview(guild, settings, calendar, true)
|
||||
.flatMap { msg.edit().withEmbedsOrNull(listOf(it)) }
|
||||
.flatMap {
|
||||
DatabaseManager.updateStaticMessage(
|
||||
static.copy(lastUpdate = Instant.now())
|
||||
)
|
||||
}.then(event.followupEphemeral(getCommonMsg("success.generic", settings)))
|
||||
})
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.notFound.message", settings)))
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.notFound.staticMessage", settings)))
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.perms.elevated", settings)))
|
||||
}.onErrorResume(NumberFormatException::class.java) {
|
||||
|
||||
+4
-4
@@ -69,8 +69,8 @@ class StaticMessageService : ApplicationRunner {
|
||||
})
|
||||
}
|
||||
}
|
||||
}.onErrorResume(ClientException.isStatusCode(404)) {
|
||||
//Message or channel was deleted, delete from database
|
||||
}.onErrorResume(ClientException.isStatusCode(403, 404)) {
|
||||
//Message or channel was deleted OR access was revoked, delete from database
|
||||
DatabaseManager.deleteStaticMessage(data.guildId, data.messageId)
|
||||
}
|
||||
}.doOnError {
|
||||
@@ -97,8 +97,8 @@ class StaticMessageService : ApplicationRunner {
|
||||
.embedsOrNull(listOf(it))
|
||||
.build()
|
||||
).then(DatabaseManager.updateStaticMessage(msg.copy(lastUpdate = Instant.now())))
|
||||
}.onErrorResume(ClientException.isStatusCode(404)) {
|
||||
//Message or channel was deleted, delete from database
|
||||
}.onErrorResume(ClientException.isStatusCode(403, 404)) {
|
||||
//Message or channel was deleted OR access was revoked, delete from database
|
||||
DatabaseManager.deleteStaticMessage(msg.guildId, msg.messageId)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user