Skip to content

Commit

Permalink
Removing more deprecated code and warnings where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
NovaFox161 committed Dec 11, 2024
1 parent b6bec26 commit 9d667a4
Show file tree
Hide file tree
Showing 20 changed files with 20 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Message> {
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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 9d667a4

Please sign in to comment.