public class CommandEngine extends net.dv8tion.jda.api.hooks.ListenerAdapter implements ICommandEngine
Modifier | Constructor and Description |
---|---|
protected |
CommandEngine()
Creates an Instance of this
ICommandEngine implementations. |
Modifier and Type | Method and Description |
---|---|
ICommandEngine |
addAlias(@NotNull String name,
ICommand command)
Add an alternative name to a command.
|
ICommandEngine |
addCommand(@NotNull ICommand command)
Registers an ICommand into the engine.
|
static void |
addCommandPackage(String path)
Set the package name where the classes that extends ICommand are located in your project.
|
static @NotNull net.dv8tion.jda.api.JDA |
create(@NotNull net.dv8tion.jda.api.JDABuilder builder)
This will build the JDA object.
|
static @NotNull net.dv8tion.jda.api.JDA |
create(String token,
Collection<net.dv8tion.jda.api.requests.GatewayIntent> intents)
Creates a JDA with the predefined token.
|
static @NotNull net.dv8tion.jda.api.JDA |
create(String token,
net.dv8tion.jda.api.requests.GatewayIntent intent,
net.dv8tion.jda.api.requests.GatewayIntent... intents)
Creates a JDA with the predefined token.
|
static @NotNull net.dv8tion.jda.api.JDA |
createDefault(String token)
Creates a JDABuilder with recommended default settings.
|
static @NotNull net.dv8tion.jda.api.JDA |
createDefault(String token,
Collection<net.dv8tion.jda.api.requests.GatewayIntent> intents)
Creates a JDABuilder with recommended default settings.
|
static @NotNull net.dv8tion.jda.api.JDA |
createDefault(String token,
net.dv8tion.jda.api.requests.GatewayIntent intent,
net.dv8tion.jda.api.requests.GatewayIntent... intents)
Creates a JDABuilder with recommended default settings.
|
static @NotNull net.dv8tion.jda.api.JDA |
createLight(String token)
Creates a JDA with low memory profile settings and with ICommandEngine preset.
|
static @NotNull net.dv8tion.jda.api.JDA |
createLight(String token,
Collection<net.dv8tion.jda.api.requests.GatewayIntent> intents)
Creates a JDA with low memory profile settings and with ICommandEngine preset.
|
static @NotNull net.dv8tion.jda.api.JDA |
createLight(String token,
net.dv8tion.jda.api.requests.GatewayIntent intent,
net.dv8tion.jda.api.requests.GatewayIntent... intents)
Creates a JDA with low memory profile settings and with ICommandEngine preset.
|
@Nullable ICommand |
getCommand(@NotNull String name)
Get an ICommand from the registered commands in the Engine.
|
@NotNull @UnmodifiableView List<ICommand> |
getCommands()
Get a list of
ICommand registered in the Engine. |
@NotNull List<ICommand> |
getCommandsByExactMatch(String name)
Get a list of ICommand from the registered commands in the Engine.
|
@NotNull List<ICommand> |
getCommandsByPartialMatch(String name)
Get a list of ICommand from the registered commands in the Engine.
|
ICommand |
getHelpCommand()
Return the ICommand object of the help command.
|
static ICommandEngine |
getInstance()
Get the actual instance of
ICommandEngine that is being used. |
net.dv8tion.jda.api.JDA |
getJda()
Get the JDA object set within this Engine.
|
Locale |
getLanguage()
Gets the default language to be used by the bot.
|
Locale |
getLanguage(@Nullable net.dv8tion.jda.api.events.Event event)
By default, gets the default language to be used by the bot.
|
String |
getPrefix()
Gets the prefix configured on the bot.
|
String |
getPrefix(@NotNull net.dv8tion.jda.api.events.Event event)
By default, it gets the prefix configured on the bot.
|
String |
getPrefix(@NotNull net.dv8tion.jda.api.events.message.MessageReceivedEvent event)
By default, it gets the prefix configured on the bot.
|
String |
getPrefix(@NotNull net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event)
By default, it gets the prefix configured on the bot.
|
IRepository |
getRepository()
Return the repository Controller.
|
@NotNull String |
getString(@NotNull String key)
Gets a text string in the configured language of the bot.
|
@NotNull String |
getString(@NotNull String key,
@NotNull Locale locale)
Gets a text string in a specific language.
|
@NotNull String[] |
getStringArray(@NotNull String key)
Gets a string Array in the configured language of the bot.
|
@NotNull String[] |
getStringArray(@NotNull String key,
@NotNull Locale locale)
Gets a string Array in a specific language.
|
static void |
includeBuildInUtils()
Include pre-created commands, such has Help, Ping, Language and prefix.
|
boolean |
isReactToMention()
Get whether the bot should react to mention or not.
|
boolean |
isReactToMention(net.dv8tion.jda.api.events.Event event)
Checks if bot should react to mention calls (Messages that starts with @BOT_NAME).
|
void |
loadCommands()
Registers ICommands from packages set into the engine.
|
void |
logDebug(String message)
Log a message at the DEBUG level.
|
void |
logError(String message)
Log a message at the ERROR level.
|
void |
logInfo(String message)
Log a message at the INFO level.
|
void |
logWarn(String message)
Log a message at the WARN level.
|
void |
onMessageReceived(@NotNull net.dv8tion.jda.api.events.message.MessageReceivedEvent event) |
void |
onSlashCommandInteraction(@NotNull net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event) |
ICommandEngine |
setHelp(String help)
Set which command is related to user help.
|
static void |
setInstance(ICommandEngine newCommandConfig)
Set a custom implementation of
ICommandEngine . |
ICommandEngine |
setJda(net.dv8tion.jda.api.JDA jda)
Set the JDA instance of the bot.
|
ICommandEngine |
setLanguage(@NotNull Locale language)
Sets the default language to be used by the bot.
|
ICommandEngine |
setPrefix(@NotNull net.dv8tion.jda.api.entities.Guild guild,
@NotNull String prefix)
Sets a prefix for a specific guild.
|
ICommandEngine |
setPrefix(@NotNull String prefix)
Sets the default prefix for the bot.
|
ICommandEngine |
setReactToMention(boolean reactToMention)
Sets if the bot should react to a message starting by mentioning the bot @bot_name
if sets to false, the bot will only react to prefix.
|
static void |
setRepository(IRepository repository) |
onApplicationCommandUpdatePrivileges, onApplicationUpdatePrivileges, onButtonInteraction, onChannelCreate, onChannelDelete, onChannelUpdateArchived, onChannelUpdateArchiveTimestamp, onChannelUpdateAutoArchiveDuration, onChannelUpdateBitrate, onChannelUpdateInvitable, onChannelUpdateLocked, onChannelUpdateName, onChannelUpdateNSFW, onChannelUpdateParent, onChannelUpdatePosition, onChannelUpdateRegion, onChannelUpdateSlowmode, onChannelUpdateTopic, onChannelUpdateType, onChannelUpdateUserLimit, onCommandAutoCompleteInteraction, onDisconnect, onEmojiAdded, onEmojiRemoved, onEmojiUpdateName, onEmojiUpdateRoles, onEvent, onException, onGatewayPing, onGenericAutoCompleteInteraction, onGenericChannel, onGenericChannelUpdate, onGenericCommandInteraction, onGenericComponentInteractionCreate, onGenericContextInteraction, onGenericEmoji, onGenericEmojiUpdate, onGenericEvent, onGenericGuild, onGenericGuildInvite, onGenericGuildMember, onGenericGuildMemberUpdate, onGenericGuildSticker, onGenericGuildStickerUpdate, onGenericGuildUpdate, onGenericGuildVoice, onGenericInteractionCreate, onGenericMessage, onGenericMessageReaction, onGenericPermissionOverride, onGenericPrivilegeUpdate, onGenericRole, onGenericRoleUpdate, onGenericSelfUpdate, onGenericStageInstance, onGenericStageInstanceUpdate, onGenericThread, onGenericThreadMember, onGenericUpdate, onGenericUser, onGenericUserPresence, onGuildAvailable, onGuildBan, onGuildInviteCreate, onGuildInviteDelete, onGuildJoin, onGuildLeave, onGuildMemberJoin, onGuildMemberRemove, onGuildMemberRoleAdd, onGuildMemberRoleRemove, onGuildMemberUpdate, onGuildMemberUpdateAvatar, onGuildMemberUpdateBoostTime, onGuildMemberUpdateNickname, onGuildMemberUpdatePending, onGuildMemberUpdateTimeOut, onGuildReady, onGuildStickerAdded, onGuildStickerRemoved, onGuildStickerUpdateAvailable, onGuildStickerUpdateDescription, onGuildStickerUpdateName, onGuildStickerUpdateTags, onGuildTimeout, onGuildUnavailable, onGuildUnban, onGuildUpdateAfkChannel, onGuildUpdateAfkTimeout, onGuildUpdateBanner, onGuildUpdateBoostCount, onGuildUpdateBoostTier, onGuildUpdateCommunityUpdatesChannel, onGuildUpdateDescription, onGuildUpdateExplicitContentLevel, onGuildUpdateFeatures, onGuildUpdateIcon, onGuildUpdateLocale, onGuildUpdateMaxMembers, onGuildUpdateMaxPresences, onGuildUpdateMFALevel, onGuildUpdateName, onGuildUpdateNotificationLevel, onGuildUpdateNSFWLevel, onGuildUpdateOwner, onGuildUpdateRulesChannel, onGuildUpdateSplash, onGuildUpdateSystemChannel, onGuildUpdateVanityCode, onGuildUpdateVerificationLevel, onGuildVoiceDeafen, onGuildVoiceGuildDeafen, onGuildVoiceGuildMute, onGuildVoiceJoin, onGuildVoiceLeave, onGuildVoiceMove, onGuildVoiceMute, onGuildVoiceRequestToSpeak, onGuildVoiceSelfDeafen, onGuildVoiceSelfMute, onGuildVoiceStream, onGuildVoiceSuppress, onGuildVoiceUpdate, onGuildVoiceVideo, onHttpRequest, onMessageBulkDelete, onMessageContextInteraction, onMessageDelete, onMessageEmbed, onMessageReactionAdd, onMessageReactionRemove, onMessageReactionRemoveAll, onMessageReactionRemoveEmoji, onMessageUpdate, onModalInteraction, onPermissionOverrideCreate, onPermissionOverrideDelete, onPermissionOverrideUpdate, onRawGateway, onReady, onReconnected, onResumed, onRoleCreate, onRoleDelete, onRoleUpdateColor, onRoleUpdateHoisted, onRoleUpdateIcon, onRoleUpdateMentionable, onRoleUpdateName, onRoleUpdatePermissions, onRoleUpdatePosition, onSelectMenuInteraction, onSelfUpdateAvatar, onSelfUpdateMFA, onSelfUpdateName, onSelfUpdateVerified, onShutdown, onStageInstanceCreate, onStageInstanceDelete, onStageInstanceUpdatePrivacyLevel, onStageInstanceUpdateTopic, onStatusChange, onThreadHidden, onThreadMemberJoin, onThreadMemberLeave, onThreadRevealed, onUnavailableGuildJoined, onUnavailableGuildLeave, onUserActivityEnd, onUserActivityStart, onUserContextInteraction, onUserTyping, onUserUpdateActivities, onUserUpdateActivityOrder, onUserUpdateAvatar, onUserUpdateDiscriminator, onUserUpdateFlags, onUserUpdateName, onUserUpdateOnlineStatus
protected CommandEngine()
ICommandEngine
implementations.
It will initialize a SQLite database if the Repository
implementation is set as the
IRepository
implementation for the Engine (preset by default). You may change it
by using setRepository(IRepository)
method.public static void addCommandPackage(String path)
It will also look though sub-packaged.
public static ICommandEngine getInstance()
ICommandEngine
that is being used.
By default, CommandEngine
implementation will be used.
ICommandEngine
public static void setInstance(ICommandEngine newCommandConfig)
ICommandEngine
. It if highly recommended that to customize the
engine, you extend from the default implementation CommandEngine
instead of a raw version.
By default, CommandEngine
implementation will be used.
newCommandConfig
- custom implementation of ICommandEngine
public static void includeBuildInUtils()
Help: command to get simple and detailed information about commands.
Ping: Test to see if the bot is reachable.
Language: Set the language used in a guild.
prefix: Set the prefix the bot react to in a guild.
ICommandEngine.addCommand(ICommand)
instead.
HelpCommand
,
PrefixCommand
,
LanguageCommand
,
PrefixCommand
public void logWarn(String message)
ICommandEngine
logWarn
in interface ICommandEngine
message
- the message string to be loggedpublic void logDebug(String message)
ICommandEngine
logDebug
in interface ICommandEngine
message
- the message string to be loggedpublic void logInfo(String message)
ICommandEngine
logInfo
in interface ICommandEngine
message
- the message string to be loggedpublic void logError(String message)
ICommandEngine
logError
in interface ICommandEngine
message
- the message string to be loggedpublic ICommandEngine setHelp(String help)
ICommandEngine
setHelp
in interface ICommandEngine
help
- command nameHelpCommand
public ICommand getHelpCommand()
ICommandEngine
getHelpCommand
in interface ICommandEngine
public void loadCommands()
ICommandEngine
loadCommands
in interface ICommandEngine
public boolean isReactToMention()
ICommandEngine
isReactToMention
in interface ICommandEngine
public ICommandEngine setReactToMention(boolean reactToMention)
ICommandEngine
setReactToMention
in interface ICommandEngine
reactToMention
- True if the bot should react to mention calls.ICommandEngine.getPrefix(MessageReceivedEvent)
public boolean isReactToMention(net.dv8tion.jda.api.events.Event event)
ICommandEngine
isReactToMention
in interface ICommandEngine
event
- Discord event that triggered this function call.@Nullable public @Nullable ICommand getCommand(@NotNull @NotNull String name)
ICommandEngine
getCommand
in interface ICommandEngine
name
- command's name.ICommand
instance.ICommand
@NotNull public @NotNull List<ICommand> getCommandsByPartialMatch(String name)
ICommandEngine
getCommandsByPartialMatch
in interface ICommandEngine
name
- partial command's name.@NotNull public @NotNull List<ICommand> getCommandsByExactMatch(String name)
ICommandEngine
getCommandsByExactMatch
in interface ICommandEngine
name
- expected command's name.@Contract(value=" -> new") @NotNull public final @NotNull @UnmodifiableView List<ICommand> getCommands()
ICommandEngine
ICommand
registered in the Engine.getCommands
in interface ICommandEngine
public ICommandEngine addCommand(@NotNull @NotNull ICommand command) throws DuplicatedNameException, InvalidNameException
ICommandEngine
addCommand
in interface ICommandEngine
command
- The command to be registered.DuplicatedNameException
- Error if there's another command with the same name or alias registered.InvalidNameException
- Error if the command doesn't match the expected name.public ICommandEngine addAlias(@NotNull @NotNull String name, ICommand command) throws DuplicatedNameException, InvalidNameException
ICommandEngine
addAlias
in interface ICommandEngine
name
- alternative name.command
- Command to be called.DuplicatedNameException
- Thrown when there's already a commando with the same name/alias.InvalidNameException
- Thrown when the command's alias uses non-alphanumeric characters.public String getPrefix(@NotNull @NotNull net.dv8tion.jda.api.events.message.MessageReceivedEvent event)
ICommandEngine
getPrefix
in interface ICommandEngine
event
- Message Received event that triggered this request.public String getPrefix(@NotNull @NotNull net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event)
ICommandEngine
getPrefix
in interface ICommandEngine
event
- Slash command that triggered this request.public String getPrefix(@NotNull @NotNull net.dv8tion.jda.api.events.Event event)
ICommandEngine
getPrefix
in interface ICommandEngine
event
- Event that triggered this request.public String getPrefix()
ICommandEngine
getPrefix
in interface ICommandEngine
public ICommandEngine setPrefix(@NotNull @NotNull String prefix)
ICommandEngine
setPrefix
in interface ICommandEngine
prefix
- prefix string.public ICommandEngine setPrefix(@NotNull @NotNull net.dv8tion.jda.api.entities.Guild guild, @NotNull @NotNull String prefix)
ICommandEngine
setPrefix
in interface ICommandEngine
guild
- Guild object.prefix
- prefix String.public Locale getLanguage()
ICommandEngine
getLanguage
in interface ICommandEngine
MultiLocaleResourceBundle.getSupportedLocale()
public ICommandEngine setLanguage(@NotNull @NotNull Locale language)
ICommandEngine
setLanguage
in interface ICommandEngine
language
- Locale to use.MultiLocaleResourceBundle.getSupportedLocale()
public Locale getLanguage(@Nullable @Nullable net.dv8tion.jda.api.events.Event event)
ICommandEngine
getLanguage
in interface ICommandEngine
event
- Discord event that triggered this function call.MultiLocaleResourceBundle.getSupportedLocale()
@NotNull public final @NotNull String getString(@NotNull @NotNull String key)
ICommandEngine
getString
in interface ICommandEngine
key
- String key in resourceBundle.@NotNull public final @NotNull String getString(@NotNull @NotNull String key, @NotNull @NotNull Locale locale)
ICommandEngine
getString
in interface ICommandEngine
key
- String key in resourceBundle.locale
- expected language.@NotNull public final @NotNull String[] getStringArray(@NotNull @NotNull String key)
ICommandEngine
getStringArray
in interface ICommandEngine
key
- String key in resourceBundle.@NotNull public final @NotNull String[] getStringArray(@NotNull @NotNull String key, @NotNull @NotNull Locale locale)
ICommandEngine
getStringArray
in interface ICommandEngine
key
- String key in resourceBundle.locale
- Expected language.public net.dv8tion.jda.api.JDA getJda()
public ICommandEngine setJda(net.dv8tion.jda.api.JDA jda)
jda
- Built JDA object.public IRepository getRepository()
ICommandEngine
getRepository
in interface ICommandEngine
public static void setRepository(IRepository repository)
public final void onMessageReceived(@NotNull @NotNull net.dv8tion.jda.api.events.message.MessageReceivedEvent event)
onMessageReceived
in class net.dv8tion.jda.api.hooks.ListenerAdapter
public void onSlashCommandInteraction(@NotNull @NotNull net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event)
onSlashCommandInteraction
in class net.dv8tion.jda.api.hooks.ListenerAdapter
@NotNull public static @NotNull net.dv8tion.jda.api.JDA createLight(String token) throws LoginException, IllegalArgumentException
token
- The bot token to use.LoginException
- If the provided token is invalid.IllegalArgumentException
- If the provided token is empty or null.
Or the provided intents/cache configuration is not possible.JDABuilder.build()
@NotNull public static @NotNull net.dv8tion.jda.api.JDA createLight(String token, Collection<net.dv8tion.jda.api.requests.GatewayIntent> intents) throws LoginException, IllegalArgumentException
token
- The bot token to use.intents
- The gateway intents to useLoginException
- If the provided token is invalid.IllegalArgumentException
- If the provided token is empty or null.
Or the provided intents/cache configuration is not possible.JDABuilder.createLight(String, Collection)
,
JDABuilder.build()
@NotNull public static @NotNull net.dv8tion.jda.api.JDA createLight(String token, net.dv8tion.jda.api.requests.GatewayIntent intent, net.dv8tion.jda.api.requests.GatewayIntent... intents) throws LoginException, IllegalArgumentException
token
- The bot token to useintent
- The first intent to useintents
- The other gateway intents to useLoginException
- If the provided token is invalid.IllegalArgumentException
- If the provided token is empty or null.
Or the provided intents/cache configuration is not possible.JDABuilder.createLight(String, GatewayIntent, GatewayIntent...)
,
JDABuilder.build()
@NotNull public static @NotNull net.dv8tion.jda.api.JDA create(String token, @Nonnull Collection<net.dv8tion.jda.api.requests.GatewayIntent> intents) throws LoginException, IllegalArgumentException
token
- The bot token to useintents
- The gateway intents to useLoginException
- If the provided token is invalid.IllegalArgumentException
- If the provided token is empty or null.
Or the provided intents/cache configuration is not possible.JDABuilder.create(String, GatewayIntent, GatewayIntent...)
,
JDABuilder.build()
@NotNull public static @NotNull net.dv8tion.jda.api.JDA create(String token, net.dv8tion.jda.api.requests.GatewayIntent intent, net.dv8tion.jda.api.requests.GatewayIntent... intents) throws LoginException, IllegalArgumentException
token
- The bot token to useintent
- The first intent to useintents
- The other gateway intents to useLoginException
- If the provided token is invalid.IllegalArgumentException
- If the provided token is empty or null.
Or the provided intents/cache configuration is not possible.JDABuilder.create(String, GatewayIntent, GatewayIntent...)
,
JDABuilder.build()
@NotNull public static @NotNull net.dv8tion.jda.api.JDA createDefault(String token) throws LoginException, IllegalArgumentException
token
- The bot token to use.LoginException
- If the provided token is invalid.IllegalArgumentException
- If the provided token is empty or null.
Or the provided intents/cache configuration is not possible.JDABuilder.createDefault(String)
,
JDABuilder.build()
@NotNull public static @NotNull net.dv8tion.jda.api.JDA createDefault(String token, Collection<net.dv8tion.jda.api.requests.GatewayIntent> intents) throws LoginException, IllegalArgumentException
token
- The bot token to use.intents
- The gateway intents to useLoginException
- If the provided token is invalid.IllegalArgumentException
- If the provided token is empty or null.
Or the provided intents/cache configuration is not possible.JDABuilder.createDefault(String, Collection)
,
JDABuilder.build()
@NotNull public static @NotNull net.dv8tion.jda.api.JDA createDefault(String token, net.dv8tion.jda.api.requests.GatewayIntent intent, net.dv8tion.jda.api.requests.GatewayIntent... intents) throws LoginException, IllegalArgumentException
token
- The bot token to useintent
- The first intent to useintents
- The other gateway intents to useLoginException
- If the provided token is invalid.IllegalArgumentException
- If the provided token is empty or null.
Or the provided intents/cache configuration is not possible.JDABuilder.createDefault(String, GatewayIntent, GatewayIntent...)
,
JDABuilder.build()
@NotNull public static @NotNull net.dv8tion.jda.api.JDA create(@NotNull @NotNull net.dv8tion.jda.api.JDABuilder builder) throws LoginException, IllegalArgumentException
This will build the JDA object.
builder
- preset JDABuilderLoginException
- If the provided token is invalid.IllegalArgumentException
- If the provided token is empty or null.
Or the provided intents/cache configuration is not possible.