public class CommandSettings extends Object
When you want your commands to become active, use activate()
| Modifier and Type | Field | Description |
|---|---|---|
protected static org.slf4j.Logger |
LOGGER |
The logger of this framework.
|
static String |
VALID_LABEL |
A regex that only matches valid labels.
|
static String |
VALID_PREFIX |
A regex that only matches valid prefixes.
|
| Constructor | Description |
|---|---|
CommandSettings(String defaultPrefix,
net.dv8tion.jda.bot.sharding.ShardManager shardManager,
boolean labelIgnoreCase) |
This is the optional constructor in case you are sharding your bot.
|
CommandSettings(String defaultPrefix,
net.dv8tion.jda.core.JDA jda,
boolean labelIgnoreCase) |
This is the constructor.
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
activate() |
Sets the prefix and the command HashMap for the rest of the API.
|
CommandSettings |
addChannelsToBlacklist(long... channelIds) |
Adds multiple channels to the blacklist.
|
CommandSettings |
addChannelsToBlacklist(Collection<Long> channelIds) |
Adds multiple channels to the blacklist.
|
CommandSettings |
addChannelToBlacklist(long channelId) |
Adds a given channel to the blacklist (meaning commands can not be executed in there).
|
CommandSettings |
addHelpLabel(String label) |
Deprecated.
This method is deprecated and thus not supported anymore.
|
CommandSettings |
addHelpLabels(String... labels) |
Deprecated.
This method is deprecated and thus not supported anymore.
|
CommandSettings |
addHelpLabels(Collection<String> labels) |
Deprecated.
This method is deprecated and thus not supported anymore.
|
boolean |
botsMayExecute() |
Returns whether bot execution is enabled.
|
CommandSettings |
clear() |
Resets this whole instance by clearing the commands and setting everything to how it was at the beginning.
|
CommandSettings |
clearBlacklist() |
Clears the blacklist so that no channel is blacklisted anymore.
|
CommandSettings |
clearCommands() |
Clears all commands.
|
CommandSettings |
clearCustomPrefixes() |
Removes all entries from the prefix map, resetting every custom prefix.
|
CommandSettings |
clearHelpLabels() |
Deprecated.
This method is deprecated and thus not supported anymore.
|
void |
deactivate() |
Deactivates the current CommandSettings by removing the command listener from jda.
|
Set<Long> |
getBlacklistedChannels() |
Use this to get the blacklisted channels.
|
protected Map<String,ICommand> |
getCommands() |
|
long |
getCooldown() |
Returns the currently set cooldown for this instance.
|
Color |
getHelpColor() |
Returns the help color for DefaultHelpCommand.
|
Set<String> |
getHelpLabelSet() |
Deprecated.
This method is deprecated and not supported in this version anymore.
|
Set<String> |
getLabels(ICommand command) |
Returns every registered label for an ICommand instance in an immutable Set.
|
Set<String> |
getLabelSet() |
Returns every registered label in a Set.
|
String |
getPrefix() |
Use this method to get the default prefix.
|
String |
getPrefix(long guildId) |
Use this method to get the prefix for a specific guild.
|
protected net.dv8tion.jda.core.entities.Message |
getUnknownCommandMessage() |
|
boolean |
isActivated() |
Returns whether this instance is activated or not.
|
boolean |
isBlacklisted(long channelId) |
Returns whether the given channel id is blacklisted.
|
boolean |
isLabelIgnoreCase() |
Returns whether command labels are case insensitive on this instance of CommandSettings.
|
boolean |
isResetCooldown() |
Returns whether the cooldown will be reset for each execution attempt.
|
CommandSettings |
put(ICommand executor,
String label) |
Use this method to add commands from your project.
|
CommandSettings |
put(ICommand executor,
String... labels) |
Use this method to add commands with aliases.
|
CommandSettings |
put(ICommand executor,
Collection<String> labels) |
Use this method to add commands with aliases from a Set.
|
boolean |
remove(String label) |
Use this method to remove existing commands.
|
boolean |
remove(String... labels) |
Use this method to remove more than one command at a time.
|
boolean |
remove(Collection<String> labels) |
Removes every label that is in the given Collection.
|
boolean |
removeChannelFromBlacklist(long channelId) |
Removes one channel from the blacklist.
|
boolean |
removeChannelsFromBlacklist(long... channelIds) |
Removes one or more channels from the blacklist.
|
boolean |
removeChannelsFromBlackList(Collection<Long> channelIds) |
Removes a given Collection of channel ids from the blacklist.
|
boolean |
removeHelpLabel(String label) |
Deprecated.
This method is deprecated and thus not supported anymore.
|
boolean |
removeHelpLabels(String... labels) |
Deprecated.
This method is deprecated and thus not supported anymore.
|
boolean |
removeHelpLabels(Collection<String> labels) |
Deprecated.
This method is deprecated and thus not supported anymore.
|
CommandSettings |
setBotExecution(boolean botExecution) |
Setter for the field botExecution.
|
CommandSettings |
setCooldown(long msCooldown) |
Sets the cooldown for this instance of settings.
|
CommandSettings |
setCustomPrefix(long guildId,
String prefix) |
Use this method to add a custom command prefix to a guild.
|
CommandSettings |
setCustomPrefixes(Map<Long,String> guildIdPrefixMap) |
You may use this method as another way to add custom prefixes.
|
CommandSettings |
setDefaultPrefix(String prefix) |
Use this method to set the default prefix.
|
CommandSettings |
setHelpCommandColor(Color color) |
Sets the color the help message embed will have if you use DefaultHelpCommand.
|
CommandSettings |
setResetCooldown(boolean resetCooldown) |
Sets the parameter resetCooldown.
|
CommandSettings |
setUnknownCommandMessage(net.dv8tion.jda.core.entities.Message message) |
Sets a Message that will be sent in the event of a Member using the prefix without executing any valid command.
|
String |
toString() |
Transforms this instance to a String, showing the current set options.
|
public static final String VALID_PREFIX
public static final String VALID_LABEL
protected static final org.slf4j.Logger LOGGER
public CommandSettings(@Nonnull String defaultPrefix, @Nonnull net.dv8tion.jda.bot.sharding.ShardManager shardManager, boolean labelIgnoreCase)
shardManager - Put your active ShardManager here. This is important for the activation of the CommandListener.defaultPrefix - The String you will have to put before every command in order to get your command execution registered. This can later be changed.labelIgnoreCase - Set this to true, if you want deactivate case sensitivity for the recognition of labels. E.g.: there will be no difference between the labels "foo",
"FOO", "FoO" and so on.public CommandSettings(@Nonnull String defaultPrefix, @Nonnull net.dv8tion.jda.core.JDA jda, boolean labelIgnoreCase)
jda - Put your active JDA here. This is important for the activation of the CommandListener.defaultPrefix - The String you will have to put before every command in order to get your command execution registered. This can later be changed.labelIgnoreCase - Set this to true, if you want deactivate case sensitivity for the recognition of labels. E.g.: there will be no difference between the labels "foo",
"FOO", "FoO" and so on.@Deprecated public CommandSettings addHelpLabel(String label)
label - The label to add.CommandSetException - if the given label is invalid (contains spaces)DefaultHelpCommand@Deprecated public CommandSettings addHelpLabels(@Nonnull String... labels)
labels - One or more labels which may later be called by members to list all commands or to show info about one specific command.DefaultHelpCommand@Deprecated public CommandSettings addHelpLabels(@Nonnull Collection<String> labels)
labels - A Set which contains the labels you want to add.CommandSetException - if one of the labels is not a valid label.DefaultHelpCommand@Deprecated public boolean removeHelpLabel(String label)
label - The label to remove.@Deprecated public boolean removeHelpLabels(@Nonnull String... labels)
labels - The help labels to remove.@Deprecated public boolean removeHelpLabels(@Nonnull Collection<String> labels)
labels - The Set of labels that are to be removed.@Deprecated public CommandSettings clearHelpLabels()
public CommandSettings addChannelToBlacklist(long channelId)
channelId - the id of the channel to be blacklisted.public CommandSettings addChannelsToBlacklist(long... channelIds)
channelIds - multiple ids or an array of ids to be added.public CommandSettings addChannelsToBlacklist(Collection<Long> channelIds)
channelIds - A Collection of channel ids to be added.public boolean removeChannelFromBlacklist(long channelId)
channelId - the id of the channel to remove.public boolean removeChannelsFromBlacklist(long... channelIds)
channelIds - The ids of the channels to remove.public boolean removeChannelsFromBlackList(Collection<Long> channelIds)
channelIds - the Collection to remove.public CommandSettings clearBlacklist()
public CommandSettings put(@Nonnull ICommand executor, String label)
The two parameters will be put in a HashMap which is used by the API to notice commands.
label - The label which describes your command, i.e. the string after the prefix [prefix][label].executor - An instance of your command class which implements ICommand.CommandSetException - If the label is empty or consists of multiple words.public CommandSettings put(@Nonnull ICommand executor, @Nonnull String... labels)
Works like put(ICommand, String) but adds multiple labels to the same command.
executor - An instance of your command class which implements ICommand.labels - One or more labels. This will throw a CommandSetException, if the label is empty or contains spaces.CommandSetException - If one label is empty or consists of multiple wordspublic CommandSettings put(@Nonnull ICommand executor, @Nonnull Collection<String> labels)
executor - An instance of your command class which implements ICommand.labels - One or more labels. This will throw a CommandSetException, if the label is empty or contains spaces.CommandSetException - if one label is empty or contains spaces.public boolean remove(String label)
label - The label of the command to remove.public boolean remove(@Nonnull String... labels)
labels - One or more labels to removepublic boolean remove(@Nonnull Collection<String> labels)
labels - The labels to remove.public CommandSettings clearCommands()
public CommandSettings clear()
public CommandSettings setDefaultPrefix(@Nonnull String prefix)
prefix - The prefix to set. In case the given String is empty, this will throw a CommandSetException.CommandSetException - if a non-null prefix does not match the requirements for a valid prefix.public CommandSettings setUnknownCommandMessage(@Nullable net.dv8tion.jda.core.entities.Message message)
message - Nullable Message object that will be wrapped in a new MessageBuilder to prevent the usage of already sent Messages. If this is null, the message is deactivated.MessageBuilderpublic CommandSettings setCustomPrefix(long guildId, @Nullable String prefix)
guildId - The guild id as a long.prefix - The nullable prefix to be set.CommandSetException - if a non-null prefix does not match the requirements for a valid prefix.public CommandSettings setCustomPrefixes(@Nonnull Map<Long,String> guildIdPrefixMap)
guildIdPrefixMap - A Map which contains the prefix for each guild to add. Key: guild ID (Long), Value: prefix (String)CommandSetException - if one of the prefixes is not valid.public CommandSettings clearCustomPrefixes()
public CommandSettings setCooldown(long msCooldown)
msCooldown - the cooldown in milliseconds.public CommandSettings setResetCooldown(boolean resetCooldown)
resetCooldown - True: The command cooldown is reset on each attempt to execute a command. E.g.:
A User executes an command and gets a 10 second cooldown. If he tries to execute another command within these 10 seconds,
the command isn't executed and the cooldown is at 10 seconds again.False: Once the cooldown is activated, it will not be reset by further attempts to execute commands.
public CommandSettings setBotExecution(boolean botExecution)
botExecution - true, if you want to allow bots to execute commands. false, if not.public CommandSettings setHelpCommandColor(@Nullable Color color)
color - The color to set. To set this to self member color, set it to null.DefaultHelpCommandpublic void activate()
Note that activating multiple CommandSettings may cause problems. You can do this to use multiple prefixes, but it is not recommended.
This method is important to call because otherwise no command will be registered by the internal command listener.
CommandSetException - if you already activated this instance.public void deactivate()
CommandSetException - if you either did not activate this instance or already deactivated it.public String getPrefix(long guildId)
guildId - The id of the guild to check.public String getPrefix()
public Set<Long> getBlacklistedChannels()
public boolean isBlacklisted(long channelId)
channelId - The id of the channel to check for.public Set<String> getLabelSet()
public Set<String> getLabels(ICommand command)
command - The ICommand instance to get the labels from@Deprecated public Set<String> getHelpLabelSet()
public boolean isActivated()
public Color getHelpColor()
public long getCooldown()
public boolean isLabelIgnoreCase()
public boolean isResetCooldown()
public boolean botsMayExecute()
public String toString()
protected net.dv8tion.jda.core.entities.Message getUnknownCommandMessage()
Copyright © 2018. All rights reserved.