Skip to content

Commit

Permalink
Change the default locale back to English, but use the portuguese lab…
Browse files Browse the repository at this point in the history
…el when searching for command mentions
  • Loading branch information
MrPowerGamerBR committed Feb 11, 2025
1 parent 0164a11 commit bb1fcad
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.perfectdreams.loritta.cinnamon.discord.interactions.vanilla

import net.dv8tion.jda.api.interactions.DiscordLocale
import net.perfectdreams.loritta.morenitta.interactions.commands.DiscordCommand

/**
Expand Down Expand Up @@ -49,7 +50,13 @@ class CommandMentions(private val registeredCommands: List<DiscordCommand>) {
private fun commandMention(path: String): String {
val rootCommandLabel = path.substringBefore(" ")

val registeredCommand = registeredCommands.firstOrNull { it.name == rootCommandLabel } ?: error("Couldn't find a command with label $rootCommandLabel!")
// This seems weird, but hear me out:
// In the past we did use the command label here, which is english
// However, this is bad because all of the strings are first created in portuguese, then translated to english
// So a command that was not translated yet to english WILL cause issues after it is translated
// (ESPECIALLY if it is being used as a command mention!)
// So now we use the localized portuguese label :3
val registeredCommand = registeredCommands.firstOrNull { it.nameLocalizations[DiscordLocale.PORTUGUESE_BRAZILIAN] == rootCommandLabel } ?: error("Couldn't find a command with label $rootCommandLabel!")

return "</${path}:${registeredCommand.id}>"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package net.perfectdreams.loritta.morenitta.interactions.commands

import kotlinx.serialization.Serializable
import net.dv8tion.jda.api.interactions.DiscordLocale
import net.dv8tion.jda.api.interactions.commands.Command

@Serializable
data class DiscordCommand(
val id: Long,
val name: String
val name: String,
val nameLocalizations: Map<DiscordLocale, String>
) {
companion object {
fun from(command: Command) = DiscordCommand(
command.idLong,
command.name
command.name,
command.nameLocalizations.toMap()
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,9 @@ class UnleashedCommandManager(val loritta: LorittaBot, val languageManager: Lang
val messageCommands = mutableListOf<MessageCommandDeclaration>()
val applicationCommands: List<ExecutableApplicationCommandDeclaration>
get() = slashCommands + userCommands + messageCommands
// In the past we did use English as the default i18nContext
// However, this is bad because all of the strings are first created in portuguese, then translated to english
// So a command that was not translated yet to english WILL cause issues after it is translated
// (ESPECIALLY if it is being used as a command mention!)
// So now we use the default i18nContext :3
val slashCommandDefaultI18nContext = languageManager.defaultI18nContext
// Use English as the default name and description localizations
// This is useful because Discord autocompletes the default string + the current Discord locale localization string
val slashCommandDefaultI18nContext = languageManager.getI18nContextById("en")

private var commandPathToDeclarations = mutableMapOf<String, SlashCommandDeclaration>()

Expand Down

0 comments on commit bb1fcad

Please sign in to comment.