Skip to content

Commit

Permalink
fix: Fix parameter annotations in discord commands
Browse files Browse the repository at this point in the history
  • Loading branch information
phinner committed Apr 22, 2024
1 parent bb3f073 commit 02712ad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
*/
package com.xpdustry.imperium.common.command.annotation

// TODO
// Using AnnotationTarget.TYPE CRASHES, AND IT HAS BEEN AN ISSUE FOR 3 YEARS!!
// Could be fixed with a custom proxy via java (https://stackoverflow.com/a/13324487)
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.VALUE_PARAMETER)
annotation class Range(val min: String = "", val max: String = "")
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class SlashCommandRegistry(
"$function has unsupported parameter type $classifier")
}

arguments += createCommandEdgeArgument(parameter.name!!, optional, classifier)
arguments += createCommandEdgeArgument(parameter, optional, classifier)
}

function.isAccessible = true
Expand All @@ -232,14 +232,14 @@ class SlashCommandRegistry(

@Suppress("UNCHECKED_CAST")
private fun <T : Any> createCommandEdgeArgument(
name: String,
parameter: KParameter,
optional: Boolean,
klass: KClass<T>
klass: KClass<T>,
): CommandEdge.Argument<T> {
val handler =
handlers[klass] as TypeHandler<T>?
?: throw IllegalArgumentException("Unsupported type $klass")
return CommandEdge.Argument(name, optional, klass, handler)
return CommandEdge.Argument(parameter.name!!, optional, parameter, handler)
}

private fun compile() {
Expand Down

0 comments on commit 02712ad

Please sign in to comment.