Skip to content

Commit

Permalink
Open Arguments functions - #123
Browse files Browse the repository at this point in the history
  • Loading branch information
gdude2002 committed May 22, 2024
1 parent fca5007 commit 5e3424c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,24 +154,26 @@ public class ConverterProcessor(
val outputText = buildString {
append(
"""
@file:OptIn(
KordPreview::class,
ConverterToDefaulting::class,
ConverterToMulti::class,
ConverterToOptional::class
)
package ${classDeclaration.packageName.asString()}
// Original converter class, for safety
import ${classDeclaration.qualifiedName!!.asString()}
// Imports that all converters need
import com.kotlindiscord.kord.extensions.InvalidArgumentException
import com.kotlindiscord.kord.extensions.commands.Arguments
import com.kotlindiscord.kord.extensions.commands.converters.*
import com.kotlindiscord.kord.extensions.commands.converters.builders.*
import dev.kord.common.annotation.KordPreview
@file:OptIn(
KordPreview::class,
ConverterToDefaulting::class,
ConverterToMulti::class,
ConverterToOptional::class,
UnexpectedFunctionBehaviour::class,
)
package ${classDeclaration.packageName.asString()}
// Original converter class, for safety
import ${classDeclaration.qualifiedName!!.asString()}
// Imports that all converters need
import com.kotlindiscord.kord.extensions.InvalidArgumentException
import com.kotlindiscord.kord.extensions.annotations.UnexpectedFunctionBehaviour
import com.kotlindiscord.kord.extensions.commands.Arguments
import com.kotlindiscord.kord.extensions.commands.converters.*
import com.kotlindiscord.kord.extensions.commands.converters.builders.*
import dev.kord.common.annotation.KordPreview
""".trimIndent()
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ 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.",
message = "Calling or overriding 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
public annotation class UnexpectedFunctionBehaviour
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package com.kotlindiscord.kord.extensions.commands

import com.kotlindiscord.kord.extensions.annotations.UnexpectedFunctionBehaviour
import com.kotlindiscord.kord.extensions.commands.converters.*

/**
Expand Down Expand Up @@ -42,6 +43,7 @@ public open class Arguments {
*
* @return Argument converter to use as a delegate.
*/
@UnexpectedFunctionBehaviour
public fun <R : Any> arg(
displayName: String,
description: String,
Expand All @@ -63,6 +65,7 @@ public open class Arguments {
*
* @return Argument converter to use as a delegate.
*/
@UnexpectedFunctionBehaviour
public fun <R : Any> arg(
displayName: String,
description: String,
Expand All @@ -84,6 +87,7 @@ public open class Arguments {
*
* @return Argument converter to use as a delegate.
*/
@UnexpectedFunctionBehaviour
public fun <R : Any> arg(
displayName: String,
description: String,
Expand All @@ -105,6 +109,7 @@ public open class Arguments {
*
* @return Argument converter to use as a delegate.
*/
@UnexpectedFunctionBehaviour
public fun <R : Any> arg(
displayName: String,
description: String,
Expand All @@ -126,6 +131,7 @@ public open class Arguments {
*
* @return Argument converter to use as a delegate.
*/
@UnexpectedFunctionBehaviour
public fun <R : Any> arg(
displayName: String,
description: String,
Expand All @@ -147,6 +153,7 @@ public open class Arguments {
*
* @return Argument converter to use as a delegate.
*/
@UnexpectedFunctionBehaviour
public fun <R : Any> arg(
displayName: String,
description: String,
Expand All @@ -168,6 +175,7 @@ public open class Arguments {
*
* @return Argument converter to use as a delegate.
*/
@UnexpectedFunctionBehaviour
public fun <R : Any> arg(
displayName: String,
description: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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.annotations.UnexpectedFunctionBehaviour
import com.kotlindiscord.kord.extensions.pagination.EphemeralResponsePaginator
import com.kotlindiscord.kord.extensions.pagination.PublicFollowUpPaginator
import com.kotlindiscord.kord.extensions.pagination.builders.PaginatorBuilder
Expand Down Expand Up @@ -38,7 +38,7 @@ public interface EphemeralInteractionContext : InteractionContext<
builder: suspend FollowupMessageCreateBuilder.() -> Unit,
): EphemeralFollowupMessage = interactionResponse.createEphemeralFollowup { builder() }

@UnexpectedBehaviour
@UnexpectedFunctionBehaviour
public override suspend fun respondOpposite(
builder: suspend FollowupMessageCreateBuilder.() -> Unit,
): PublicFollowupMessage = interactionResponse.createPublicFollowup { builder() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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.annotations.UnexpectedFunctionBehaviour
import com.kotlindiscord.kord.extensions.pagination.BaseButtonPaginator
import com.kotlindiscord.kord.extensions.pagination.builders.PaginatorBuilder
import dev.kord.core.behavior.interaction.response.InteractionResponseBehavior
Expand Down Expand Up @@ -79,7 +79,7 @@ public interface InteractionContext<
* 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
@UnexpectedFunctionBehaviour
public suspend fun respondOpposite(
builder: suspend FollowupMessageCreateBuilder.() -> Unit,
): OppositeFollowupType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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.annotations.UnexpectedFunctionBehaviour
import com.kotlindiscord.kord.extensions.pagination.PublicFollowUpPaginator
import com.kotlindiscord.kord.extensions.pagination.PublicResponsePaginator
import com.kotlindiscord.kord.extensions.pagination.builders.PaginatorBuilder
Expand Down Expand Up @@ -37,7 +37,7 @@ public interface PublicInteractionContext : InteractionContext<
builder: suspend FollowupMessageCreateBuilder.() -> Unit,
): PublicFollowupMessage = interactionResponse.createPublicFollowup { builder() }

@UnexpectedBehaviour
@UnexpectedFunctionBehaviour
public override suspend fun respondOpposite(
builder: suspend FollowupMessageCreateBuilder.() -> Unit,
): EphemeralFollowupMessage = interactionResponse.createEphemeralFollowup { builder() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
*/

@file:OptIn(
ConverterToOptional::class
ConverterToOptional::class,
UnexpectedFunctionBehaviour::class
)
@file:Suppress("StringLiteralDuplication")

package com.kotlindiscord.kord.extensions.modules.unsafe.converters

import com.kotlindiscord.kord.extensions.DiscordRelayedException
import com.kotlindiscord.kord.extensions.annotations.UnexpectedFunctionBehaviour
import com.kotlindiscord.kord.extensions.commands.Argument
import com.kotlindiscord.kord.extensions.commands.Arguments
import com.kotlindiscord.kord.extensions.commands.CommandContext
Expand Down

0 comments on commit 5e3424c

Please sign in to comment.