From 9d667a4ff2f84d344183d6bb0c3e151fdb544342 Mon Sep 17 00:00:00 2001 From: NovaFox161 Date: Wed, 11 Dec 2024 16:06:02 -0600 Subject: [PATCH] Removing more deprecated code and warnings where possible --- .../discal/client/commands/SlashCommand.kt | 11 +---------- .../discal/client/commands/dev/DevCommand.kt | 2 +- .../commands/global/AnnouncementCommand.kt | 2 +- .../client/commands/global/CalendarCommand.kt | 2 +- .../client/commands/global/DiscalCommand.kt | 2 +- .../commands/global/DisplayCalendarCommand.kt | 2 +- .../client/commands/global/EventCommand.kt | 2 +- .../client/commands/global/EventsCommand.kt | 2 +- .../client/commands/global/HelpCommand.kt | 2 +- .../commands/global/LinkCalendarCommand.kt | 2 +- .../client/commands/global/RsvpCommand.kt | 2 +- .../client/commands/global/SettingsCommand.kt | 2 +- .../client/commands/global/TimeCommand.kt | 2 +- .../client/commands/premium/AddCalCommand.kt | 2 +- .../listeners/discord/SlashCommandListener.kt | 2 +- .../object/network/discal/CredentialData.kt | 19 ------------------- .../discal/core/object/new/Credential.kt | 2 +- .../core/object/web/AuthenticationState.kt | 2 ++ .../discal/core/object/web/WebCalendar.kt | 1 + .../discal/core/object/web/WebRole.kt | 2 +- 20 files changed, 20 insertions(+), 45 deletions(-) delete mode 100644 core/src/main/kotlin/org/dreamexposure/discal/core/object/network/discal/CredentialData.kt diff --git a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/SlashCommand.kt b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/SlashCommand.kt index 6cc018680..61ce37372 100644 --- a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/SlashCommand.kt +++ b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/SlashCommand.kt @@ -2,11 +2,8 @@ package org.dreamexposure.discal.client.commands import discord4j.core.event.domain.interaction.ChatInputInteractionEvent import discord4j.core.`object`.entity.Message -import kotlinx.coroutines.reactor.awaitSingle -import kotlinx.coroutines.reactor.mono import org.dreamexposure.discal.core.`object`.new.GuildSettings import org.dreamexposure.discal.core.utils.MessageSourceLoader -import reactor.core.publisher.Mono interface SlashCommand { val name: String @@ -15,14 +12,8 @@ interface SlashCommand { fun shouldDefer(event: ChatInputInteractionEvent): Boolean = true - @Deprecated("Use new handleSuspend for K-coroutines") - fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Mono { - return mono { suspendHandle(event, settings) } - } - suspend fun suspendHandle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { - return handle(event, settings).awaitSingle() - } + suspend fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Message fun getMessage(key: String, settings: GuildSettings, vararg args: String): String { val src = MessageSourceLoader.getSourceByPath("command/$name/$name") diff --git a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/dev/DevCommand.kt b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/dev/DevCommand.kt index e425e9991..21c58c43e 100644 --- a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/dev/DevCommand.kt +++ b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/dev/DevCommand.kt @@ -22,7 +22,7 @@ class DevCommand( override val hasSubcommands = true override val ephemeral = true - override suspend fun suspendHandle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { + override suspend fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { // Validate this user is actually a dev if (!GlobalVal.devUserIds.contains(event.interaction.user.id)) return event.createFollowup(getMessage("error.notDeveloper", settings)) diff --git a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/AnnouncementCommand.kt b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/AnnouncementCommand.kt index dcbfe9bca..c59b3015d 100644 --- a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/AnnouncementCommand.kt +++ b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/AnnouncementCommand.kt @@ -31,7 +31,7 @@ class AnnouncementCommand( override val hasSubcommands = true override val ephemeral = true - override suspend fun suspendHandle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { + override suspend fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { return when (event.options[0].name) { "create" -> create(event, settings) "type" -> type(event, settings) diff --git a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/CalendarCommand.kt b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/CalendarCommand.kt index cd243d982..232e32f3d 100644 --- a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/CalendarCommand.kt +++ b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/CalendarCommand.kt @@ -32,7 +32,7 @@ class CalendarCommand( override val ephemeral = true private val OVERVIEW_EVENT_COUNT = Config.CALENDAR_OVERVIEW_DEFAULT_EVENT_COUNT.getInt() - override suspend fun suspendHandle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { + override suspend fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { return when (event.options[0].name) { "view" -> view(event, settings) "list" -> list(event, settings) diff --git a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/DiscalCommand.kt b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/DiscalCommand.kt index 56bf772e0..838800b7e 100644 --- a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/DiscalCommand.kt +++ b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/DiscalCommand.kt @@ -20,7 +20,7 @@ class DiscalCommand( override val hasSubcommands = false override val ephemeral = false - override suspend fun suspendHandle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { + override suspend fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { val announcementCount = announcementService.getAnnouncementCount() val calendarCount = calendarService.getCalendarCount() val guildCount = event.client.guilds.count().awaitSingle() diff --git a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/DisplayCalendarCommand.kt b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/DisplayCalendarCommand.kt index e0edabc35..c31554607 100644 --- a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/DisplayCalendarCommand.kt +++ b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/DisplayCalendarCommand.kt @@ -24,7 +24,7 @@ class DisplayCalendarCommand( override val ephemeral = true - override suspend fun suspendHandle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { + override suspend fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { return when (event.options[0].name) { "new" -> new(event, settings) else -> throw IllegalStateException("Invalid subcommand specified") diff --git a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/EventCommand.kt b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/EventCommand.kt index 3f623881c..22402ee37 100644 --- a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/EventCommand.kt +++ b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/EventCommand.kt @@ -34,7 +34,7 @@ class EventCommand( override val hasSubcommands = true override val ephemeral = true - override suspend fun suspendHandle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { + override suspend fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { return when (event.options[0].name) { "create" -> create(event, settings) "name" -> name(event, settings) diff --git a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/EventsCommand.kt b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/EventsCommand.kt index a6d581fe8..177c9835d 100644 --- a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/EventsCommand.kt +++ b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/EventsCommand.kt @@ -26,7 +26,7 @@ class EventsCommand( override val ephemeral = false - override suspend fun suspendHandle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { + override suspend fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { return when (event.options[0].name) { "upcoming" -> upcomingEvents(event, settings) "ongoing" -> ongoingEvents(event, settings) diff --git a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/HelpCommand.kt b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/HelpCommand.kt index 92c199e6a..e41b4216c 100644 --- a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/HelpCommand.kt +++ b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/HelpCommand.kt @@ -14,7 +14,7 @@ class HelpCommand : SlashCommand { override val hasSubcommands = false override val ephemeral = true - override suspend fun suspendHandle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { + override suspend fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { return event.createFollowup( getMessage("error.workInProgress", settings, "${Config.URL_BASE.getString()}/commands") ).withEphemeral(ephemeral).awaitSingle() diff --git a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/LinkCalendarCommand.kt b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/LinkCalendarCommand.kt index 2fe0b6304..893cf8d51 100644 --- a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/LinkCalendarCommand.kt +++ b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/LinkCalendarCommand.kt @@ -25,7 +25,7 @@ class LinkCalendarCommand( private val OVERVIEW_EVENT_COUNT = Config.CALENDAR_OVERVIEW_DEFAULT_EVENT_COUNT.getInt() - override suspend fun suspendHandle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { + override suspend fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { val showOverview = event.getOption("overview") .flatMap(ApplicationCommandInteractionOption::getValue) .map(ApplicationCommandInteractionOptionValue::asBoolean) diff --git a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/RsvpCommand.kt b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/RsvpCommand.kt index 653d0986b..720e37a0b 100644 --- a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/RsvpCommand.kt +++ b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/RsvpCommand.kt @@ -27,7 +27,7 @@ class RsvpCommand( override val ephemeral = true - override suspend fun suspendHandle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { + override suspend fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { return when (event.options[0].name) { "ontime" -> onTime(event, settings) "late" -> late(event, settings) diff --git a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/SettingsCommand.kt b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/SettingsCommand.kt index af4b88f3c..3bf422255 100644 --- a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/SettingsCommand.kt +++ b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/SettingsCommand.kt @@ -25,7 +25,7 @@ class SettingsCommand( override val hasSubcommands = true override val ephemeral = true - override suspend fun suspendHandle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { + override suspend fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { // Validate permissions val hasElevatedPerms = permissionService.hasElevatedPermissions(settings.guildId, event.interaction.user.id) if (!hasElevatedPerms) return event.createFollowup(getCommonMsg("error.perms.elevated", settings.locale)) diff --git a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/TimeCommand.kt b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/TimeCommand.kt index 79adf9fc8..c11e2c9e8 100644 --- a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/TimeCommand.kt +++ b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/TimeCommand.kt @@ -21,7 +21,7 @@ class TimeCommand( override val hasSubcommands = false override val ephemeral = true - override suspend fun suspendHandle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { + override suspend fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { val calendarNumber = event.getOption("calendar") .flatMap(ApplicationCommandInteractionOption::getValue) .map(ApplicationCommandInteractionOptionValue::asLong) diff --git a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/premium/AddCalCommand.kt b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/premium/AddCalCommand.kt index a7f42e7ac..4070d8222 100644 --- a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/premium/AddCalCommand.kt +++ b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/premium/AddCalCommand.kt @@ -20,7 +20,7 @@ class AddCalCommand( override val hasSubcommands = false override val ephemeral = true - override suspend fun suspendHandle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { + override suspend fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { //TODO: Remove dev-only and switch to patron-only once this is completed if (!settings.devGuild) return event.createFollowup(getCommonMsg("error.disabled", settings.locale)) .withEphemeral(ephemeral) diff --git a/client/src/main/kotlin/org/dreamexposure/discal/client/listeners/discord/SlashCommandListener.kt b/client/src/main/kotlin/org/dreamexposure/discal/client/listeners/discord/SlashCommandListener.kt index 5bd36dc64..e48807816 100644 --- a/client/src/main/kotlin/org/dreamexposure/discal/client/listeners/discord/SlashCommandListener.kt +++ b/client/src/main/kotlin/org/dreamexposure/discal/client/listeners/discord/SlashCommandListener.kt @@ -38,7 +38,7 @@ class SlashCommandListener( val settings = settingsService.getSettings(event.interaction.guildId.get()) - command.suspendHandle(event, settings) + command.handle(event, settings) } catch (e: Exception) { LOGGER.error(DEFAULT, "Error handling slash command | $event", e) diff --git a/core/src/main/kotlin/org/dreamexposure/discal/core/object/network/discal/CredentialData.kt b/core/src/main/kotlin/org/dreamexposure/discal/core/object/network/discal/CredentialData.kt deleted file mode 100644 index ca886d677..000000000 --- a/core/src/main/kotlin/org/dreamexposure/discal/core/object/network/discal/CredentialData.kt +++ /dev/null @@ -1,19 +0,0 @@ -package org.dreamexposure.discal.core.`object`.network.discal - -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable -import org.dreamexposure.discal.core.serializers.InstantAsStringSerializer -import java.time.Instant - -@Serializable -@Deprecated("Really shouldn't need this after the auth wrapper has been redone, replaced with the TokenV1Model") -data class CredentialData( - @SerialName("access_token") - val accessToken: String, - - @SerialName("valid_until") - @Serializable(with = InstantAsStringSerializer::class) - val validUntil: Instant -) { - fun isExpired(): Boolean = Instant.now().isAfter(validUntil) -} diff --git a/core/src/main/kotlin/org/dreamexposure/discal/core/object/new/Credential.kt b/core/src/main/kotlin/org/dreamexposure/discal/core/object/new/Credential.kt index ffcaca1e9..2bdb43b66 100644 --- a/core/src/main/kotlin/org/dreamexposure/discal/core/object/new/Credential.kt +++ b/core/src/main/kotlin/org/dreamexposure/discal/core/object/new/Credential.kt @@ -8,7 +8,7 @@ import org.dreamexposure.discal.core.extensions.asInstantMilli import java.time.Instant -@Suppress("DataClassPrivateConstructor") +@ConsistentCopyVisibility data class Credential private constructor( val credentialNumber: Int, var expiresAt: Instant, diff --git a/core/src/main/kotlin/org/dreamexposure/discal/core/object/web/AuthenticationState.kt b/core/src/main/kotlin/org/dreamexposure/discal/core/object/web/AuthenticationState.kt index ccb626e0b..a4b4c14c2 100644 --- a/core/src/main/kotlin/org/dreamexposure/discal/core/object/web/AuthenticationState.kt +++ b/core/src/main/kotlin/org/dreamexposure/discal/core/object/web/AuthenticationState.kt @@ -4,7 +4,9 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.Transient +@ConsistentCopyVisibility @Serializable +@Deprecated("Prefer to use new authentication implementations.") data class AuthenticationState private constructor( @Transient val success: Boolean = true, diff --git a/core/src/main/kotlin/org/dreamexposure/discal/core/object/web/WebCalendar.kt b/core/src/main/kotlin/org/dreamexposure/discal/core/object/web/WebCalendar.kt index 5f49197db..b597403d7 100644 --- a/core/src/main/kotlin/org/dreamexposure/discal/core/object/web/WebCalendar.kt +++ b/core/src/main/kotlin/org/dreamexposure/discal/core/object/web/WebCalendar.kt @@ -5,6 +5,7 @@ import kotlinx.serialization.Serializable import org.dreamexposure.discal.core.enums.calendar.CalendarHost import org.dreamexposure.discal.core.`object`.new.model.discal.CalendarV3Model +@ConsistentCopyVisibility @Serializable @Deprecated("Prefer to use the CalendarV3Model impl") data class WebCalendar internal constructor( diff --git a/core/src/main/kotlin/org/dreamexposure/discal/core/object/web/WebRole.kt b/core/src/main/kotlin/org/dreamexposure/discal/core/object/web/WebRole.kt index efd23494c..9cc9b8fcf 100644 --- a/core/src/main/kotlin/org/dreamexposure/discal/core/object/web/WebRole.kt +++ b/core/src/main/kotlin/org/dreamexposure/discal/core/object/web/WebRole.kt @@ -5,7 +5,7 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.builtins.LongAsStringSerializer import org.dreamexposure.discal.core.`object`.new.model.discal.WebRoleV3Model -@Suppress("DataClassPrivateConstructor") +@ConsistentCopyVisibility @Serializable @Deprecated("Prefer to use WebRoleV3Model instead") data class WebRole private constructor(