diff --git a/kord-extensions/src/main/kotlin/com/kotlindiscord/kord/extensions/Exceptions.kt b/kord-extensions/src/main/kotlin/com/kotlindiscord/kord/extensions/Exceptions.kt index a806cf8d49..6b938cd120 100644 --- a/kord-extensions/src/main/kotlin/com/kotlindiscord/kord/extensions/Exceptions.kt +++ b/kord-extensions/src/main/kotlin/com/kotlindiscord/kord/extensions/Exceptions.kt @@ -13,6 +13,7 @@ import com.kotlindiscord.kord.extensions.commands.converters.builders.ConverterB import com.kotlindiscord.kord.extensions.events.EventHandler import com.kotlindiscord.kord.extensions.extensions.Extension import com.kotlindiscord.kord.extensions.parser.StringParser +import java.util.Locale import kotlin.reflect.KClass /** @@ -27,13 +28,13 @@ public open class ExtensionsException : Exception() * @property reason Reason for the validation failure **/ public class InvalidArgumentException( - public val builder: ConverterBuilder<*>, - public val reason: String + public val builder: ConverterBuilder<*>, + public val reason: String, ) : ExtensionsException() { - override val message: String = toString() + override val message: String = toString() - override fun toString(): String = - "Invalid argument: $builder ($reason)" + override fun toString(): String = + "Invalid argument: $builder ($reason)" } /** @@ -43,20 +44,20 @@ public class InvalidArgumentException( * @param reason Why this [Extension] is considered invalid. */ public class InvalidExtensionException( - public val clazz: KClass, - public val reason: String? + public val clazz: KClass, + public val reason: String?, ) : ExtensionsException() { - override val message: String = toString() + override val message: String = toString() - override fun toString(): String { - val formattedReason = if (reason != null) { - " ($reason)" - } else { - "" - } + override fun toString(): String { + val formattedReason = if (reason != null) { + " ($reason)" + } else { + "" + } - return "Invalid extension class: ${clazz.qualifiedName}$formattedReason" - } + return "Invalid extension class: ${clazz.qualifiedName}$formattedReason" + } } /** @@ -65,9 +66,9 @@ public class InvalidExtensionException( * @param reason Why this [EventHandler] is considered invalid. */ public class InvalidEventHandlerException(public val reason: String) : ExtensionsException() { - override val message: String = toString() + override val message: String = toString() - override fun toString(): String = "Invalid event handler: $reason" + override fun toString(): String = "Invalid event handler: $reason" } /** @@ -76,9 +77,9 @@ public class InvalidEventHandlerException(public val reason: String) : Extension * @param reason Why this [EventHandler] could not be registered. */ public class EventHandlerRegistrationException(public val reason: String) : ExtensionsException() { - override val message: String = toString() + override val message: String = toString() - override fun toString(): String = "Failed to register event handler: $reason" + override fun toString(): String = "Failed to register event handler: $reason" } /** @@ -88,15 +89,15 @@ public class EventHandlerRegistrationException(public val reason: String) : Exte * @param reason Why this [ChatCommand] is considered invalid. */ public class InvalidCommandException(public val name: String?, public val reason: String) : ExtensionsException() { - override val message: String = toString() + override val message: String = toString() - override fun toString(): String { - if (name == null) { - return "Invalid command: $reason" - } + override fun toString(): String { + if (name == null) { + return "Invalid command: $reason" + } - return "Invalid command $name: $reason" - } + return "Invalid command $name: $reason" + } } /** @@ -106,15 +107,15 @@ public class InvalidCommandException(public val name: String?, public val reason * @param reason Why this [ChatCommand] could not be registered. */ public class CommandRegistrationException(public val name: String?, public val reason: String) : ExtensionsException() { - override val message: String = toString() + override val message: String = toString() - override fun toString(): String { - if (name == null) { - return "Failed to register command: $reason" - } + override fun toString(): String { + if (name == null) { + return "Failed to register command: $reason" + } - return "Failed to register command $name: $reason" - } + return "Failed to register command $name: $reason" + } } /** @@ -126,14 +127,14 @@ public class CommandRegistrationException(public val name: String?, public val r * @param translationKey Translation key used to create the [reason] string, if any. */ public open class DiscordRelayedException( - public open val reason: String, - public open val translationKey: String? = null + public open val reason: String, + public open val translationKey: String? = null, ) : ExtensionsException() { - override val message: String by lazy { toString() } + override val message: String by lazy { toString() } - public constructor(other: DiscordRelayedException) : this(other.reason) + public constructor(other: DiscordRelayedException) : this(other.reason) - override fun toString(): String = reason + override fun toString(): String = reason } /** @@ -146,16 +147,23 @@ public open class DiscordRelayedException( * @param parser Tokenizing string parser used for this parse attempt, if this was a chat command. */ public open class ArgumentParsingException( - public override val reason: String, - public override val translationKey: String?, - public val argument: Argument<*>?, - public val arguments: Arguments, - public val parser: StringParser? + public override val reason: String, + public override val translationKey: String?, + public val locale: Locale, + public val bundle: String?, + public val argument: Argument<*>?, + public val arguments: Arguments, + public val parser: StringParser?, ) : DiscordRelayedException(reason, translationKey) { - override val message: String by lazy { toString() } + override val message: String by lazy { toString() } - public constructor(other: ArgumentParsingException) : - this(other.reason, other.translationKey, other.argument, other.arguments, other.parser) + public constructor(other: ArgumentParsingException) : + this( + other.reason, + other.translationKey, other.locale, other.bundle, + other.argument, other.arguments, + other.parser + ) - override fun toString(): String = reason + override fun toString(): String = reason } diff --git a/kord-extensions/src/main/kotlin/com/kotlindiscord/kord/extensions/commands/application/slash/SlashCommandParser.kt b/kord-extensions/src/main/kotlin/com/kotlindiscord/kord/extensions/commands/application/slash/SlashCommandParser.kt index c49e087730..ca05088ebf 100644 --- a/kord-extensions/src/main/kotlin/com/kotlindiscord/kord/extensions/commands/application/slash/SlashCommandParser.kt +++ b/kord-extensions/src/main/kotlin/com/kotlindiscord/kord/extensions/commands/application/slash/SlashCommandParser.kt @@ -100,6 +100,9 @@ public open class SlashCommandParser { "argumentParser.error.invalidValue", + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, null @@ -120,6 +123,9 @@ public open class SlashCommandParser { converter.handleError(e, context), null, + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, null @@ -157,6 +163,9 @@ public open class SlashCommandParser { "argumentParser.error.invalidValue", + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, null @@ -177,6 +186,9 @@ public open class SlashCommandParser { converter.handleError(e, context), null, + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, null @@ -211,6 +223,9 @@ public open class SlashCommandParser { converter.handleError(e, context), null, + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, null @@ -245,6 +260,9 @@ public open class SlashCommandParser { converter.handleError(e, context), null, + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, null @@ -279,6 +297,9 @@ public open class SlashCommandParser { converter.handleError(e, context), null, + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, null @@ -313,6 +334,9 @@ public open class SlashCommandParser { converter.handleError(e, context), null, + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, null diff --git a/kord-extensions/src/main/kotlin/com/kotlindiscord/kord/extensions/commands/chat/ChatCommandParser.kt b/kord-extensions/src/main/kotlin/com/kotlindiscord/kord/extensions/commands/chat/ChatCommandParser.kt index aa604ab15b..2061f9903d 100644 --- a/kord-extensions/src/main/kotlin/com/kotlindiscord/kord/extensions/commands/chat/ChatCommandParser.kt +++ b/kord-extensions/src/main/kotlin/com/kotlindiscord/kord/extensions/commands/chat/ChatCommandParser.kt @@ -135,6 +135,9 @@ public open class ChatCommandParser : KordExKoinComponent { "argumentParser.error.requiresOneValue", + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, parser @@ -163,6 +166,9 @@ public open class ChatCommandParser : KordExKoinComponent { "argumentParser.error.invalidValue", + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, parser @@ -194,6 +200,9 @@ public open class ChatCommandParser : KordExKoinComponent { "argumentParser.error.errorInArgument", + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, parser @@ -218,6 +227,9 @@ public open class ChatCommandParser : KordExKoinComponent { "argumentParser.error.requiresOneValue", + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, parser @@ -254,6 +266,9 @@ public open class ChatCommandParser : KordExKoinComponent { "argumentParser.error.errorInArgument", + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, parser @@ -274,6 +289,9 @@ public open class ChatCommandParser : KordExKoinComponent { "argumentParser.error.requiresOneValue", + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, parser @@ -310,6 +328,9 @@ public open class ChatCommandParser : KordExKoinComponent { "argumentParser.error.errorInArgument", + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, parser @@ -347,6 +368,9 @@ public open class ChatCommandParser : KordExKoinComponent { "argumentParser.error.invalidValue", + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, parser @@ -373,6 +397,9 @@ public open class ChatCommandParser : KordExKoinComponent { "argumentParser.error.notAllValid", + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, parser @@ -407,6 +434,9 @@ public open class ChatCommandParser : KordExKoinComponent { "argumentParser.error.errorInArgument", + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, parser @@ -444,6 +474,9 @@ public open class ChatCommandParser : KordExKoinComponent { "argumentParser.error.invalidValue", + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, parser @@ -470,6 +503,9 @@ public open class ChatCommandParser : KordExKoinComponent { "argumentParser.error.notAllValid", + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, parser @@ -506,6 +542,9 @@ public open class ChatCommandParser : KordExKoinComponent { "argumentParser.error.errorInArgument", + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, parser @@ -543,6 +582,9 @@ public open class ChatCommandParser : KordExKoinComponent { "argumentParser.error.invalidValue", + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, parser @@ -569,6 +611,9 @@ public open class ChatCommandParser : KordExKoinComponent { "argumentParser.error.notAllValid", + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, parser @@ -603,6 +648,9 @@ public open class ChatCommandParser : KordExKoinComponent { "argumentParser.error.errorInArgument", + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, parser @@ -640,6 +688,9 @@ public open class ChatCommandParser : KordExKoinComponent { "argumentParser.error.invalidValue", + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, parser @@ -666,6 +717,9 @@ public open class ChatCommandParser : KordExKoinComponent { "argumentParser.error.notAllValid", + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, parser @@ -700,6 +754,9 @@ public open class ChatCommandParser : KordExKoinComponent { "argumentParser.error.errorInArgument", + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, parser @@ -732,6 +789,9 @@ public open class ChatCommandParser : KordExKoinComponent { "argumentParser.error.errorInArgument", + context.getLocale(), + context.command.resolvedBundle ?: converter.bundle, + currentArg, argumentsObj, parser @@ -757,6 +817,9 @@ public open class ChatCommandParser : KordExKoinComponent { "argumentParser.error.noFilledArguments", + context.getLocale(), + context.command.resolvedBundle, + null, argumentsObj, parser @@ -774,6 +837,9 @@ public open class ChatCommandParser : KordExKoinComponent { "argumentParser.error.someFilledArguments", + context.getLocale(), + context.command.resolvedBundle, + null, argumentsObj, parser