-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/root' into root
- Loading branch information
Showing
29 changed files
with
195 additions
and
109 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...ons/src/main/kotlin/com/kotlindiscord/kord/extensions/annotations/AlwaysPublicResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
16 changes: 16 additions & 0 deletions
16
...ions/src/main/kotlin/com/kotlindiscord/kord/extensions/annotations/UnexpectedBehaviour.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...-extensions/src/main/kotlin/com/kotlindiscord/kord/extensions/types/InteractionContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.