Skip to content

Commit 1e077d7

Browse files
committed
Fix an issue where subcommand aliases could trip up toDiscordCommands()
1 parent 5e7845e commit 1e077d7

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group 'me.devoxin'
8-
version '4.1.0'
8+
version '4.1.1'
99

1010
repositories {
1111
maven {

src/main/kotlin/me/devoxin/flight/api/CommandClient.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class CommandClient(
8383
?: commands.values.firstOrNull { it.properties.aliases.contains(command) }
8484
?: return dispatchSafely { it.onUnknownCommand(event, command, args) }
8585

86-
val subcommand = args.firstOrNull()?.lowercase().let { cmd.subcommands[it] }
86+
val subcommand = args.firstOrNull()?.lowercase().let { cmd.subcommands[it] ?: cmd.subcommandAliases[it] }
8787
val invoked = subcommand ?: cmd
8888

8989
if (subcommand != null) {
@@ -128,7 +128,7 @@ class CommandClient(
128128

129129
private fun onSlashCommand(event: SlashCommandInteractionEvent) {
130130
val cmd = commands[event.name] ?: return
131-
val subcommand = event.subcommandName?.let { cmd.subcommands[it] ?: return }
131+
val subcommand = event.subcommandName?.let { cmd.subcommands[it] ?: cmd.subcommandAliases[it] ?: return }
132132
val invoked = subcommand ?: cmd
133133
val ctx = SlashContext(this, event, invoked)
134134

src/main/kotlin/me/devoxin/flight/api/CommandFunction.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class CommandFunction(
3030
) : Executable(name, method, cog, arguments, contextParameter) {
3131
val contextType: ContextType
3232
val subcommands = hashMapOf<String, SubCommandFunction>()
33+
val subcommandAliases = hashMapOf<String, SubCommandFunction>()
3334

3435
init {
3536
val jvmCtx = contextParameter.type
@@ -41,14 +42,14 @@ class CommandFunction(
4142
}
4243

4344
for (sc in subCmds) {
44-
val triggers = listOf(sc.name, *sc.properties.aliases)
45+
subcommands[sc.name] = sc
4546

46-
for (trigger in triggers) {
47-
if (subcommands.containsKey(trigger)) {
47+
for (trigger in sc.properties.aliases) {
48+
if (subcommandAliases.containsKey(trigger)) {
4849
throw IllegalStateException("The sub-command trigger $trigger already exists!")
4950
}
5051

51-
subcommands[trigger] = sc
52+
subcommandAliases[trigger] = sc
5253
}
5354
}
5455
}

src/main/kotlin/me/devoxin/flight/api/entities/CommandRegistry.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class CommandRegistry : HashMap<String, CommandFunction>() {
8282
}
8383

8484
fun findCommandByAlias(alias: String): CommandFunction? {
85-
return this.values.firstOrNull { it.properties.aliases.contains(alias) }
85+
return this.values.firstOrNull { alias in it.properties.aliases }
8686
}
8787

8888
fun findCogByName(name: String): Cog? {

0 commit comments

Comments
 (0)