Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/root' into root
Browse files Browse the repository at this point in the history
  • Loading branch information
weblate committed Oct 27, 2023
2 parents e04665b + c82e73c commit a17ef13
Show file tree
Hide file tree
Showing 29 changed files with 195 additions and 109 deletions.
4 changes: 0 additions & 4 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Writerside/v.list
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<!DOCTYPE vars SYSTEM "https://resources.jetbrains.com/writerside/1.0/vars.dtd">
<vars>
<var name="product" value="Kord Extensions" />
<var name="version" value="1.5.10-SNAPSHOT" />
<var name="version" value="1.6.0-SNAPSHOT" />
</vars>
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import com.kotlindiscord.kord.extensions.pagination.pages.Page
import com.kotlindiscord.kord.extensions.pagination.pages.Pages
import com.kotlindiscord.kord.extensions.plugins.extra.MappingsPlugin
import com.kotlindiscord.kord.extensions.sentry.BreadcrumbType
import com.kotlindiscord.kord.extensions.types.respond
import dev.kord.core.event.interaction.ChatInputCommandInteractionCreateEvent
import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.coroutines.DelicateCoroutinesApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.extensions.ephemeralMessageCommand
import com.kotlindiscord.kord.extensions.extensions.ephemeralSlashCommand
import com.kotlindiscord.kord.extensions.extensions.event
import com.kotlindiscord.kord.extensions.types.respond
import com.kotlindiscord.kord.extensions.utils.dm
import com.kotlindiscord.kord.extensions.utils.getJumpUrl
import com.kotlindiscord.kord.extensions.utils.tagOrUsername
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import com.kotlindiscord.kord.extensions.modules.extra.pluralkit.storage.PKGuild
import com.kotlindiscord.kord.extensions.modules.extra.pluralkit.utils.LRUHashMap
import com.kotlindiscord.kord.extensions.storage.StorageType
import com.kotlindiscord.kord.extensions.storage.StorageUnit
import com.kotlindiscord.kord.extensions.types.respond
import com.kotlindiscord.kord.extensions.utils.scheduling.Scheduler
import com.kotlindiscord.kord.extensions.utils.scheduling.Task
import dev.kord.common.entity.Permission
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kotlin.incremental = true
ksp.incremental = false

# Must be updated for Writerside in v.list
projectVersion = 1.5.11-SNAPSHOT
projectVersion = 1.6.0-SNAPSHOT

#dokka will run out of memory with the default meta space
org.gradle.jvmargs=-XX:MaxMetaspaceSize=1024m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

package com.kotlindiscord.kord.extensions.annotations

/** Marks a function that always results in public interaction responses. **/
@RequiresOptIn(
message = "This function will always result in a public interaction response, even if used within an " +
"ephemeral interaction.",
level = RequiresOptIn.Level.WARNING
)
@Target(AnnotationTarget.FUNCTION)
public annotation class AlwaysPublicResponse
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

package com.kotlindiscord.kord.extensions.annotations

/** Marks a function that may result in unexpected behaviour, and ask the developer to check the docs. **/
@RequiresOptIn(
message = "Calling this function may result in unexpected behaviour. Please ensure you read its documentation " +
"comment before continuing.",
level = RequiresOptIn.Level.WARNING
)
@Target(AnnotationTarget.FUNCTION)
public annotation class UnexpectedBehaviour
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import com.kotlindiscord.kord.extensions.commands.events.EphemeralMessageCommand
import com.kotlindiscord.kord.extensions.components.forms.ModalForm
import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.types.FailureReason
import com.kotlindiscord.kord.extensions.types.respond
import com.kotlindiscord.kord.extensions.utils.MutableStringKeyedMap
import com.kotlindiscord.kord.extensions.utils.getLocale
import dev.kord.common.annotation.KordUnsafe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import com.kotlindiscord.kord.extensions.commands.events.PublicMessageCommandSuc
import com.kotlindiscord.kord.extensions.components.forms.ModalForm
import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.types.FailureReason
import com.kotlindiscord.kord.extensions.types.respond
import com.kotlindiscord.kord.extensions.utils.MutableStringKeyedMap
import com.kotlindiscord.kord.extensions.utils.getLocale
import dev.kord.common.annotation.KordUnsafe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import com.kotlindiscord.kord.extensions.commands.events.*
import com.kotlindiscord.kord.extensions.components.forms.ModalForm
import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.types.FailureReason
import com.kotlindiscord.kord.extensions.types.respond
import com.kotlindiscord.kord.extensions.utils.MutableStringKeyedMap
import com.kotlindiscord.kord.extensions.utils.getLocale
import dev.kord.common.annotation.KordUnsafe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import com.kotlindiscord.kord.extensions.commands.events.*
import com.kotlindiscord.kord.extensions.components.forms.ModalForm
import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.types.FailureReason
import com.kotlindiscord.kord.extensions.types.respond
import com.kotlindiscord.kord.extensions.utils.MutableStringKeyedMap
import com.kotlindiscord.kord.extensions.utils.getLocale
import dev.kord.common.annotation.KordUnsafe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import com.kotlindiscord.kord.extensions.commands.events.EphemeralUserCommandSuc
import com.kotlindiscord.kord.extensions.components.forms.ModalForm
import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.types.FailureReason
import com.kotlindiscord.kord.extensions.types.respond
import com.kotlindiscord.kord.extensions.utils.MutableStringKeyedMap
import com.kotlindiscord.kord.extensions.utils.getLocale
import dev.kord.common.annotation.KordUnsafe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import com.kotlindiscord.kord.extensions.commands.events.PublicUserCommandSuccee
import com.kotlindiscord.kord.extensions.components.forms.ModalForm
import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.types.FailureReason
import com.kotlindiscord.kord.extensions.types.respond
import com.kotlindiscord.kord.extensions.utils.MutableStringKeyedMap
import com.kotlindiscord.kord.extensions.utils.getLocale
import dev.kord.common.annotation.KordUnsafe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ package com.kotlindiscord.kord.extensions.components.buttons
import com.kotlindiscord.kord.extensions.DiscordRelayedException
import com.kotlindiscord.kord.extensions.components.forms.ModalForm
import com.kotlindiscord.kord.extensions.types.FailureReason
import com.kotlindiscord.kord.extensions.types.respond
import com.kotlindiscord.kord.extensions.utils.MutableStringKeyedMap
import com.kotlindiscord.kord.extensions.utils.getLocale
import com.kotlindiscord.kord.extensions.utils.scheduling.Task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ package com.kotlindiscord.kord.extensions.components.buttons
import com.kotlindiscord.kord.extensions.DiscordRelayedException
import com.kotlindiscord.kord.extensions.components.forms.ModalForm
import com.kotlindiscord.kord.extensions.types.FailureReason
import com.kotlindiscord.kord.extensions.types.respond
import com.kotlindiscord.kord.extensions.utils.MutableStringKeyedMap
import com.kotlindiscord.kord.extensions.utils.getLocale
import com.kotlindiscord.kord.extensions.utils.scheduling.Task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.kotlindiscord.kord.extensions.components.forms.ModalForm
import com.kotlindiscord.kord.extensions.components.menus.channel.InitialEphemeralSelectMenuResponseBuilder
import com.kotlindiscord.kord.extensions.types.EphemeralInteractionContext
import com.kotlindiscord.kord.extensions.types.FailureReason
import com.kotlindiscord.kord.extensions.types.respond
import com.kotlindiscord.kord.extensions.utils.MutableStringKeyedMap
import com.kotlindiscord.kord.extensions.utils.getLocale
import com.kotlindiscord.kord.extensions.utils.scheduling.Task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.kotlindiscord.kord.extensions.components.forms.ModalForm
import com.kotlindiscord.kord.extensions.components.menus.channel.InitialEphemeralSelectMenuResponseBuilder
import com.kotlindiscord.kord.extensions.types.FailureReason
import com.kotlindiscord.kord.extensions.types.PublicInteractionContext
import com.kotlindiscord.kord.extensions.types.respond
import com.kotlindiscord.kord.extensions.utils.MutableStringKeyedMap
import com.kotlindiscord.kord.extensions.utils.getLocale
import com.kotlindiscord.kord.extensions.utils.scheduling.Task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import com.kotlindiscord.kord.extensions.extensions.chatCommand
import com.kotlindiscord.kord.extensions.extensions.ephemeralSlashCommand
import com.kotlindiscord.kord.extensions.sentry.SentryAdapter
import com.kotlindiscord.kord.extensions.sentry.sentryId
import com.kotlindiscord.kord.extensions.types.respond
import com.kotlindiscord.kord.extensions.utils.respond
import com.kotlindiscord.kord.extensions.utils.tagOrUsername
import io.sentry.Sentry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

package com.kotlindiscord.kord.extensions.types

import com.kotlindiscord.kord.extensions.annotations.AlwaysPublicResponse
import com.kotlindiscord.kord.extensions.annotations.UnexpectedBehaviour
import com.kotlindiscord.kord.extensions.pagination.EphemeralResponsePaginator
import com.kotlindiscord.kord.extensions.pagination.PublicFollowUpPaginator
import com.kotlindiscord.kord.extensions.pagination.builders.PaginatorBuilder
Expand All @@ -20,58 +22,53 @@ import dev.kord.rest.builder.message.create.FollowupMessageCreateBuilder
import dev.kord.rest.builder.message.modify.InteractionResponseModifyBuilder
import java.util.*

/** Interface representing an ephemeral-only interaction action context. **/
public interface EphemeralInteractionContext {
/** Response created by acknowledging the interaction ephemerally. **/
public val interactionResponse: EphemeralMessageInteractionResponseBehavior
}

/**
* Respond to the current interaction with an ephemeral followup.
* Interface representing an ephemeral interaction context.
*
* **Note:** Calling this twice (or at all after [edit]) will result in a public followup!
* @see InteractionContext
*/
public suspend inline fun EphemeralInteractionContext.respond(
builder: FollowupMessageCreateBuilder.() -> Unit
): EphemeralFollowupMessage = interactionResponse.createEphemeralFollowup { builder() }
public interface EphemeralInteractionContext : InteractionContext<
EphemeralMessageInteractionResponseBehavior,
EphemeralMessageInteractionResponse,
EphemeralFollowupMessage,
PublicFollowupMessage,
> {

/** Respond to the current interaction with a public followup. **/
public suspend inline fun EphemeralInteractionContext.respondPublic(
builder: FollowupMessageCreateBuilder.() -> Unit
): PublicFollowupMessage = interactionResponse.createPublicFollowup { builder() }
public override suspend fun respond(
builder: suspend FollowupMessageCreateBuilder.() -> Unit,
): EphemeralFollowupMessage = interactionResponse.createEphemeralFollowup { builder() }

/**
* Edit the current interaction's response.
*/
public suspend inline fun EphemeralInteractionContext.edit(
builder: InteractionResponseModifyBuilder.() -> Unit
): EphemeralMessageInteractionResponse = interactionResponse.edit(builder)
@UnexpectedBehaviour
public override suspend fun respondOpposite(
builder: suspend FollowupMessageCreateBuilder.() -> Unit,
): PublicFollowupMessage = interactionResponse.createPublicFollowup { builder() }

/**
* Create a paginator that edits the original interaction. This is the only option for an ephemeral interaction, as
* it's impossible to edit an ephemeral follow-up.
*/
public inline fun EphemeralInteractionContext.editingPaginator(
defaultGroup: String = "",
locale: Locale? = null,
builder: (PaginatorBuilder).() -> Unit
): EphemeralResponsePaginator {
val pages = PaginatorBuilder(locale = locale, defaultGroup = defaultGroup)
public override suspend fun edit(
builder: suspend InteractionResponseModifyBuilder.() -> Unit,
): EphemeralMessageInteractionResponse = interactionResponse.edit { builder() }

builder(pages)
public override fun editingPaginator(
defaultGroup: String,
locale: Locale?,
builder: (PaginatorBuilder).() -> Unit,
): EphemeralResponsePaginator {
val pages = PaginatorBuilder(locale = locale, defaultGroup = defaultGroup)

return EphemeralResponsePaginator(pages, interactionResponse)
}
builder(pages)

return EphemeralResponsePaginator(pages, interactionResponse)
}

/** Create a paginator that creates a follow-up message, and edits that. **/
public inline fun EphemeralInteractionContext.publicRespondingPaginator(
defaultGroup: String = "",
locale: Locale? = null,
builder: (PaginatorBuilder).() -> Unit
): PublicFollowUpPaginator {
val pages = PaginatorBuilder(locale = locale, defaultGroup = defaultGroup)
@AlwaysPublicResponse
public override fun respondingPaginator(
defaultGroup: String,
locale: Locale?,
builder: (PaginatorBuilder).() -> Unit,
): PublicFollowUpPaginator {
val pages = PaginatorBuilder(locale = locale, defaultGroup = defaultGroup)

builder(pages)
builder(pages)

return PublicFollowUpPaginator(pages, interactionResponse)
return PublicFollowUpPaginator(pages, interactionResponse)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

@file:Suppress("UnnecessaryAbstractClass")

package com.kotlindiscord.kord.extensions.types

import com.kotlindiscord.kord.extensions.annotations.AlwaysPublicResponse
import com.kotlindiscord.kord.extensions.annotations.UnexpectedBehaviour
import com.kotlindiscord.kord.extensions.pagination.BaseButtonPaginator
import com.kotlindiscord.kord.extensions.pagination.builders.PaginatorBuilder
import dev.kord.core.entity.interaction.followup.FollowupMessage
import dev.kord.core.entity.interaction.response.MessageInteractionResponse
import dev.kord.rest.builder.message.create.FollowupMessageCreateBuilder
import dev.kord.rest.builder.message.modify.InteractionResponseModifyBuilder
import java.util.*

/**
* Interface representing an interaction context. Provides a generic base type for action contexts when working
* with interactions.
*
* More specific types representing each interaction type (ephemeral/public) extend this class.
*
* @param ResponseBehavior Generic representing the relevant interaction response behavior.
* @param FollowupType Generic representing the follow-up type for the current interaction type.
* @param OppositeFollowupType Generic representing the opposite follow-up type for the current interaction type.
*/
public interface InteractionContext<
ResponseBehavior,
ResponseType : MessageInteractionResponse,
FollowupType : FollowupMessage,
OppositeFollowupType : FollowupMessage,
> {
/** Current interaction response being worked with. **/
public val interactionResponse: ResponseBehavior

/** Create a paginator that edits the original interaction response. **/
public fun editingPaginator(
defaultGroup: String = "",
locale: Locale? = null,
builder: (PaginatorBuilder).() -> Unit,
): BaseButtonPaginator

/**
* Create a paginator that creates a follow-up message, and edits that.
*
* This function always creates a public follow-up, as Discord prevents bots from editing ephemeral follow-ups.
*/
@AlwaysPublicResponse
public fun respondingPaginator(
defaultGroup: String = "",
locale: Locale? = null,
builder: (PaginatorBuilder).() -> Unit,
): BaseButtonPaginator

/** Edit the original interaction response. **/
public suspend fun edit(
builder: suspend InteractionResponseModifyBuilder.() -> Unit,
): ResponseType

/** Create a follow-up response. **/
public suspend fun respond(
builder: suspend FollowupMessageCreateBuilder.() -> Unit,
): FollowupType

/**
* Create a follow-up response using the opposite interaction type.
*
* While Discord's API allows you to do this, it will rarely do what you'd expect.
* Only use this if you're sure it'll do what you want, and test thoroughly.
*/
@UnexpectedBehaviour
public suspend fun respondOpposite(
builder: suspend FollowupMessageCreateBuilder.() -> Unit,
): OppositeFollowupType
}
Loading

0 comments on commit a17ef13

Please sign in to comment.