Skip to content

Commit

Permalink
Implement error handling for attempting to update dedicated channels …
Browse files Browse the repository at this point in the history
…that don't exist anymore
  • Loading branch information
bombies committed Sep 16, 2023
1 parent e6bf4b0 commit a57ae9c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/main/events/AbstractEventController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import main.main.Robertify
import net.dv8tion.jda.api.events.GenericEvent
import net.dv8tion.jda.api.hooks.ListenerAdapter

abstract class AbstractEventController : ListenerAdapter() {
abstract class AbstractEventController {

companion object {
protected val shardManager = Robertify.shardManager
Expand Down
4 changes: 0 additions & 4 deletions src/main/kotlin/main/main/Listener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ class Listener : AbstractEventController() {
}
}

override fun onGuildReady(event: GuildReadyEvent) {
logger.info("Guild ${event.guild.name} is ready")
}

private val guildJoinListener =
onEvent<GuildJoinEvent> { event ->
val guild = event.guild
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/main/main/Robertify.kt
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ object Robertify {
loadNeededSlashCommands(guild)
rescheduleUnbans(guild)
RemindersConfig(guild).scheduleReminders()
logger.info("${guild.name} is ready!")

// GuildResumeManager(guild).loadTracks()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import net.dv8tion.jda.api.entities.MessageHistory
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel
import net.dv8tion.jda.api.exceptions.ErrorHandler
import net.dv8tion.jda.api.exceptions.ErrorResponseException
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException
import net.dv8tion.jda.api.interactions.components.ActionRow
import net.dv8tion.jda.api.interactions.components.buttons.Button
Expand Down Expand Up @@ -181,7 +182,7 @@ class RequestChannelConfig(private val guild: Guild, private val shardManager: S

suspend fun isChannelSet(): Boolean {
val obj = getGuildModel().dedicated_channel
return obj != null && obj.channel_id != -1L
return obj.channel_id != -1L
}

suspend fun isRequestChannel(channel: GuildMessageChannel): Boolean = when {
Expand Down Expand Up @@ -215,25 +216,14 @@ class RequestChannelConfig(private val guild: Guild, private val shardManager: S
msg.editMessage(localeManager.getMessage(DedicatedChannelMessages.DEDICATED_CHANNEL_QUEUE_NOTHING_PLAYING))
.setEmbeds(eb.build())
.await()
// TODO: Handle unknown message error properly
// msgRequest.queue(
// { msg: Message ->
//
// },
// ErrorHandler()
// .handle(
// ErrorResponse.UNKNOWN_MESSAGE
// ) { removeChannel() }
// .handle(
// ErrorResponse.MISSING_PERMISSIONS
// ) {
// sendEditErrorMessage(
// announcementChannel
// )
// }
// )
} catch (e: InsufficientPermissionException) {
if (e.message!!.contains("MESSAGE_SEND")) sendEditErrorMessage(announcementChannel)
} catch (e: ErrorResponseException) {
when (e.errorResponse) {
ErrorResponse.MISSING_PERMISSIONS -> sendEditErrorMessage(announcementChannel)
ErrorResponse.UNKNOWN_MESSAGE -> removeChannel()
else -> {}
}
}
} else {
eb.setColor(theme.color)
Expand Down

0 comments on commit a57ae9c

Please sign in to comment.