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.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new MessageHandler instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    addEvent​(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.
    boolean
    checkEvent​(String hash)
    Checks if an event hash is still present in the map.
    void
    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.
    void
    onButtonInteraction​(net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent evt)
     
    void
    onMessageDelete​(net.dv8tion.jda.api.events.message.MessageDeleteEvent evt)
     
    void
    onMessageReactionAdd​(net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent evt)
     
    void
    onMessageReactionRemove​(net.dv8tion.jda.api.events.message.react.MessageReactionRemoveEvent evt)
     
    void
    removeEvent​(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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MessageHandler

      public MessageHandler()
      Creates a new MessageHandler instance.
  • 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 - The Message to hold the event.
      act - The action to be executed when the button is pressed.
      Returns:
      An ActionReference pointing 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 - The Message which had attached events.
    • checkEvent

      public boolean checkEvent(@Nullable String hash)
      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 by MessageChannel ID plus the Message ID.
      Returns:
      An unmodifiable Map containing 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:
      onMessageReactionAdd in class net.dv8tion.jda.api.hooks.ListenerAdapter
    • onMessageReactionRemove

      public void onMessageReactionRemove(@NotNull net.dv8tion.jda.api.events.message.react.MessageReactionRemoveEvent evt)
      Overrides:
      onMessageReactionRemove in class net.dv8tion.jda.api.hooks.ListenerAdapter
    • onMessageDelete

      public void onMessageDelete(@NotNull net.dv8tion.jda.api.events.message.MessageDeleteEvent evt)
      Overrides:
      onMessageDelete in class net.dv8tion.jda.api.hooks.ListenerAdapter
    • onButtonInteraction

      public void onButtonInteraction(@NotNull net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent evt)
      Overrides:
      onButtonInteraction in class net.dv8tion.jda.api.hooks.ListenerAdapter