Skip to content

Commit

Permalink
chore: update JDA
Browse files Browse the repository at this point in the history
  • Loading branch information
ANutley committed Aug 5, 2024
1 parent 95bbee3 commit 00cd2a4
Show file tree
Hide file tree
Showing 20 changed files with 121 additions and 106 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ allprojects {
ext {
dependencies {
// Creates shortcuts to avoid repeating dependencies throughout modules
jda = { [group: 'net.dv8tion', name: 'JDA', version: "5.0.0-alpha.17"] }
jda = { [group: 'net.dv8tion', name: 'JDA', version: "5.0.2"] }
logback = { [group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.11'] }
reflections = { [group: 'org.reflections', name: 'reflections', version: '0.10.2'] }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import me.anutley.jdautils.commands.events.*;
import me.anutley.jdautils.commands.text.TextCommand;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.StandardGuildMessageChannel;
import net.dv8tion.jda.api.entities.channel.middleman.StandardGuildMessageChannel;
import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import me.anutley.jdautils.commands.application.slash.SlashCommand;
import me.anutley.jdautils.commands.application.slash.SlashCommandOption;
import me.anutley.jdautils.commands.application.slash.annotations.JDASlashCommand;
import net.dv8tion.jda.api.entities.ChannelType;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.Command;
import net.dv8tion.jda.api.interactions.commands.OptionType;
Expand Down Expand Up @@ -148,7 +148,7 @@ public List<ApplicationCommandData> getCommandData() {
*/
public SlashCommand getCommandFromEvent(SlashCommandInteractionEvent event) {

return this.commands.stream().filter(slashCommand -> slashCommand.getAnnotation().name().equals(event.getCommandPath()))
return this.commands.stream().filter(slashCommand -> slashCommand.getAnnotation().name().equals(event.getFullCommandName()))
.findFirst()
.orElse(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import me.anutley.jdautils.commands.annotations.CommandMeta;
import me.anutley.jdautils.commands.application.slash.annotations.JDASlashCommand;
import me.anutley.jdautils.commands.events.SlashCommandEvent;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.channel.concrete.*;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import net.dv8tion.jda.api.entities.channel.unions.GuildChannelUnion;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.anutley.jdautils.commands.application.slash.annotations;

import net.dv8tion.jda.api.entities.ChannelType;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.interactions.commands.Command.Option;
import net.dv8tion.jda.api.interactions.commands.OptionType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import me.anutley.jdautils.commands.Command;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.events.GenericEvent;
import net.dv8tion.jda.api.interactions.commands.CommandInteraction;
import org.jetbrains.annotations.Nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import me.anutley.jdautils.commands.application.context.MessageContextCommand;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.CommandInteraction;
import org.jetbrains.annotations.Nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import me.anutley.jdautils.commands.application.slash.SlashCommand;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.interaction.command.GenericContextInteractionEvent;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.Interaction;
import net.dv8tion.jda.api.interactions.commands.CommandInteraction;
import org.jetbrains.annotations.Nullable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import me.anutley.jdautils.commands.text.TextCommand;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.interactions.commands.CommandInteraction;
import org.jetbrains.annotations.Nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import me.anutley.jdautils.commands.application.context.UserContextCommand;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.CommandInteraction;
import org.jetbrains.annotations.Nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.dv8tion.jda.api.events.Event;
import net.dv8tion.jda.api.events.GenericEvent;
import net.dv8tion.jda.api.events.ShutdownEvent;
import net.dv8tion.jda.api.events.session.ShutdownEvent;
import net.dv8tion.jda.api.hooks.EventListener;
import org.jetbrains.annotations.NotNull;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void main(String[] args) throws LoginException, InterruptedExcepti
JDA jda = JDABuilder.createDefault(args[0])
.setEnabledIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_EMOJIS_AND_STICKERS, GatewayIntent.DIRECT_MESSAGES, GatewayIntent.GUILD_MESSAGE_REACTIONS)
.addEventListeners(waiter)
.disableCache(CacheFlag.VOICE_STATE)
.disableCache(CacheFlag.VOICE_STATE, CacheFlag.SCHEDULED_EVENTS)
.setMemberCachePolicy(MemberCachePolicy.ALL)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import me.anutley.jdautils.commands.application.slash.annotations.JDASlashCommand;
import me.anutley.jdautils.commands.events.SlashCommandEvent;
import me.anutley.jdautils.menus.ButtonMenu;
import me.anutley.jdautils.menus.SelectionMenu;
import me.anutley.jdautils.menus.StringSelectionMenu;
import me.anutley.jdautils.menus.paginator.ButtonPaginator;
import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.interactions.components.ActionRow;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.interactions.components.selections.SelectMenu;
import net.dv8tion.jda.api.interactions.components.selections.StringSelectMenu;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import net.dv8tion.jda.api.utils.messages.MessageEditBuilder;

import java.util.concurrent.TimeUnit;

Expand All @@ -24,8 +25,8 @@ public void buttonPaginator(SlashCommandEvent event) {
.setEventWaiter(MenuBot.waiter())
.setTimeout(20)
.setUnits(TimeUnit.SECONDS)
.addPage(new MessageBuilder().setContent("test").build())
.addPage(new MessageBuilder().setContent("test2").build())
.addPage(new MessageCreateBuilder().setContent("test").build())
.addPage(new MessageCreateBuilder().setContent("test2").build())
.build().show(event.getDiscordEvent());
}

Expand All @@ -39,16 +40,26 @@ public void buttonMenu(SlashCommandEvent event) {
Button.danger("cancel", "Cancel")
))
.setAction(aEvent -> {
aEvent.deferEdit().queue();

if (aEvent.getButton().getId().equals("confirm")) {
aEvent.getMessage().editMessage("Confirmed!").override(true).queue();
aEvent.getMessage().editMessage(new MessageEditBuilder()
.setContent("Confirmed")
.setComponents() // clear confirm / deny buttons
.build())
.queue();
// Do some things here
} else if (aEvent.getButton().getId().equals("cancel")) {
aEvent.getMessage().editMessage("Cancelled!").override(true).queue();
aEvent.getMessage().editMessage(new MessageEditBuilder()
.setContent("Cancelled")
.setComponents() // clear confirm / deny buttons
.build())
.queue();
// Do some other stuff here
}
})
.setInitialMessage(
new MessageBuilder().setContent("Do you want to confirm or deny?").build()
new MessageCreateBuilder().setContent("Do you want to confirm or deny?").build()
)
.setRecursive(false)
.build()
Expand All @@ -58,18 +69,16 @@ public void buttonMenu(SlashCommandEvent event) {
@GuildCommand("833042350850441216")
@JDASlashCommand(name = "select-menu", description = "A select menu!")
public void selectMenu(SlashCommandEvent event) {
new SelectionMenu.Builder()
new StringSelectionMenu.Builder()
.setEventWaiter(MenuBot.waiter())
.addActionRows(ActionRow.of(
SelectMenu.create("test")
StringSelectMenu.create("test")
.addOption("Cool option 1", "Cool Option 1")
.addOption("Even cooler option 2", "Even Cooler Option 2")
.build()
)
).setAction(aEvent -> {
aEvent.reply(aEvent.getUser().getName() + " picked " + aEvent.getValues()).queue();
})
.setInitialMessage(new MessageBuilder().setContent("test").build())
).setAction(aEvent -> aEvent.reply(aEvent.getUser().getName() + " picked " + aEvent.getValues()).queue())
.setInitialMessage(new MessageCreateBuilder().setContent("test").build())
.setEphemeral(true)
.build().show(event.getDiscordEvent());
}
Expand Down
24 changes: 12 additions & 12 deletions menus/src/main/java/me/anutley/jdautils/menus/ButtonMenu.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package me.anutley.jdautils.menus;

import me.anutley.jdautils.eventwaiter.EventWaiter;
import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.interaction.command.GenericCommandInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
import net.dv8tion.jda.api.interactions.components.ActionRow;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import net.dv8tion.jda.api.utils.messages.MessageCreateData;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -18,11 +18,11 @@

public class ButtonMenu extends Menu {

protected final Message initialMessage;
protected final MessageCreateData initialMessage;
protected final Consumer<ButtonInteractionEvent> action;
protected final List<ActionRow> actionRows;

public ButtonMenu(EventWaiter eventWaiter, List<User> allowedUsers, List<Role> allowedRoles, long timeout, TimeUnit units, boolean recursive, boolean ephemeral, Message initialMessage, Consumer<ButtonInteractionEvent> action, List<ActionRow> actionRows) {
public ButtonMenu(EventWaiter eventWaiter, List<User> allowedUsers, List<Role> allowedRoles, long timeout, TimeUnit units, boolean recursive, boolean ephemeral, MessageCreateData initialMessage, Consumer<ButtonInteractionEvent> action, List<ActionRow> actionRows) {
super(eventWaiter, allowedUsers, allowedRoles, timeout, units, recursive, ephemeral);
this.initialMessage = initialMessage;
this.action = action;
Expand All @@ -32,8 +32,8 @@ public ButtonMenu(EventWaiter eventWaiter, List<User> allowedUsers, List<Role> a
@Override
public void show(MessageChannel channel) {
channel.sendMessage(
new MessageBuilder(initialMessage)
.setActionRows(actionRows)
MessageCreateBuilder.from(initialMessage)
.setComponents(actionRows)
.build()
).queue(
success -> waitForClick(success.getIdLong())
Expand All @@ -43,8 +43,8 @@ public void show(MessageChannel channel) {
@Override
public void show(GenericCommandInteractionEvent event) {
event.reply(
new MessageBuilder(initialMessage)
.setActionRows(actionRows)
MessageCreateBuilder.from(initialMessage)
.setComponents(actionRows)
.build()
).setEphemeral(ephemeral).queue(
success -> success.retrieveOriginal().queue(m -> waitForClick(m.getIdLong()))
Expand All @@ -67,15 +67,15 @@ private void waitForClick(long messageId) {

public static class Builder extends Menu.Builder<Builder, ButtonMenu> {

protected Message initialMessage = null;
protected MessageCreateData initialMessage = null;
protected Consumer<ButtonInteractionEvent> action = null;
protected List<ActionRow> actionRows = new ArrayList<>();

@Override
public ButtonMenu build() {

if (eventWaiter == null) throw new IllegalStateException("The Event Waiter must be set!");
if (actionRows.size() == 0) throw new IllegalStateException("There must be at least one action row");
if (actionRows.isEmpty()) throw new IllegalStateException("There must be at least one action row");
if (action == null) throw new IllegalStateException("There must be a callback action");
if (initialMessage == null) throw new IllegalStateException("There must be an initial message");

Expand All @@ -97,7 +97,7 @@ public ButtonMenu build() {
* @param initialMessage Sets the initial message that should be sent with the components
* @return Itself for chaining convenience
*/
public Builder setInitialMessage(Message initialMessage) {
public Builder setInitialMessage(MessageCreateData initialMessage) {
this.initialMessage = initialMessage;
return this;
}
Expand Down
2 changes: 1 addition & 1 deletion menus/src/main/java/me/anutley/jdautils/menus/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import me.anutley.jdautils.eventwaiter.EventWaiter;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.events.interaction.command.GenericCommandInteractionEvent;
import org.jetbrains.annotations.Nullable;

Expand Down
18 changes: 9 additions & 9 deletions menus/src/main/java/me/anutley/jdautils/menus/ReactionMenu.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package me.anutley.jdautils.menus;

import me.anutley.jdautils.eventwaiter.EventWaiter;
import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.events.interaction.command.GenericCommandInteractionEvent;
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import net.dv8tion.jda.api.utils.messages.MessageCreateData;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -18,11 +18,11 @@

public class ReactionMenu extends Menu {

protected final Message initialMessage;
protected final MessageCreateData initialMessage;
protected final Consumer<MessageReactionAddEvent> action;
protected final List<String> reactions;

public ReactionMenu(EventWaiter eventWaiter, List<User> allowedUsers, List<Role> allowedRoles, long timeout, TimeUnit units, boolean recursive, boolean ephemeral, Message initialMessage, Consumer<MessageReactionAddEvent> action, List<String> reactions) {
public ReactionMenu(EventWaiter eventWaiter, List<User> allowedUsers, List<Role> allowedRoles, long timeout, TimeUnit units, boolean recursive, boolean ephemeral, MessageCreateData initialMessage, Consumer<MessageReactionAddEvent> action, List<String> reactions) {
super(eventWaiter, allowedUsers, allowedRoles, timeout, units, recursive, ephemeral);
this.initialMessage = initialMessage;
this.action = action;
Expand All @@ -31,7 +31,7 @@ public ReactionMenu(EventWaiter eventWaiter, List<User> allowedUsers, List<Role>

@Override
public void show(MessageChannel channel) {
channel.sendMessage(new MessageBuilder(initialMessage).build()).queue(
channel.sendMessage(MessageCreateBuilder.from(initialMessage).build()).queue(
message -> {
reactions.forEach(r -> message.addReaction(Emoji.fromUnicode(r)).queue());
waitForClick(message.getIdLong());
Expand All @@ -42,7 +42,7 @@ public void show(MessageChannel channel) {
@Override
public void show(GenericCommandInteractionEvent event) {
event.reply(
new MessageBuilder((initialMessage))
MessageCreateBuilder.from((initialMessage))
.build()
).setEphemeral(ephemeral).queue(
success -> success.retrieveOriginal().queue(m -> {
Expand All @@ -69,7 +69,7 @@ private void waitForClick(long messageId) {

public static class Builder extends Menu.Builder<ReactionMenu.Builder, ReactionMenu> {

protected Message initialMessage = null;
protected MessageCreateData initialMessage = null;
protected Consumer<MessageReactionAddEvent> action = null;
protected List<String> reactions = new ArrayList<>();

Expand Down Expand Up @@ -99,7 +99,7 @@ public ReactionMenu build() {
* @param initialMessage Sets the initial message that should be sent with the components
* @return Itself for chaining convenience
*/
public Builder setInitialMessage(Message initialMessage) {
public Builder setInitialMessage(MessageCreateData initialMessage) {
this.initialMessage = initialMessage;
return this;
}
Expand Down
Loading

0 comments on commit 00cd2a4

Please sign in to comment.