Package com.github.ygimenez.listener
Class MessageHandler
java.lang.Object
net.dv8tion.jda.api.hooks.ListenerAdapter
com.github.ygimenez.listener.MessageHandler
- All Implemented Interfaces:
net.dv8tion.jda.api.hooks.EventListener
public class MessageHandler
extends net.dv8tion.jda.api.hooks.ListenerAdapter
Class responsible for handling reaction events sent by the handler.
Only one event is added to the handler to prevent cluttering and unnecessary listeners.
Only one event is added to the handler to prevent cluttering and unnecessary listeners.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddEvent(net.dv8tion.jda.api.entities.Message msg, ThrowingBiConsumer<net.dv8tion.jda.api.entities.User,PaginationEventWrapper> act)Adds an event to the handler, which will be executed whenever a button with the same ID is pressed.booleancheckEvent(String hash)Checks if an event hash is still present in the map.voidclear()Purge events map.
WARNING: This will break all active pagination, use with caution.Map<String,ThrowingBiConsumer<net.dv8tion.jda.api.entities.User,PaginationEventWrapper>>Retrieves the event handler map.voidonButtonInteraction(net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent evt)voidonMessageDelete(net.dv8tion.jda.api.events.message.MessageDeleteEvent evt)voidonMessageReactionAdd(net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent evt)voidonMessageReactionRemove(net.dv8tion.jda.api.events.message.react.MessageReactionRemoveEvent evt)voidremoveEvent(net.dv8tion.jda.api.entities.Message msg)Removes an event from the handler.Methods inherited from class net.dv8tion.jda.api.hooks.ListenerAdapter
onApplicationCommandUpdatePrivileges, onApplicationUpdatePrivileges, onChannelCreate, onChannelDelete, onChannelUpdateAppliedTags, onChannelUpdateArchived, onChannelUpdateArchiveTimestamp, onChannelUpdateAutoArchiveDuration, onChannelUpdateBitrate, onChannelUpdateDefaultReaction, onChannelUpdateDefaultThreadSlowmode, onChannelUpdateFlags, onChannelUpdateInvitable, onChannelUpdateLocked, onChannelUpdateName, onChannelUpdateNSFW, onChannelUpdateParent, onChannelUpdatePosition, onChannelUpdateRegion, onChannelUpdateSlowmode, onChannelUpdateTopic, onChannelUpdateType, onChannelUpdateUserLimit, onCommandAutoCompleteInteraction, onEmojiAdded, onEmojiRemoved, onEmojiUpdateName, onEmojiUpdateRoles, onEntitySelectInteraction, onEvent, onException, onForumTagAdd, onForumTagRemove, onForumTagUpdateEmoji, onForumTagUpdateModerated, onForumTagUpdateName, onGatewayPing, onGenericAutoCompleteInteraction, onGenericChannel, onGenericChannelUpdate, onGenericCommandInteraction, onGenericComponentInteractionCreate, onGenericContextInteraction, onGenericEmoji, onGenericEmojiUpdate, onGenericEvent, onGenericForumTag, onGenericForumTagUpdate, onGenericGuild, onGenericGuildInvite, onGenericGuildMember, onGenericGuildMemberUpdate, onGenericGuildSticker, onGenericGuildStickerUpdate, onGenericGuildUpdate, onGenericGuildVoice, onGenericInteractionCreate, onGenericMessage, onGenericMessageReaction, onGenericPermissionOverride, onGenericPrivilegeUpdate, onGenericRole, onGenericRoleUpdate, onGenericScheduledEventUpdate, onGenericSelectMenuInteraction, onGenericSelfUpdate, onGenericSessionEvent, onGenericStageInstance, onGenericStageInstanceUpdate, onGenericThread, onGenericThreadMember, onGenericUpdate, onGenericUser, onGenericUserPresence, onGuildAuditLogEntryCreate, 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, onGuildVoiceMute, onGuildVoiceRequestToSpeak, onGuildVoiceSelfDeafen, onGuildVoiceSelfMute, onGuildVoiceStream, onGuildVoiceSuppress, onGuildVoiceUpdate, onGuildVoiceVideo, onHttpRequest, onMessageBulkDelete, onMessageContextInteraction, onMessageEmbed, onMessageReactionRemoveAll, onMessageReactionRemoveEmoji, onMessageReceived, onMessageUpdate, onModalInteraction, onPermissionOverrideCreate, onPermissionOverrideDelete, onPermissionOverrideUpdate, onRawGateway, onReady, onRoleCreate, onRoleDelete, onRoleUpdateColor, onRoleUpdateHoisted, onRoleUpdateIcon, onRoleUpdateMentionable, onRoleUpdateName, onRoleUpdatePermissions, onRoleUpdatePosition, onScheduledEventCreate, onScheduledEventDelete, onScheduledEventUpdateDescription, onScheduledEventUpdateEndTime, onScheduledEventUpdateLocation, onScheduledEventUpdateName, onScheduledEventUpdateStartTime, onScheduledEventUpdateStatus, onScheduledEventUserAdd, onScheduledEventUserRemove, onSelfUpdateAvatar, onSelfUpdateMFA, onSelfUpdateName, onSelfUpdateVerified, onSessionDisconnect, onSessionInvalidate, onSessionRecreate, onSessionResume, onShutdown, onSlashCommandInteraction, onStageInstanceCreate, onStageInstanceDelete, onStageInstanceUpdatePrivacyLevel, onStageInstanceUpdateTopic, onStatusChange, onStringSelectInteraction, onThreadHidden, onThreadMemberJoin, onThreadMemberLeave, onThreadRevealed, onUnavailableGuildJoined, onUnavailableGuildLeave, onUserActivityEnd, onUserActivityStart, onUserContextInteraction, onUserTyping, onUserUpdateActivities, onUserUpdateActivityOrder, onUserUpdateAvatar, onUserUpdateDiscriminator, onUserUpdateFlags, onUserUpdateName, onUserUpdateOnlineStatus
-
Constructor Details
-
MessageHandler
public MessageHandler()Creates a newMessageHandlerinstance.
-
-
Method Details
-
addEvent
public ActionReference addEvent(@NotNull net.dv8tion.jda.api.entities.Message msg, @NotNull ThrowingBiConsumer<net.dv8tion.jda.api.entities.User,PaginationEventWrapper> act)Adds an event to the handler, which will be executed whenever a button with the same ID is pressed.- Parameters:
msg- TheMessageto hold the event.act- The action to be executed when the button is pressed.- Returns:
- An
ActionReferencepointing to this event. This is useful if you need to track whether an event is still being processed or was already removed (ie. garbage collected).
-
removeEvent
public void removeEvent(@NotNull net.dv8tion.jda.api.entities.Message msg)Removes an event from the handler.- Parameters:
msg- TheMessagewhich had attached events.
-
checkEvent
Checks if an event hash is still present in the map.- Parameters:
hash- The event hash.- Returns:
- Whether the hash exists in the events map (will be always false if hash is null).
-
getEventMap
public Map<String,ThrowingBiConsumer<net.dv8tion.jda.api.entities.User,PaginationEventWrapper>> getEventMap()Retrieves the event handler map. This will contain all currently active events being handled by the library mapped byMessageChannelID plus theMessageID.- Returns:
- An unmodifiable
Mapcontaining events handled by the library.
-
clear
public void clear()Purge events map.
WARNING: This will break all active pagination, use with caution. -
onMessageReactionAdd
public void onMessageReactionAdd(@NotNull net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent evt)- Overrides:
onMessageReactionAddin classnet.dv8tion.jda.api.hooks.ListenerAdapter
-
onMessageReactionRemove
public void onMessageReactionRemove(@NotNull net.dv8tion.jda.api.events.message.react.MessageReactionRemoveEvent evt)- Overrides:
onMessageReactionRemovein classnet.dv8tion.jda.api.hooks.ListenerAdapter
-
onMessageDelete
public void onMessageDelete(@NotNull net.dv8tion.jda.api.events.message.MessageDeleteEvent evt)- Overrides:
onMessageDeletein classnet.dv8tion.jda.api.hooks.ListenerAdapter
-
onButtonInteraction
public void onButtonInteraction(@NotNull net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent evt)- Overrides:
onButtonInteractionin classnet.dv8tion.jda.api.hooks.ListenerAdapter
-