Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make SlashCommand#getHelp() return translated text when available. #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.jagrosh.jdautilities.command;

import com.jagrosh.jdautilities.commons.utils.TranslateUtil;
import net.dv8tion.jda.annotations.ForRemoval;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.GuildVoiceState;
Expand Down Expand Up @@ -177,6 +178,24 @@ public void onAutoComplete(CommandAutoCompleteInteractionEvent event) {}
*/
@Override
protected void execute(CommandEvent event) {}

/**
* Returns the description of this SlashCommand instance.<br>
* Should there be {@link #getDescriptionLocalization() translations for this text} will the client try to
* obtain a translation for the Description using {@link TranslateUtil#getDefaultLocale() the default locale} and
* in case of a null or empty String return the default help text set.
*
* @return Translated Help text for default locale, or help text set in constructor.
*/
@Override
public String getHelp(){
String helpMessage = null;
if (!getDescriptionLocalization().isEmpty()) {
helpMessage = getDescriptionLocalization().get(TranslateUtil.getDefaultLocale());
}

return (helpMessage == null || helpMessage.isEmpty()) ? this.help : helpMessage;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should always return this.help if it is specified, and only do this logic if it's not

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for a late reply... Honestly forgot this.

The main issue is, that help is always there. By default is it no help available, so if we should have this logic will this require modifications to the default help message (i.e. make it null and have getHelp() return the default text in case of null), which I feel like a breaking change here.

Maybe another aproach could be a dedicated option and getter for the command description for slash commands that defaults to returning getHelp() if nothing is set?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any input on this?

}

/**
* Runs checks for the {@link SlashCommand SlashCommand} with the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static String t(Guild server, String key) {

/**
* Converts the following key to the provided locale. Will default to {@code DEFAULT} if no locale.<br>
* Recommended use: {@code t("MY_KEY", event.getUserLocale())} on interactions.
* Recommended use: {@code t(event.getUserLocale(), "MY_KEY")} on interactions.
*
* @param locale The locale to convert to
* @param key The key to convert
Expand Down Expand Up @@ -97,4 +97,14 @@ public static Map<DiscordLocale, String> buildLocaleMap(String key) {

return locales;
}

/**
* Returns the Default locale set to use by this TranslateUtil. By default is the default locale {@link DiscordLocale#ENGLISH_US}
* but may be changed using {@link #setDefaultLocale(DiscordLocale)}
*
* @return The Default DiscordLocale used by this TranslateUtil.
*/
public static DiscordLocale getDefaultLocale() {
return DEFAULT;
}
}
Loading