From 9856f5c90ed4a3607ba0299695a9d09ad3f33dc2 Mon Sep 17 00:00:00 2001 From: southernscreamer32 Date: Sat, 18 Nov 2023 23:34:58 -0800 Subject: [PATCH] Updated dependencies: lavaplayer 1.3.78 -> 2.0.3, JDA 4.4.1 -> 5.0.0, JDA-Utilities 3.0.5 -> integrated and a bunch of smaller stuff too --- pom.xml | 13 ++- .../hayashi/jdautilities/command/Command.java | 45 +------- .../jdautilities/command/CommandEvent.java | 32 +++--- .../command/GuildSettingsManager.java | 24 ---- .../command/GuildSettingsProvider.java | 2 - .../command/impl/CommandClientImpl.java | 20 ++-- .../commons/utils/FinderUtil.java | 32 +++--- .../commons/waiter/EventWaiter.java | 2 +- .../hayashi/jdautilities/menu/ButtonMenu.java | 73 +++++------- .../java/hayashi/jdautilities/menu/Menu.java | 4 +- .../jdautilities/menu/OrderedMenu.java | 57 ++++++---- .../hayashi/jdautilities/menu/Paginator.java | 99 ++++++++--------- .../jdautilities/menu/SelectionDialog.java | 67 ++++++----- .../hayashi/jdautilities/menu/Slideshow.java | 104 +++++++++--------- src/main/java/hayashi/raiko/ChatBot.java | 2 +- src/main/java/hayashi/raiko/Listener.java | 9 +- src/main/java/hayashi/raiko/Raiko.java | 18 +-- .../hayashi/raiko/audio/AudioHandler.java | 16 +-- .../raiko/audio/NowplayingHandler.java | 9 +- .../hayashi/raiko/commands/MusicCommand.java | 14 ++- .../raiko/commands/admin/SettcCmd.java | 2 +- .../raiko/commands/admin/SetvcCmd.java | 2 +- .../raiko/commands/general/AboutCommand.java | 2 +- .../raiko/commands/general/SettingsCmd.java | 15 ++- .../raiko/commands/music/NowplayingCmd.java | 5 +- .../hayashi/raiko/commands/music/PlayCmd.java | 7 +- .../raiko/commands/music/QueueCmd.java | 11 +- .../raiko/commands/music/ShuffleCmd.java | 4 +- .../raiko/commands/owner/DebugCmd.java | 5 +- .../java/hayashi/raiko/settings/Settings.java | 3 +- .../java/hayashi/raiko/utils/FormatUtil.java | 3 +- src/test/java/hayashi/raiko/CTest.java | 2 +- 32 files changed, 323 insertions(+), 380 deletions(-) diff --git a/pom.xml b/pom.xml index 164cf9275..6a269b8a4 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,7 @@ net.dv8tion JDA - 4.4.1_353 + 5.0.0-beta.17 @@ -82,17 +82,22 @@ ch.qos.logback logback-classic - 1.2.9 + 1.2.12 com.typesafe config - 1.3.2 + 1.4.3 org.jsoup jsoup - 1.15.3 + 1.16.2 + + + commons-codec + commons-codec + 1.13 diff --git a/src/main/java/hayashi/jdautilities/command/Command.java b/src/main/java/hayashi/jdautilities/command/Command.java index e9ba7273f..a6f685338 100644 --- a/src/main/java/hayashi/jdautilities/command/Command.java +++ b/src/main/java/hayashi/jdautilities/command/Command.java @@ -21,47 +21,10 @@ import java.util.function.Predicate; import java.util.regex.Pattern; import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.*; +import net.dv8tion.jda.api.entities.GuildVoiceState; +import net.dv8tion.jda.api.entities.channel.*; +import net.dv8tion.jda.api.entities.channel.concrete.*; -/** - * - *

The internal inheritance for Commands used in JDA-Utilities is that of the Command object. - * - *

Classes created inheriting this class gain the unique traits of commands operated using the Commands Extension. - *
Using several fields, a command can define properties that make it unique and complex while maintaining - * a low level of development. - *
All Commands extending this class can define any number of these fields in a object constructor and then - * create the command action/response in the abstract - * {@link Command#execute(CommandEvent) #execute(CommandEvent)} body: - * - *

 public class ExampleCmd extends Command {
- *
- *      public ExampleCmd() {
- *          this.name = "example";
- *          this.aliases = new String[]{"test","demo"};
- *          this.help = "gives an example of commands do";
- *      }
- *
- *      {@literal @Override}
- *      protected void execute(CommandEvent) {
- *          event.reply("Hey look! This would be the bot's reply if this was a command!");
- *      }
- *
- * }
- *

- * Execution is with the provision of a MessageReceivedEvent-CommandClient wrapper called a - * {@link CommandEvent CommandEvent} and is performed in two steps: - *

- * - * @author John Grosh (jagrosh) - */ public abstract class Command { public static final Pattern COMPILE = Pattern.compile("\\s+"); @@ -146,7 +109,7 @@ public final void run(CommandEvent event) { if (p.isChannel()) { if (p.name().startsWith("VOICE")) { GuildVoiceState gvc = event.getMember().getVoiceState(); - VoiceChannel vc = gvc == null ? null : gvc.getChannel(); + VoiceChannel vc = gvc == null ? null : gvc.getChannel().asVoiceChannel(); if (vc == null) { terminate(event, event.getClient().getError() + " You must be in a voice channel to use that!"); return; diff --git a/src/main/java/hayashi/jdautilities/command/CommandEvent.java b/src/main/java/hayashi/jdautilities/command/CommandEvent.java index c450480a5..2c8655327 100644 --- a/src/main/java/hayashi/jdautilities/command/CommandEvent.java +++ b/src/main/java/hayashi/jdautilities/command/CommandEvent.java @@ -23,9 +23,15 @@ import hayashi.jdautilities.command.impl.CommandClientImpl; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.*; +import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.exceptions.PermissionException; +import net.dv8tion.jda.api.utils.FileUpload; +import net.dv8tion.jda.api.utils.messages.MessageCreateData; import net.dv8tion.jda.internal.utils.Checks; +import net.dv8tion.jda.api.entities.channel.*; +import net.dv8tion.jda.api.entities.channel.concrete.*; +import net.dv8tion.jda.api.entities.channel.middleman.*; public class CommandEvent { private static final Pattern COMPILE = Pattern.compile(""); @@ -99,14 +105,14 @@ public void reply(MessageEmbed embed, Consumer success, Consumer { if (event.isFromType(ChannelType.TEXT)) linkId(m); }); } - public void reply(Message message, Consumer success) { + public void reply(MessageCreateData message, Consumer success) { event.getChannel().sendMessage(message).queue(m -> { if (event.isFromType(ChannelType.TEXT)) linkId(m); @@ -114,7 +120,7 @@ public void reply(Message message, Consumer success) { }); } - public void reply(Message message, Consumer success, Consumer failure) { + public void reply(MessageCreateData message, Consumer success, Consumer failure) { event.getChannel().sendMessage(message).queue(m -> { if (event.isFromType(ChannelType.TEXT)) linkId(m); @@ -123,11 +129,11 @@ public void reply(Message message, Consumer success, Consumer success, Consumer pc.sendMessageEmbeds(embed).queue(success, failure), failure); } - public void replyInDm(Message message) { + public void replyInDm(MessageCreateData message) { if (event.isFromType(ChannelType.PRIVATE)) reply(message); else event.getAuthor().openPrivateChannel().queue(pc -> pc.sendMessage(message).queue()); } - public void replyInDm(Message message, Consumer success) { + public void replyInDm(MessageCreateData message, Consumer success) { if (event.isFromType(ChannelType.PRIVATE)) getPrivateChannel().sendMessage(message).queue(success); else event.getAuthor().openPrivateChannel().queue(pc -> pc.sendMessage(message).queue(success)); } - public void replyInDm(Message message, Consumer success, Consumer failure) { + public void replyInDm(MessageCreateData message, Consumer success, Consumer failure) { if (event.isFromType(ChannelType.PRIVATE)) getPrivateChannel().sendMessage(message).queue(success, failure); else @@ -217,7 +223,7 @@ public void replyInDm(String message, File file, String filename) { if (event.isFromType(ChannelType.PRIVATE)) reply(message, file, filename); else - event.getAuthor().openPrivateChannel().queue(pc -> pc.sendFile(file, filename).content(message).queue()); + event.getAuthor().openPrivateChannel().queue(pc -> pc.sendFiles(FileUpload.fromData(file, filename)).setContent(message).queue()); } public void replySuccess(String message) { @@ -267,7 +273,7 @@ public void async(Runnable runnable) { private void react(String reaction) { if (reaction != null && !reaction.isEmpty()) try { - event.getMessage().addReaction(COMPILE.matcher(reaction).replaceAll("$1:$2")).queue(); + event.getMessage().addReaction(Emoji.fromFormatted(COMPILE.matcher(reaction).replaceAll("$1:$2"))).queue(); } catch (PermissionException ignored) {} } @@ -396,7 +402,7 @@ public Message getMessage() { } public PrivateChannel getPrivateChannel() { - return event.getPrivateChannel(); + return event.getChannel().asPrivateChannel(); } public long getResponseNumber() { @@ -404,7 +410,7 @@ public long getResponseNumber() { } public TextChannel getTextChannel() { - return event.getTextChannel(); + return event.getChannel().asTextChannel(); } public boolean isFromType(ChannelType channelType) { diff --git a/src/main/java/hayashi/jdautilities/command/GuildSettingsManager.java b/src/main/java/hayashi/jdautilities/command/GuildSettingsManager.java index 248c2268b..4093f860f 100644 --- a/src/main/java/hayashi/jdautilities/command/GuildSettingsManager.java +++ b/src/main/java/hayashi/jdautilities/command/GuildSettingsManager.java @@ -17,32 +17,8 @@ import net.dv8tion.jda.api.entities.Guild; -import javax.annotation.Nullable; - -/** - * An implementable frame for classes that handle Guild-Specific - * settings. - * - *

Standard implementations should be able to simply provide a - * type of {@link java.lang.Object Object} provided a non-null - * {@link net.dv8tion.jda.api.entities.Guild Guild}. Further - * customization of the implementation is allowed on the developer - * end. - * - * @param The specific type of the settings object. - * @author Kaidan Gustave - * @implNote Unless in the event of a major breaking change to - * JDA, there is no chance of implementations of this - * interface being required to implement additional - * methods. - *
If in the future it is decided to add a method - * to this interface, the method will have a default - * implementation that doesn't require developer additions. - * @since 2.0 - */ @FunctionalInterface public interface GuildSettingsManager { - @Nullable T getSettings(Guild guild); default void init() {} diff --git a/src/main/java/hayashi/jdautilities/command/GuildSettingsProvider.java b/src/main/java/hayashi/jdautilities/command/GuildSettingsProvider.java index 32dd6e57d..119bcbc68 100644 --- a/src/main/java/hayashi/jdautilities/command/GuildSettingsProvider.java +++ b/src/main/java/hayashi/jdautilities/command/GuildSettingsProvider.java @@ -15,11 +15,9 @@ */ package hayashi.jdautilities.command; -import javax.annotation.Nullable; import java.util.Collection; public interface GuildSettingsProvider { - @Nullable default Collection getPrefixes() { return null; } diff --git a/src/main/java/hayashi/jdautilities/command/impl/CommandClientImpl.java b/src/main/java/hayashi/jdautilities/command/impl/CommandClientImpl.java index 12044bcc4..39e0f94ed 100644 --- a/src/main/java/hayashi/jdautilities/command/impl/CommandClientImpl.java +++ b/src/main/java/hayashi/jdautilities/command/impl/CommandClientImpl.java @@ -24,12 +24,11 @@ import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.events.GenericEvent; -import net.dv8tion.jda.api.events.ReadyEvent; -import net.dv8tion.jda.api.events.ShutdownEvent; import net.dv8tion.jda.api.events.guild.GuildJoinEvent; import net.dv8tion.jda.api.events.guild.GuildLeaveEvent; +import net.dv8tion.jda.api.events.message.MessageDeleteEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; -import net.dv8tion.jda.api.events.message.guild.GuildMessageDeleteEvent; +import net.dv8tion.jda.api.events.session.*; import net.dv8tion.jda.api.hooks.EventListener; import net.dv8tion.jda.internal.utils.Checks; import okhttp3.*; @@ -37,7 +36,7 @@ import org.json.JSONTokener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - +import net.dv8tion.jda.api.entities.channel.*; import java.io.IOException; import java.io.Reader; import java.time.OffsetDateTime; @@ -68,6 +67,7 @@ public class CommandClientImpl implements CommandClient, EventListener { private final ScheduledExecutorService executor; private final AnnotatedModuleCompiler compiler; private final GuildSettingsManager manager; + private final MediaType mediaType = MediaType.parse("application/json"); private String textPrefix; private CommandListener listener; @@ -367,7 +367,7 @@ public void onEvent(GenericEvent event) { if (event instanceof MessageReceivedEvent e) onMessageReceived(e); - else if (event instanceof GuildMessageDeleteEvent e && usesLinkedDeletion()) + else if (event instanceof MessageDeleteEvent e && usesLinkedDeletion()) onMessageDelete(e); else if (event instanceof GuildJoinEvent e) { @@ -444,7 +444,7 @@ private void onMessageReceived(MessageReceivedEvent event) { listener.onCompletedCommand(cevent, null); return; // Help Consumer is done } - if (event.isFromType(ChannelType.PRIVATE) || event.getTextChannel().canTalk()) { + if (event.isFromType(ChannelType.PRIVATE) || event.getChannel().canTalk()) { final Command command; // this will be null if it's not a command // this may be cleanable synchronized (commandIndex) { @@ -504,7 +504,7 @@ public void onFailure(Call call, IOException e) { } client.newCall(new Request.Builder() - .post(RequestBody.create(MediaType.parse("application/json"), body.toString())) + .post(RequestBody.create(body.toString(),mediaType)) .url("https://discord.bots.gg/api/v1/bots/" + jda.getSelfUser().getId() + "/stats") .header("Authorization", botsKey) .header("Content-Type", "application/json") @@ -533,15 +533,15 @@ public void onFailure(Call call, IOException e) { } } - private void onMessageDelete(GuildMessageDeleteEvent event) { + private void onMessageDelete(MessageDeleteEvent event) { // We don't need to cover whether or not this client usesLinkedDeletion() because // that is checked in onEvent(Event) before this is even called. synchronized (linkMap) { if (linkMap.contains(event.getMessageIdLong())) { Set messages = linkMap.get(event.getMessageIdLong()); if (messages.size() > 1 && event.getGuild().getSelfMember() - .hasPermission(event.getChannel(), Permission.MESSAGE_MANAGE)) - event.getChannel().deleteMessages(messages).queue(unused -> { + .hasPermission(event.getChannel().asGuildMessageChannel(), Permission.MESSAGE_MANAGE)) + event.getChannel().asGuildMessageChannel().deleteMessages(messages).queue(unused -> { }, ignored -> { }); else if (!messages.isEmpty()) diff --git a/src/main/java/hayashi/jdautilities/commons/utils/FinderUtil.java b/src/main/java/hayashi/jdautilities/commons/utils/FinderUtil.java index 678512f31..92b3bd018 100644 --- a/src/main/java/hayashi/jdautilities/commons/utils/FinderUtil.java +++ b/src/main/java/hayashi/jdautilities/commons/utils/FinderUtil.java @@ -15,10 +15,12 @@ */ package hayashi.jdautilities.commons.utils; +import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji; import net.dv8tion.jda.api.sharding.ShardManager; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.utils.cache.SnowflakeCacheView; +import net.dv8tion.jda.api.entities.channel.concrete.*; import java.util.*; import java.util.regex.Matcher; @@ -370,50 +372,50 @@ else if (name.toLowerCase().contains(lowerquery) && startswith.isEmpty()) return Collections.unmodifiableList(contains); } - public static List findEmotes(String query, JDA jda) { + public static List findEmotes(String query, JDA jda) { return jdaFindEmotes(query, jda, true); } - public static List findShardEmotes(String query, JDA jda) { + public static List findShardEmotes(String query, JDA jda) { return jdaFindEmotes(query, jda, false); } - public static List findEmotes(String query, Guild guild) { + public static List findEmotes(String query, Guild guild) { Matcher mentionMatcher = EMOTE_MENTION.matcher(query); if (DISCORD_ID.matcher(query).matches()) { - Emote emote = guild.getEmoteById(query); + RichCustomEmoji emote = guild.getEmojiById(query); if (emote != null) return Collections.singletonList(emote); } else if (mentionMatcher.matches()) { - Emote emote = guild.getEmoteById(mentionMatcher.group(2)); + RichCustomEmoji emote = guild.getEmojiById(mentionMatcher.group(2)); if (emote != null && emote.getName().equals(mentionMatcher.group(1))) return Collections.singletonList(emote); } - return genericEmoteSearch(query, guild.getEmoteCache()); + return genericEmoteSearch(query, guild.getEmojiCache()); } - private static List jdaFindEmotes(String query, JDA jda, boolean useShardManager) { + private static List jdaFindEmotes(String query, JDA jda, boolean useShardManager) { Matcher mentionMatcher = EMOTE_MENTION.matcher(query); ShardManager manager = useShardManager ? jda.getShardManager() : null; if (DISCORD_ID.matcher(query).matches()) { - Emote emote = manager != null ? manager.getEmoteById(query) : jda.getEmoteById(query); + RichCustomEmoji emote = manager != null ? manager.getEmojiById(query) : jda.getEmojiById(query); if (emote != null) return Collections.singletonList(emote); } else if (mentionMatcher.matches()) { String emoteId = mentionMatcher.group(2); - Emote emote = manager != null ? manager.getEmoteById(emoteId) : jda.getEmoteById(emoteId); + RichCustomEmoji emote = manager != null ? manager.getEmojiById(emoteId) : jda.getEmojiById(emoteId); if (emote != null && emote.getName().equals(mentionMatcher.group(1))) return Collections.singletonList(emote); } - return genericEmoteSearch(query, jda.getEmoteCache()); + return genericEmoteSearch(query, jda.getEmojiCache()); } - private static List genericEmoteSearch(String query, SnowflakeCacheView cache) { - ArrayList exact = new ArrayList<>(); - ArrayList wrongcase = new ArrayList<>(); - ArrayList startswith = new ArrayList<>(); - ArrayList contains = new ArrayList<>(); + private static List genericEmoteSearch(String query, SnowflakeCacheView cache) { + ArrayList exact = new ArrayList<>(); + ArrayList wrongcase = new ArrayList<>(); + ArrayList startswith = new ArrayList<>(); + ArrayList contains = new ArrayList<>(); String lowerquery = query.toLowerCase(); cache.forEach(emote -> { String name = emote.getName(); diff --git a/src/main/java/hayashi/jdautilities/commons/waiter/EventWaiter.java b/src/main/java/hayashi/jdautilities/commons/waiter/EventWaiter.java index 5b1a6877e..41efdbc92 100644 --- a/src/main/java/hayashi/jdautilities/commons/waiter/EventWaiter.java +++ b/src/main/java/hayashi/jdautilities/commons/waiter/EventWaiter.java @@ -17,7 +17,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.*; import net.dv8tion.jda.api.hooks.EventListener; import net.dv8tion.jda.api.hooks.SubscribeEvent; import net.dv8tion.jda.internal.utils.Checks; diff --git a/src/main/java/hayashi/jdautilities/menu/ButtonMenu.java b/src/main/java/hayashi/jdautilities/menu/ButtonMenu.java index 6658afdb5..f3eedfb3c 100644 --- a/src/main/java/hayashi/jdautilities/menu/ButtonMenu.java +++ b/src/main/java/hayashi/jdautilities/menu/ButtonMenu.java @@ -24,26 +24,26 @@ import hayashi.jdautilities.commons.waiter.EventWaiter; import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.MessageBuilder; -import net.dv8tion.jda.api.entities.Emote; import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.MessageChannel; -import net.dv8tion.jda.api.entities.MessageReaction.ReactionEmote; +import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent; import net.dv8tion.jda.api.requests.RestAction; +import net.dv8tion.jda.api.utils.messages.MessageCreateData; +import net.dv8tion.jda.api.utils.messages.MessageEditBuilder; +import net.dv8tion.jda.api.utils.messages.MessageEditData; import net.dv8tion.jda.internal.utils.Checks; - +import net.dv8tion.jda.api.entities.channel.middleman.*; public class ButtonMenu extends Menu { private final Color color; private final String text, description; - private final List choices; - private final Consumer action; + private final List choices; + private final Consumer action; private final Consumer finalAction; ButtonMenu(EventWaiter waiter, Set users, Set roles, long timeout, TimeUnit unit, - Color incolor, String intext, String desc, List inchoices, Consumer inaction, Consumer infinalAction) { + Color incolor, String intext, String desc, List inchoices, Consumer inaction, Consumer infinalAction) { super(waiter, users, roles, timeout, unit); color = incolor; text = intext; @@ -55,7 +55,7 @@ public class ButtonMenu extends Menu { @Override public void display(MessageChannel channel) { - initialize(channel.sendMessage(getMessage())); + initialize(channel.sendMessage(MessageCreateData.fromEditData(getMessage()))); } @Override @@ -70,16 +70,16 @@ private void initialize(RestAction ra) { ra.queue(m -> { for (int i = 0; i < choices.size(); i++) { // Get the emote to display. - Emote emote; - try { - emote = m.getJDA().getEmoteById(choices.get(i)); - } catch (Exception e) { - emote = null; - } + Emoji emote = choices.get(i); +// try { +// emote = m.getJDA().getE(choices.get(i)); +// } catch (Exception e) { +// emote = null; +// } // If the emote is null that means that it might be an emoji. // If it's neither, that's on the developer and we'll let it // throw an error when we queue a rest action. - RestAction r = emote == null ? m.addReaction(choices.get(i)) : m.addReaction(emote); + RestAction r = m.addReaction(emote); if (i + 1 < choices.size()) { r.queue(); // If there is still more reactions to add we delay using the EventWaiter continue; @@ -98,16 +98,14 @@ private void initialize(RestAction ra) { // Last check is that the person who added the reaction // is a valid user. return event.getMessageId().equals(m.getId()) && - choices.contains(event.getReaction().getReactionEmote().isEmote() - ? event.getReaction().getReactionEmote().getId() - : event.getReaction().getReactionEmote().getName()) && + choices.contains(event.getReaction().getEmoji()) && isValidUser(event.getUser(), event.isFromGuild() ? event.getGuild() : null); }, (MessageReactionAddEvent event) -> { // What happens next is after a valid event // is fired and processed above. // Preform the specified action with the ReactionEmote - action.accept(event.getReaction().getReactionEmote()); + action.accept(event.getReaction().getEmoji()); finalAction.accept(m); }, timeout, unit, () -> finalAction.accept(m))); } @@ -115,10 +113,10 @@ private void initialize(RestAction ra) { } // Generates a ButtonMenu message - private Message getMessage() { - MessageBuilder mbuilder = new MessageBuilder(); + private MessageEditData getMessage() { + MessageEditBuilder mbuilder = new MessageEditBuilder(); if (text != null) - mbuilder.append(text); + mbuilder.setContent(text); if (description != null) mbuilder.setEmbeds(new EmbedBuilder().setColor(color).setDescription(description).build()); return mbuilder.build(); @@ -127,8 +125,8 @@ private Message getMessage() { public static class Builder extends Menu.Builder { private Color color; private String text, description; - private final List choices = new LinkedList<>(); - private Consumer action; + private final List choices = new LinkedList<>(); + private Consumer action; private Consumer finalAction = (m) -> {}; @Override @@ -156,7 +154,7 @@ public Builder setDescription(String desc) { return this; } - public Builder setAction(Consumer consumer) { + public Builder setAction(Consumer consumer) { action = consumer; return this; } @@ -166,35 +164,20 @@ public Builder setFinalAction(Consumer consumer) { return this; } - public Builder addChoice(String emoji) { + public Builder addChoice(Emoji emoji) { choices.add(emoji); return this; } - public Builder addChoice(Emote emote) { - return addChoice(emote.getId()); - } - - public Builder addChoices(String... emojis) { - for (String emoji : emojis) + public Builder addChoices(Emoji... emojis) { + for (Emoji emoji : emojis) addChoice(emoji); return this; } - public Builder addChoices(Emote... emotes) { - for (Emote emote : emotes) - addChoice(emote); - return this; - } - - public Builder setChoices(String... emojis) { + public Builder setChoices(Emoji... emojis) { choices.clear(); return addChoices(emojis); } - - public Builder setChoices(Emote... emotes) { - choices.clear(); - return addChoices(emotes); - } } } \ No newline at end of file diff --git a/src/main/java/hayashi/jdautilities/menu/Menu.java b/src/main/java/hayashi/jdautilities/menu/Menu.java index 25044c070..a1d2bcbba 100644 --- a/src/main/java/hayashi/jdautilities/menu/Menu.java +++ b/src/main/java/hayashi/jdautilities/menu/Menu.java @@ -23,7 +23,7 @@ import hayashi.jdautilities.commons.waiter.EventWaiter; import net.dv8tion.jda.api.entities.*; -import javax.annotation.Nullable; +import net.dv8tion.jda.api.entities.channel.middleman.*; public abstract class Menu { protected final EventWaiter waiter; @@ -48,7 +48,7 @@ protected boolean isValidUser(User user) { return isValidUser(user, null); } - protected boolean isValidUser(User user, @Nullable Guild guild) { + protected boolean isValidUser(User user, Guild guild) { if (user.isBot()) return false; if ((users.isEmpty() && roles.isEmpty()) || users.contains(user)) diff --git a/src/main/java/hayashi/jdautilities/menu/OrderedMenu.java b/src/main/java/hayashi/jdautilities/menu/OrderedMenu.java index a2edb48de..e11723900 100644 --- a/src/main/java/hayashi/jdautilities/menu/OrderedMenu.java +++ b/src/main/java/hayashi/jdautilities/menu/OrderedMenu.java @@ -25,20 +25,23 @@ import hayashi.jdautilities.commons.waiter.EventWaiter; import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.MessageBuilder; import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.ChannelType; import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.MessageChannel; import net.dv8tion.jda.api.entities.Role; -import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.events.message.GenericMessageEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent; import net.dv8tion.jda.api.exceptions.PermissionException; import net.dv8tion.jda.api.requests.RestAction; +import net.dv8tion.jda.api.utils.messages.MessageCreateData; +import net.dv8tion.jda.api.utils.messages.MessageEditBuilder; +import net.dv8tion.jda.api.utils.messages.MessageEditData; import net.dv8tion.jda.internal.utils.Checks; +import net.dv8tion.jda.api.entities.channel.*; +import net.dv8tion.jda.api.entities.channel.concrete.*; +import net.dv8tion.jda.api.entities.channel.middleman.*; public class OrderedMenu extends Menu { private final Color color; @@ -48,13 +51,21 @@ public class OrderedMenu extends Menu { private final Consumer cancel; private final boolean useLetters, allowTypedInput, useCancel; - public final static String[] NUMBERS = {"1\u20E3", "2\u20E3", "3\u20E3", - "4\u20E3", "5\u20E3", "6\u20E3", "7\u20E3", "8\u20E3", "9\u20E3", "\uD83D\uDD1F"}; + public final static Emoji[] NUMBERS = {Emoji.fromUnicode("1\u20E3"), + Emoji.fromUnicode("2\u20E3"), Emoji.fromUnicode("3\u20E3"), + Emoji.fromUnicode("4\u20E3"), Emoji.fromUnicode("5\u20E3"), + Emoji.fromUnicode("6\u20E3"), Emoji.fromUnicode("7\u20E3"), + Emoji.fromUnicode("8\u20E3"), Emoji.fromUnicode("9\u20E3"), + Emoji.fromUnicode("\uD83D\uDD1F")}; - public final static String[] LETTERS = {"\uD83C\uDDE6", "\uD83C\uDDE7", "\uD83C\uDDE8", - "\uD83C\uDDE9", "\uD83C\uDDEA", "\uD83C\uDDEB", "\uD83C\uDDEC", "\uD83C\uDDED", "\uD83C\uDDEE", "\uD83C\uDDEF"}; + public final static Emoji[] LETTERS = {Emoji.fromUnicode("\uD83C\uDDE6"), + Emoji.fromUnicode("\uD83C\uDDE7"), Emoji.fromUnicode("\uD83C\uDDE8"), + Emoji.fromUnicode("\uD83C\uDDE9"), Emoji.fromUnicode("\uD83C\uDDEA"), + Emoji.fromUnicode("\uD83C\uDDEB"), Emoji.fromUnicode("\uD83C\uDDEC"), + Emoji.fromUnicode("\uD83C\uDDED"), Emoji.fromUnicode("\uD83C\uDDEE"), + Emoji.fromUnicode("\uD83C\uDDEF")}; - public final static String CANCEL = "\u274C"; + public final static Emoji CANCEL = Emoji.fromUnicode("\u274C"); OrderedMenu(EventWaiter waiter, Set users, Set roles, long timeout, TimeUnit unit, Color c, String t, String d, List ch, BiConsumer biConsumer, @@ -81,7 +92,7 @@ public void display(MessageChannel channel) { && !allowTypedInput && !((TextChannel) channel).getGuild().getSelfMember().hasPermission((TextChannel) channel, Permission.MESSAGE_ADD_REACTION)) throw new PermissionException("Must be able to add reactions if not allowing typed input!"); - initialize(channel.sendMessage(getMessage())); + initialize(channel.sendMessage(MessageCreateData.fromEditData(getMessage()))); } @Override @@ -92,7 +103,7 @@ public void display(Message message) { // Does not have permission to add reactions if (message.getChannelType() == ChannelType.TEXT && !allowTypedInput - && !message.getGuild().getSelfMember().hasPermission(message.getTextChannel(), Permission.MESSAGE_ADD_REACTION)) + && !message.getGuild().getSelfMember().hasPermission(message.getChannel().asTextChannel(), Permission.MESSAGE_ADD_REACTION)) throw new PermissionException("Must be able to add reactions if not allowing typed input!"); initialize(message.editMessage(getMessage())); } @@ -160,13 +171,13 @@ private void waitGeneric(Message m) { // If it's a valid MessageReactionAddEvent if (e instanceof MessageReactionAddEvent event) { // Process which reaction it is - if (event.getReaction().getReactionEmote().getName().equals(CANCEL)) + if (event.getReaction().getEmoji().equals(CANCEL)) cancel.accept(m); else // The int provided in the success consumer is not indexed from 0 to number of choices - 1, // but from 1 to number of choices. So the first choice will correspond to 1, the second // choice to 2, etc. - action.accept(m, getNumber(event.getReaction().getReactionEmote().getName())); + action.accept(m, getNumber(event.getReaction().getEmoji())); } // If it's a valid MessageReceivedEvent else if (e instanceof MessageReceivedEvent event) { @@ -185,21 +196,21 @@ private void waitReactionOnly(Message m) { // This one is only for reactions waiter.waitForEvent(MessageReactionAddEvent.class, e -> isValidReaction(m, e), e -> { m.delete().queue(); - if (e.getReaction().getReactionEmote().getName().equals(CANCEL)) + if (e.getReaction().getEmoji().equals(CANCEL)) cancel.accept(m); else // The int provided in the success consumer is not indexed from 0 to number of choices - 1, // but from 1 to number of choices. So the first choice will correspond to 1, the second // choice to 2, etc. - action.accept(m, getNumber(e.getReaction().getReactionEmote().getName())); + action.accept(m, getNumber(e.getReaction().getEmoji())); }, timeout, unit, () -> cancel.accept(m)); } // This is where the displayed message for the OrderedMenu is built. - private Message getMessage() { - MessageBuilder mbuilder = new MessageBuilder(); + private MessageEditData getMessage() { + MessageEditBuilder mbuilder = new MessageEditBuilder(); if (text != null) - mbuilder.append(text); + mbuilder.setContent(text); StringBuilder sb = new StringBuilder(); for (int i = 0; i < choices.size(); i++) sb.append("\n").append(getEmoji(i)).append(" ").append(choices.get(i)); @@ -214,10 +225,10 @@ private boolean isValidReaction(Message m, MessageReactionAddEvent e) { if (!e.getMessageId().equals(m.getId()) || !isValidUser(e.getUser(), e.isFromGuild() ? e.getGuild() : null)) return false; // The reaction is the cancel reaction - if (e.getReaction().getReactionEmote().getName().equals(CANCEL)) + if (e.getReaction().getEmoji().equals(CANCEL)) return true; - int num = getNumber(e.getReaction().getReactionEmote().getName()); + int num = getNumber(e.getReaction().getEmoji()); return !(num < 0 || num > choices.size()); } @@ -227,7 +238,7 @@ private boolean isValidMessage(Message m, MessageReceivedEvent e) { return e.getChannel().equals(m.getChannel()) && isValidUser(e.getAuthor(), e.isFromGuild() ? e.getGuild() : null); } - private String getEmoji(int number) { + private Emoji getEmoji(int number) { return useLetters ? LETTERS[number] : NUMBERS[number]; } @@ -238,8 +249,8 @@ private String getEmoji(int number) { // this should be cleanable - private int getNumber(String emoji) { - String[] array = useLetters ? LETTERS : NUMBERS; + private int getNumber(Emoji emoji) { + Emoji[] array = useLetters ? LETTERS : NUMBERS; for (int i = 0; i < array.length; i++) if (array[i].equals(emoji)) return i + 1; diff --git a/src/main/java/hayashi/jdautilities/menu/Paginator.java b/src/main/java/hayashi/jdautilities/menu/Paginator.java index 850b5249b..319bfc647 100644 --- a/src/main/java/hayashi/jdautilities/menu/Paginator.java +++ b/src/main/java/hayashi/jdautilities/menu/Paginator.java @@ -26,17 +26,21 @@ import hayashi.jdautilities.commons.waiter.EventWaiter; import net.dv8tion.jda.api.EmbedBuilder; -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.emoji.Emoji; import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.entities.emoji.EmojiUnion; import net.dv8tion.jda.api.events.message.GenericMessageEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent; import net.dv8tion.jda.api.exceptions.PermissionException; import net.dv8tion.jda.api.requests.RestAction; +import net.dv8tion.jda.api.utils.messages.MessageCreateData; +import net.dv8tion.jda.api.utils.messages.MessageEditBuilder; +import net.dv8tion.jda.api.utils.messages.MessageEditData; import net.dv8tion.jda.internal.utils.Checks; +import net.dv8tion.jda.api.entities.channel.middleman.*; public class Paginator extends Menu { private final BiFunction color; @@ -47,11 +51,11 @@ public class Paginator extends Menu { private final Consumer finalAction; private final String leftText, rightText; - public static final String BIG_LEFT = "\u23EA"; - public static final String LEFT = "\u25C0"; - public static final String STOP = "\u23F9"; - public static final String RIGHT = "\u25B6"; - public static final String BIG_RIGHT = "\u23E9"; + public static final Emoji BIG_LEFT = Emoji.fromUnicode("\u23EA"); + public static final Emoji LEFT = Emoji.fromUnicode("\u25C0"); + public static final Emoji STOP = Emoji.fromUnicode("\u23F9"); + public static final Emoji RIGHT = Emoji.fromUnicode("\u25B6"); + public static final Emoji BIG_RIGHT = Emoji.fromUnicode("\u23E9"); Paginator(EventWaiter waiter, Set users, Set roles, long timeout, TimeUnit unit, BiFunction c, BiFunction function, @@ -91,7 +95,7 @@ public void paginate(MessageChannel channel, int pageNum) { pageNum = 1; else if (pageNum > pages) pageNum = pages; - initialize(channel.sendMessage(renderPage(pageNum)), pageNum); + initialize(channel.sendMessage(MessageCreateData.fromEditData(renderPage(pageNum))), pageNum); } public void paginate(Message message, int pageNum) { @@ -185,55 +189,52 @@ private void paginationWithoutTextInput(Message message, int pageNum) { private boolean checkReaction(MessageReactionAddEvent event, long messageId) { if (event.getMessageIdLong() != messageId) return false; - return switch (event.getReactionEmote().getName()) { - // LEFT, STOP, RIGHT, BIG_LEFT, BIG_RIGHT all fall-through to - // return if the User is valid or not. If none trip, this defaults - // and returns false. - case LEFT, STOP, RIGHT -> isValidUser(event.getUser(), event.isFromGuild() ? event.getGuild() : null); - case BIG_LEFT, BIG_RIGHT -> bulkSkipNumber > 1 && isValidUser(event.getUser(), event.isFromGuild() ? event.getGuild() : null); - default -> false; - }; + Emoji name = event.getEmoji();// LEFT, STOP, RIGHT, BIG_LEFT, BIG_RIGHT all fall-through to +// return if the User is valid or not. If none trip, this defaults +// and returns false. + if (name.equals(LEFT) || name.equals(STOP) || name.equals(RIGHT)) { + return isValidUser(event.getUser(), event.isFromGuild() ? event.getGuild() : null); + } + if (name.equals(BIG_LEFT) || name.equals(BIG_RIGHT)) { + return bulkSkipNumber > 1 && isValidUser(event.getUser(), event.isFromGuild() ? event.getGuild() : null); + } + return false; } // Private method that handles MessageReactionAddEvents // this should also be doable private void handleMessageReactionAddAction(MessageReactionAddEvent event, Message message, int pageNum) { int newPageNum = pageNum; - switch (event.getReaction().getReactionEmote().getName()) { - case LEFT -> { - if (newPageNum == 1 && wrapPageEnds) - newPageNum = pages + 1; - if (newPageNum > 1) + Emoji emoji = event.getReaction().getEmoji(); + if (emoji.equals(LEFT)) { + if (newPageNum == 1 && wrapPageEnds) + newPageNum = pages + 1; + if (newPageNum > 1) + newPageNum--; + } else if (emoji.equals(RIGHT)) { + if (newPageNum == pages && wrapPageEnds) + newPageNum = 0; + if (newPageNum < pages) + newPageNum++; + } else if (emoji.equals(BIG_LEFT)) { + if (newPageNum > 1 || wrapPageEnds) { + for (int i = 1; (newPageNum > 1 || wrapPageEnds) && i < bulkSkipNumber; i++) { + if (newPageNum == 1 && wrapPageEnds) + newPageNum = pages + 1; newPageNum--; - } - case RIGHT -> { - if (newPageNum == pages && wrapPageEnds) - newPageNum = 0; - if (newPageNum < pages) - newPageNum++; - } - case BIG_LEFT -> { - if (newPageNum > 1 || wrapPageEnds) { - for (int i = 1; (newPageNum > 1 || wrapPageEnds) && i < bulkSkipNumber; i++) { - if (newPageNum == 1 && wrapPageEnds) - newPageNum = pages + 1; - newPageNum--; - } } } - case BIG_RIGHT -> { - if (newPageNum < pages || wrapPageEnds) { - for (int i = 1; (newPageNum < pages || wrapPageEnds) && i < bulkSkipNumber; i++) { - if (newPageNum == pages && wrapPageEnds) - newPageNum = 0; - newPageNum++; - } + } else if (emoji.equals(BIG_RIGHT)) { + if (newPageNum < pages || wrapPageEnds) { + for (int i = 1; (newPageNum < pages || wrapPageEnds) && i < bulkSkipNumber; i++) { + if (newPageNum == pages && wrapPageEnds) + newPageNum = 0; + newPageNum++; } } - case STOP -> { - finalAction.accept(message); - return; - } + } else if (emoji.equals(STOP)) { + finalAction.accept(message); + return; } try { @@ -244,8 +245,8 @@ private void handleMessageReactionAddAction(MessageReactionAddEvent event, Messa message.editMessage(renderPage(newPageNum)).queue(m -> pagination(m, n)); } - private Message renderPage(int pageNum) { - MessageBuilder mbuilder = new MessageBuilder(); + private MessageEditData renderPage(int pageNum) { + MessageEditBuilder mbuilder = new MessageEditBuilder(); EmbedBuilder ebuilder = new EmbedBuilder(); int start = (pageNum - 1) * itemsPerPage; int end = Math.min(strings.size(), pageNum * itemsPerPage); @@ -269,7 +270,7 @@ private Message renderPage(int pageNum) { ebuilder.setFooter("Page " + pageNum + "/" + pages, null); mbuilder.setEmbeds(ebuilder.build()); if (text != null) - mbuilder.append(text.apply(pageNum, pages)); + mbuilder.setContent(text.apply(pageNum, pages)); return mbuilder.build(); } diff --git a/src/main/java/hayashi/jdautilities/menu/SelectionDialog.java b/src/main/java/hayashi/jdautilities/menu/SelectionDialog.java index ffbba083b..1fb6cf906 100644 --- a/src/main/java/hayashi/jdautilities/menu/SelectionDialog.java +++ b/src/main/java/hayashi/jdautilities/menu/SelectionDialog.java @@ -27,15 +27,16 @@ import hayashi.jdautilities.commons.waiter.EventWaiter; import net.dv8tion.jda.api.EmbedBuilder; -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.Role; import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent; import net.dv8tion.jda.api.exceptions.PermissionException; import net.dv8tion.jda.api.requests.RestAction; +import net.dv8tion.jda.api.utils.messages.*; import net.dv8tion.jda.internal.utils.Checks; +import net.dv8tion.jda.api.entities.channel.middleman.*; public class SelectionDialog extends Menu { private final List choices; @@ -46,10 +47,10 @@ public class SelectionDialog extends Menu { private final BiConsumer success; private final Consumer cancel; - public static final String UP = "\uD83D\uDD3C"; - public static final String DOWN = "\uD83D\uDD3D"; - public static final String SELECT = "\u2705"; - public static final String CANCEL = "\u274E"; + public static final Emoji UP = Emoji.fromUnicode("\uD83D\uDD3C"); + public static final Emoji DOWN = Emoji.fromUnicode("\uD83D\uDD3D"); + public static final Emoji SELECT = Emoji.fromUnicode("\u2705"); + public static final Emoji CANCEL = Emoji.fromUnicode("\u274E"); SelectionDialog(EventWaiter waiter, Set users, Set roles, long timeout, TimeUnit unit, List c, String le, String re, String dl, String dr, @@ -92,7 +93,7 @@ public void showDialog(MessageChannel channel, int selection) { selection = 1; else if (selection > choices.size()) selection = choices.size(); - initialize(channel.sendMessage(render(selection)), selection); + initialize(channel.sendMessage(MessageCreateData.fromEditData(render(selection))), selection); } public void showDialog(Message message, int selection) { @@ -121,36 +122,32 @@ private void selectionDialog(Message message, int selection) { waiter.waitForEvent(MessageReactionAddEvent.class, event -> { if (!event.getMessageId().equals(message.getId())) return false; - if (!(UP.equals(event.getReaction().getReactionEmote().getName()) - || DOWN.equals(event.getReaction().getReactionEmote().getName()) - || CANCEL.equals(event.getReaction().getReactionEmote().getName()) - || SELECT.equals(event.getReaction().getReactionEmote().getName()))) + if (!(UP.equals(event.getReaction().getEmoji()) + || DOWN.equals(event.getReaction().getEmoji()) + || CANCEL.equals(event.getReaction().getEmoji()) + || SELECT.equals(event.getReaction().getEmoji()))) return false; return isValidUser(event.getUser(), event.isFromGuild() ? event.getGuild() : null); }, event -> { int newSelection = selection; - switch (event.getReaction().getReactionEmote().getName()) { - case UP -> { - if (newSelection > 1) - newSelection--; - else if (loop) - newSelection = choices.size(); - } - case DOWN -> { - if (newSelection < choices.size()) - newSelection++; - else if (loop) - newSelection = 1; - } - case SELECT -> { - success.accept(message, selection); - if (singleSelectionMode) - return; - } - case CANCEL -> { - cancel.accept(message); + Emoji emoji = event.getReaction().getEmoji(); + if (emoji.equals(UP)) { + if (newSelection > 1) + newSelection--; + else if (loop) + newSelection = choices.size(); + } else if (emoji.equals(DOWN)) { + if (newSelection < choices.size()) + newSelection++; + else if (loop) + newSelection = 1; + } else if (emoji.equals(SELECT)) { + success.accept(message, selection); + if (singleSelectionMode) return; - } + } else if (emoji.equals(CANCEL)) { + cancel.accept(message); + return; } try { event.getReaction().removeReaction(event.getUser()).queue(); @@ -160,7 +157,7 @@ else if (loop) }, timeout, unit, () -> cancel.accept(message)); } - private Message render(int selection) { + private MessageEditData render(int selection) { StringBuilder sbuilder = new StringBuilder(); selection--; for (int i = 0; i < choices.size(); i++) @@ -168,10 +165,10 @@ private Message render(int selection) { sbuilder.append("\n").append(leftEnd).append(choices.get(i)).append(rightEnd); else sbuilder.append("\n").append(defaultLeft).append(choices.get(i)).append(defaultRight); - MessageBuilder mbuilder = new MessageBuilder(); + MessageEditBuilder mbuilder = new MessageEditBuilder(); String content = text.apply(++selection); if (content != null) - mbuilder.append(content); + mbuilder.setContent(content); return mbuilder.setEmbeds(new EmbedBuilder() .setColor(color.apply(selection)) .setDescription(sbuilder.toString()) diff --git a/src/main/java/hayashi/jdautilities/menu/Slideshow.java b/src/main/java/hayashi/jdautilities/menu/Slideshow.java index 59d8bf609..11b4133f3 100644 --- a/src/main/java/hayashi/jdautilities/menu/Slideshow.java +++ b/src/main/java/hayashi/jdautilities/menu/Slideshow.java @@ -26,17 +26,21 @@ import hayashi.jdautilities.commons.waiter.EventWaiter; import net.dv8tion.jda.api.EmbedBuilder; -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.Role; import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.entities.emoji.Emoji; +import net.dv8tion.jda.api.entities.emoji.EmojiUnion; import net.dv8tion.jda.api.events.message.GenericMessageEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent; import net.dv8tion.jda.api.exceptions.PermissionException; import net.dv8tion.jda.api.requests.RestAction; +import net.dv8tion.jda.api.utils.messages.MessageCreateData; +import net.dv8tion.jda.api.utils.messages.MessageEditBuilder; +import net.dv8tion.jda.api.utils.messages.MessageEditData; import net.dv8tion.jda.internal.utils.Checks; +import net.dv8tion.jda.api.entities.channel.middleman.*; public class Slideshow extends Menu { private final BiFunction color; @@ -47,11 +51,11 @@ public class Slideshow extends Menu { private final int bulkSkipNumber; private final String leftText, rightText; - public static final String BIG_LEFT = "\u23EA"; - public static final String LEFT = "\u25C0"; - public static final String STOP = "\u23F9"; - public static final String RIGHT = "\u25B6"; - public static final String BIG_RIGHT = "\u23E9"; + public static final Emoji BIG_LEFT = Emoji.fromUnicode("\u23EA"); + public static final Emoji LEFT = Emoji.fromUnicode("\u25C0"); + public static final Emoji STOP = Emoji.fromUnicode("\u23F9"); + public static final Emoji RIGHT = Emoji.fromUnicode("\u25B6"); + public static final Emoji BIG_RIGHT = Emoji.fromUnicode("\u23E9"); Slideshow(EventWaiter waiter, Set users, Set roles, long timeout, TimeUnit unit, BiFunction c, BiFunction t, @@ -89,8 +93,7 @@ public void paginate(MessageChannel channel, int pageNum) { pageNum = 1; else if (pageNum > urls.size()) pageNum = urls.size(); - Message msg = renderPage(pageNum); - initialize(channel.sendMessage(msg), pageNum); + initialize(channel.sendMessage(MessageCreateData.fromEditData(renderPage(pageNum))), pageNum); } public void paginate(Message message, int pageNum) { @@ -98,8 +101,7 @@ public void paginate(Message message, int pageNum) { pageNum = 1; else if (pageNum > urls.size()) pageNum = urls.size(); - Message msg = renderPage(pageNum); - initialize(message.editMessage(msg), pageNum); + initialize(message.editMessage(renderPage(pageNum)), pageNum); } private void initialize(RestAction action, int pageNum) { @@ -182,56 +184,52 @@ private void paginationWithoutTextInput(Message message, int pageNum) { private boolean checkReaction(MessageReactionAddEvent event, long messageId) { if (event.getMessageIdLong() != messageId) return false; - return switch (event.getReactionEmote().getName()) { - // LEFT, STOP, RIGHT, BIG_LEFT, BIG_RIGHT all fall-through to - // return if the User is valid or not. If none trip, this defaults - // and returns false. - case LEFT, STOP, RIGHT -> isValidUser(event.getUser(), event.isFromGuild() ? event.getGuild() : null); - case BIG_LEFT, BIG_RIGHT -> - bulkSkipNumber > 1 && isValidUser(event.getUser(), event.isFromGuild() ? event.getGuild() : null); - default -> false; - }; + EmojiUnion emoji = event.getEmoji();// LEFT, STOP, RIGHT, BIG_LEFT, BIG_RIGHT all fall-through to +// return if the User is valid or not. If none trip, this defaults +// and returns false. + if (emoji.equals(LEFT) || emoji.equals(STOP) || emoji.equals(RIGHT)) { + return isValidUser(event.getUser(), event.isFromGuild() ? event.getGuild() : null); + } + if (emoji.equals(BIG_LEFT) || emoji.equals(BIG_RIGHT)) { + return bulkSkipNumber > 1 && isValidUser(event.getUser(), event.isFromGuild() ? event.getGuild() : null); + } + return false; } // Private method that handles MessageReactionAddEvents private void handleMessageReactionAddAction(MessageReactionAddEvent event, Message message, int pageNum) { int newPageNum = pageNum; int pages = urls.size(); - switch (event.getReaction().getReactionEmote().getName()) { - case LEFT -> { - if (newPageNum == 1 && wrapPageEnds) - newPageNum = pages + 1; - if (newPageNum > 1) + Emoji emoji = event.getReaction().getEmoji(); + if (emoji.equals(LEFT)) { + if (newPageNum == 1 && wrapPageEnds) + newPageNum = pages + 1; + if (newPageNum > 1) + newPageNum--; + } else if (emoji.equals(RIGHT)) { + if (newPageNum == pages && wrapPageEnds) + newPageNum = 0; + if (newPageNum < pages) + newPageNum++; + } else if (emoji.equals(BIG_LEFT)) { + if (newPageNum > 1 || wrapPageEnds) { + for (int i = 1; (newPageNum > 1 || wrapPageEnds) && i < bulkSkipNumber; i++) { + if (newPageNum == 1 && wrapPageEnds) + newPageNum = pages + 1; newPageNum--; - } - case RIGHT -> { - if (newPageNum == pages && wrapPageEnds) - newPageNum = 0; - if (newPageNum < pages) - newPageNum++; - } - case BIG_LEFT -> { - if (newPageNum > 1 || wrapPageEnds) { - for (int i = 1; (newPageNum > 1 || wrapPageEnds) && i < bulkSkipNumber; i++) { - if (newPageNum == 1 && wrapPageEnds) - newPageNum = pages + 1; - newPageNum--; - } } } - case BIG_RIGHT -> { - if (newPageNum < pages || wrapPageEnds) { - for (int i = 1; (newPageNum < pages || wrapPageEnds) && i < bulkSkipNumber; i++) { - if (newPageNum == pages && wrapPageEnds) - newPageNum = 0; - newPageNum++; - } + } else if (emoji.equals(BIG_RIGHT)) { + if (newPageNum < pages || wrapPageEnds) { + for (int i = 1; (newPageNum < pages || wrapPageEnds) && i < bulkSkipNumber; i++) { + if (newPageNum == pages && wrapPageEnds) + newPageNum = 0; + newPageNum++; } } - case STOP -> { - finalAction.accept(message); - return; - } + } else if (emoji.equals(STOP)) { + finalAction.accept(message); + return; } try { @@ -242,8 +240,8 @@ private void handleMessageReactionAddAction(MessageReactionAddEvent event, Messa message.editMessage(renderPage(newPageNum)).queue(m -> pagination(m, n)); } - private Message renderPage(int pageNum) { - MessageBuilder mbuilder = new MessageBuilder(); + private MessageEditData renderPage(int pageNum) { + MessageEditBuilder mbuilder = new MessageEditBuilder(); EmbedBuilder ebuilder = new EmbedBuilder(); ebuilder.setImage(urls.get(pageNum - 1)); ebuilder.setColor(color.apply(pageNum, urls.size())); @@ -252,7 +250,7 @@ private Message renderPage(int pageNum) { ebuilder.setFooter("Image " + pageNum + "/" + urls.size(), null); mbuilder.setEmbeds(ebuilder.build()); if (text != null) - mbuilder.append(text.apply(pageNum, urls.size())); + mbuilder.setContent(text.apply(pageNum, urls.size())); return mbuilder.build(); } diff --git a/src/main/java/hayashi/raiko/ChatBot.java b/src/main/java/hayashi/raiko/ChatBot.java index f54a2a0c0..ee6904ee0 100644 --- a/src/main/java/hayashi/raiko/ChatBot.java +++ b/src/main/java/hayashi/raiko/ChatBot.java @@ -27,7 +27,7 @@ public String chat(String s) { try { String reply = (new JSONObject(client.newCall(new Request.Builder() .url("https://api.openai.com/v1/chat/completions") - .post(RequestBody.create(mediaType, jsonhead + "]}")) + .post(RequestBody.create(jsonhead + "]}",mediaType)) .addHeader("Authorization", "Bearer " + apiKey) .addHeader("Content-Type", "application/json") .build()) diff --git a/src/main/java/hayashi/raiko/Listener.java b/src/main/java/hayashi/raiko/Listener.java index a61884f45..df6b32ed1 100644 --- a/src/main/java/hayashi/raiko/Listener.java +++ b/src/main/java/hayashi/raiko/Listener.java @@ -17,12 +17,11 @@ import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.Guild; -import net.dv8tion.jda.api.entities.VoiceChannel; -import net.dv8tion.jda.api.events.ReadyEvent; -import net.dv8tion.jda.api.events.ShutdownEvent; +import net.dv8tion.jda.api.entities.channel.concrete.*; +import net.dv8tion.jda.api.events.session.*; import net.dv8tion.jda.api.events.guild.GuildJoinEvent; import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent; -import net.dv8tion.jda.api.events.message.guild.GuildMessageDeleteEvent; +import net.dv8tion.jda.api.events.message.MessageDeleteEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; @@ -54,7 +53,7 @@ public void onReady(ReadyEvent event) { } @Override - public void onGuildMessageDelete(GuildMessageDeleteEvent event) { + public void onMessageDelete(MessageDeleteEvent event) { bot.getNowplayingHandler().onMessageDelete(event.getGuild(), event.getMessageIdLong()); } diff --git a/src/main/java/hayashi/raiko/Raiko.java b/src/main/java/hayashi/raiko/Raiko.java index ba9fb6105..bce9ec406 100644 --- a/src/main/java/hayashi/raiko/Raiko.java +++ b/src/main/java/hayashi/raiko/Raiko.java @@ -29,7 +29,6 @@ import java.awt.Color; import java.util.Arrays; -import javax.security.auth.login.LoginException; import hayashi.raiko.commands.admin.PrefixCmd; import hayashi.raiko.commands.admin.SettcCmd; @@ -44,10 +43,11 @@ public class Raiko { public final static Logger LOG = LoggerFactory.getLogger(Raiko.class); - public final static Permission[] RECOMMENDED_PERMS = {Permission.MESSAGE_READ, Permission.MESSAGE_WRITE, Permission.MESSAGE_HISTORY, Permission.MESSAGE_ADD_REACTION, + public final static Permission[] RECOMMENDED_PERMS = {Permission.VIEW_CHANNEL, Permission.MESSAGE_SEND, Permission.MESSAGE_HISTORY, Permission.MESSAGE_ADD_REACTION, Permission.MESSAGE_EMBED_LINKS, Permission.MESSAGE_ATTACH_FILES, Permission.MESSAGE_MANAGE, Permission.MESSAGE_EXT_EMOJI, Permission.MANAGE_CHANNEL, Permission.VOICE_CONNECT, Permission.VOICE_SPEAK, Permission.NICKNAME_CHANGE}; - public final static GatewayIntent[] INTENTS = {GatewayIntent.DIRECT_MESSAGES, GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_MESSAGE_REACTIONS, GatewayIntent.GUILD_VOICE_STATES}; + public final static GatewayIntent[] INTENTS = {GatewayIntent.DIRECT_MESSAGES, GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_MESSAGE_REACTIONS, + GatewayIntent.GUILD_VOICE_STATES, GatewayIntent.MESSAGE_CONTENT, GatewayIntent.GUILD_EMOJIS_AND_STICKERS, GatewayIntent.SCHEDULED_EVENTS}; public static void main(String[] args) { if (args.length > 0 && "generate-config".equalsIgnoreCase(args[0])) { @@ -158,7 +158,7 @@ else if ("none".equalsIgnoreCase(config.getGame().getName())) { try { JDA jda = JDABuilder.create(config.getToken(), Arrays.asList(INTENTS)) .enableCache(CacheFlag.MEMBER_OVERRIDES, CacheFlag.VOICE_STATE) - .disableCache(CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS, CacheFlag.EMOTE, CacheFlag.ONLINE_STATUS) + .disableCache(CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS, CacheFlag.EMOJI, CacheFlag.ONLINE_STATUS) .setActivity(nogame ? null : Activity.playing("loading...")) .setStatus(config.getStatus() == OnlineStatus.INVISIBLE || config.getStatus() == OnlineStatus.OFFLINE ? OnlineStatus.INVISIBLE : OnlineStatus.DO_NOT_DISTURB) @@ -166,11 +166,11 @@ else if ("none".equalsIgnoreCase(config.getGame().getName())) { .setBulkDeleteSplittingEnabled(true) .build(); bot.setJDA(jda); - } catch (LoginException ex) { - prompt.alert(Prompt.Level.ERROR, "Raiko", ex + "\nPlease make sure you are " - + "editing the correct config.txt file, and that you have used the " - + "correct token (not the 'secret'!)\nConfig Location: " + config.getConfigLocation()); - System.exit(1); +// } catch (LoginException ex) { +// prompt.alert(Prompt.Level.ERROR, "Raiko", ex + "\nPlease make sure you are " +// + "editing the correct config.txt file, and that you have used the " +// + "correct token (not the 'secret'!)\nConfig Location: " + config.getConfigLocation()); +// System.exit(1); } catch (IllegalArgumentException ex) { prompt.alert(Prompt.Level.ERROR, "Raiko", "Some aspect of the configuration is " + "invalid: " + ex + "\nConfig Location: " + config.getConfigLocation()); diff --git a/src/main/java/hayashi/raiko/audio/AudioHandler.java b/src/main/java/hayashi/raiko/audio/AudioHandler.java index cac9eba32..6ba01d7c4 100644 --- a/src/main/java/hayashi/raiko/audio/AudioHandler.java +++ b/src/main/java/hayashi/raiko/audio/AudioHandler.java @@ -34,11 +34,11 @@ import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.JDA; -import net.dv8tion.jda.api.MessageBuilder; import net.dv8tion.jda.api.audio.AudioSendHandler; import net.dv8tion.jda.api.entities.Guild; -import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.utils.messages.MessageEditBuilder; +import net.dv8tion.jda.api.utils.messages.MessageEditData; public class AudioHandler extends AudioEventAdapter implements AudioSendHandler { public final static String PLAY_EMOJI = "\u25B6"; // ▶ @@ -85,7 +85,7 @@ public void stopAndClear() { } public boolean isMusicPlaying(JDA jda) { - return guild(jda).getSelfMember().getVoiceState().inVoiceChannel() && audioPlayer.getPlayingTrack() != null; + return guild(jda).getSelfMember().getVoiceState().inAudioChannel() && audioPlayer.getPlayingTrack() != null; } public AudioPlayer getPlayer() { @@ -158,13 +158,13 @@ public void onTrackStart(AudioPlayer player, AudioTrack track) { // Formatting - public Message getNowPlaying(JDA jda) { + public MessageEditData getNowPlaying(JDA jda) { if (!isMusicPlaying(jda)) return null; Guild guild = guild(jda); AudioTrack track = audioPlayer.getPlayingTrack(); - MessageBuilder mb = new MessageBuilder(); - mb.append(FormatUtil.filter(manager.getBot().getConfig().getSuccess() + " **Now Playing in " + guild.getSelfMember().getVoiceState().getChannel().getAsMention() + "...**")); + MessageEditBuilder mb = new MessageEditBuilder(); + mb.setContent(FormatUtil.filter(manager.getBot().getConfig().getSuccess() + " **Now Playing in " + guild.getSelfMember().getVoiceState().getChannel().getAsMention() + "...**")); EmbedBuilder eb = new EmbedBuilder(); eb.setColor(guild.getSelfMember().getColor()); RequestMetadata rm = getRequestMetadata(); @@ -195,9 +195,9 @@ public Message getNowPlaying(JDA jda) { return mb.setEmbeds(eb.build()).build(); } - public Message getNoMusicPlaying(JDA jda) { + public MessageEditData getNoMusicPlaying(JDA jda) { Guild guild = guild(jda); - return new MessageBuilder() + return new MessageEditBuilder() .setContent(FormatUtil.filter(manager.getBot().getConfig().getSuccess() + " **Now Playing...**")) .setEmbeds(new EmbedBuilder() .setTitle("No music playing") diff --git a/src/main/java/hayashi/raiko/audio/NowplayingHandler.java b/src/main/java/hayashi/raiko/audio/NowplayingHandler.java index 5e4048aa3..7fd859999 100644 --- a/src/main/java/hayashi/raiko/audio/NowplayingHandler.java +++ b/src/main/java/hayashi/raiko/audio/NowplayingHandler.java @@ -28,9 +28,10 @@ import net.dv8tion.jda.api.entities.Activity; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.channel.concrete.*; import net.dv8tion.jda.api.exceptions.PermissionException; import net.dv8tion.jda.api.exceptions.RateLimitedException; +import net.dv8tion.jda.api.utils.messages.MessageEditData; public class NowplayingHandler { private final Bot bot; @@ -47,7 +48,7 @@ public void init() { } public void setLastNPMessage(Message m) { - lastNP.put(m.getGuild().getIdLong(), new Pair<>(m.getTextChannel().getIdLong(), m.getIdLong())); + lastNP.put(m.getGuild().getIdLong(), new Pair<>(m.getChannel().asTextChannel().getIdLong(), m.getIdLong())); } public void clearLastNPMessage(Guild guild) { @@ -70,7 +71,7 @@ private void updateAll() { continue; } AudioHandler handler = (AudioHandler)guild.getAudioManager().getSendingHandler(); - Message msg = handler.getNowPlaying(bot.getJDA()); + MessageEditData msg = handler.getNowPlaying(bot.getJDA()); if(msg==null) { msg = handler.getNoMusicPlaying(bot.getJDA()); toRemove.add(guildId); @@ -115,7 +116,7 @@ else if(topic.contains("\u200B")) public void onTrackUpdate(long guildId, AudioTrack track, AudioHandler handler) { // update bot status if applicable if(bot.getConfig().getSongInStatus()) { - if(track!=null && bot.getJDA().getGuilds().stream().filter(g -> g.getSelfMember().getVoiceState().inVoiceChannel()).count()<=1) + if(track!=null && bot.getJDA().getGuilds().stream().filter(g -> g.getSelfMember().getVoiceState().inAudioChannel()).count()<=1) bot.getJDA().getPresence().setActivity(Activity.listening(track.getInfo().title)); else bot.resetGame(); diff --git a/src/main/java/hayashi/raiko/commands/MusicCommand.java b/src/main/java/hayashi/raiko/commands/MusicCommand.java index 356e51f5f..c1c388110 100644 --- a/src/main/java/hayashi/raiko/commands/MusicCommand.java +++ b/src/main/java/hayashi/raiko/commands/MusicCommand.java @@ -21,8 +21,7 @@ import hayashi.raiko.settings.Settings; import hayashi.raiko.audio.AudioHandler; import net.dv8tion.jda.api.entities.GuildVoiceState; -import net.dv8tion.jda.api.entities.TextChannel; -import net.dv8tion.jda.api.entities.VoiceChannel; +import net.dv8tion.jda.api.entities.channel.concrete.*; import net.dv8tion.jda.api.exceptions.PermissionException; public abstract class MusicCommand extends Command { @@ -52,11 +51,14 @@ protected void execute(CommandEvent event) { return; } if (beListening) { - VoiceChannel current = event.getGuild().getSelfMember().getVoiceState().getChannel(); - if (current == null) + VoiceChannel current; + try { + current = event.getGuild().getSelfMember().getVoiceState().getChannel().asVoiceChannel(); + } catch (Exception ex) { current = settings.getVoiceChannel(event.getGuild()); + } GuildVoiceState userState = event.getMember().getVoiceState(); - if (!userState.inVoiceChannel() || userState.isDeafened() || (current != null && !userState.getChannel().equals(current))) { + if (!userState.inAudioChannel() || userState.isDeafened() || (current != null && !userState.getChannel().equals(current))) { event.replyError("You must be listening in " + (current == null ? "a voice channel" : current.getAsMention()) + " to use that!"); return; } @@ -67,7 +69,7 @@ protected void execute(CommandEvent event) { return; } - if (!event.getGuild().getSelfMember().getVoiceState().inVoiceChannel()) { + if (!event.getGuild().getSelfMember().getVoiceState().inAudioChannel()) { try { event.getGuild().getAudioManager().openAudioConnection(userState.getChannel()); } catch (PermissionException ex) { diff --git a/src/main/java/hayashi/raiko/commands/admin/SettcCmd.java b/src/main/java/hayashi/raiko/commands/admin/SettcCmd.java index d2a5ac320..89760f42a 100644 --- a/src/main/java/hayashi/raiko/commands/admin/SettcCmd.java +++ b/src/main/java/hayashi/raiko/commands/admin/SettcCmd.java @@ -23,7 +23,7 @@ import hayashi.raiko.commands.AdminCommand; import hayashi.raiko.settings.Settings; import hayashi.raiko.utils.FormatUtil; -import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.channel.concrete.*; public class SettcCmd extends AdminCommand { public SettcCmd(Bot bot) { diff --git a/src/main/java/hayashi/raiko/commands/admin/SetvcCmd.java b/src/main/java/hayashi/raiko/commands/admin/SetvcCmd.java index 6dd5293d0..273af150d 100644 --- a/src/main/java/hayashi/raiko/commands/admin/SetvcCmd.java +++ b/src/main/java/hayashi/raiko/commands/admin/SetvcCmd.java @@ -23,7 +23,7 @@ import hayashi.raiko.commands.AdminCommand; import hayashi.raiko.settings.Settings; import hayashi.raiko.utils.FormatUtil; -import net.dv8tion.jda.api.entities.VoiceChannel; +import net.dv8tion.jda.api.entities.channel.concrete.*; public class SetvcCmd extends AdminCommand { public SetvcCmd(Bot bot) { diff --git a/src/main/java/hayashi/raiko/commands/general/AboutCommand.java b/src/main/java/hayashi/raiko/commands/general/AboutCommand.java index becde8791..a02ac3528 100644 --- a/src/main/java/hayashi/raiko/commands/general/AboutCommand.java +++ b/src/main/java/hayashi/raiko/commands/general/AboutCommand.java @@ -6,7 +6,7 @@ import net.dv8tion.jda.api.JDAInfo; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.ApplicationInfo; -import net.dv8tion.jda.api.entities.ChannelType; +import net.dv8tion.jda.api.entities.channel.ChannelType; import org.slf4j.LoggerFactory; import java.awt.*; diff --git a/src/main/java/hayashi/raiko/commands/general/SettingsCmd.java b/src/main/java/hayashi/raiko/commands/general/SettingsCmd.java index 0dd27bc0a..27d0832bb 100644 --- a/src/main/java/hayashi/raiko/commands/general/SettingsCmd.java +++ b/src/main/java/hayashi/raiko/commands/general/SettingsCmd.java @@ -22,9 +22,8 @@ import hayashi.raiko.settings.Settings; import hayashi.raiko.utils.FormatUtil; import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.MessageBuilder; -import net.dv8tion.jda.api.entities.TextChannel; -import net.dv8tion.jda.api.entities.VoiceChannel; +import net.dv8tion.jda.api.entities.channel.concrete.*; +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; public class SettingsCmd extends Command { private final static String EMOJI = "\uD83C\uDFA7"; // 🎧 @@ -41,10 +40,10 @@ protected void execute(CommandEvent event) { Settings s = event.getClient().getSettingsFor(event.getGuild()); TextChannel tchan = s.getTextChannel(event.getGuild()); VoiceChannel vchan = s.getVoiceChannel(event.getGuild()); - event.getChannel().sendMessage(new MessageBuilder() - .append(EMOJI + " **") - .append(FormatUtil.filter(event.getSelfUser().getName())) - .append("** settings:") + event.getChannel().sendMessage(new MessageCreateBuilder() + .addContent(EMOJI + " **") + .addContent(FormatUtil.filter(event.getSelfUser().getName())) + .addContent("** settings:") .setEmbeds(new EmbedBuilder() .setColor(event.getSelfMember().getColor()) .setDescription("Text Channel: " + (tchan == null ? "Any" : "**#" + tchan.getName() + "**") @@ -56,7 +55,7 @@ protected void execute(CommandEvent event) { + "\nDefault Playlist: " + (s.getDefaultPlaylist() == null ? "None" : "**" + s.getDefaultPlaylist() + "**") ) .setFooter(event.getJDA().getGuilds().size() + " servers | " - + event.getJDA().getGuilds().stream().filter(g -> g.getSelfMember().getVoiceState().inVoiceChannel()).count() + + event.getJDA().getGuilds().stream().filter(g -> g.getSelfMember().getVoiceState().inAudioChannel()).count() + " audio connections", null).build()).build()).queue(); } diff --git a/src/main/java/hayashi/raiko/commands/music/NowplayingCmd.java b/src/main/java/hayashi/raiko/commands/music/NowplayingCmd.java index 8605c9677..a0ff69503 100644 --- a/src/main/java/hayashi/raiko/commands/music/NowplayingCmd.java +++ b/src/main/java/hayashi/raiko/commands/music/NowplayingCmd.java @@ -20,7 +20,6 @@ import hayashi.raiko.audio.AudioHandler; import hayashi.raiko.commands.MusicCommand; import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.Message; public class NowplayingCmd extends MusicCommand { public NowplayingCmd(Bot bot) { @@ -34,10 +33,10 @@ public NowplayingCmd(Bot bot) { @Override public void doCommand(CommandEvent event) { AudioHandler handler = (AudioHandler) event.getGuild().getAudioManager().getSendingHandler(); - Message m = handler.getNowPlaying(event.getJDA()); + String m = handler.getNowPlaying(event.getJDA()).getContent(); if (m != null) event.reply(m, msg -> bot.getNowplayingHandler().setLastNPMessage(msg)); - event.reply(handler.getNoMusicPlaying(event.getJDA())); + event.reply(handler.getNoMusicPlaying(event.getJDA()).getContent()); bot.getNowplayingHandler().clearLastNPMessage(event.getGuild()); } } diff --git a/src/main/java/hayashi/raiko/commands/music/PlayCmd.java b/src/main/java/hayashi/raiko/commands/music/PlayCmd.java index d8cae7306..ae6a934c8 100644 --- a/src/main/java/hayashi/raiko/commands/music/PlayCmd.java +++ b/src/main/java/hayashi/raiko/commands/music/PlayCmd.java @@ -35,11 +35,12 @@ import hayashi.raiko.playlist.PlaylistLoader; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.exceptions.PermissionException; public class PlayCmd extends MusicCommand { - private final static String LOAD = "\uD83D\uDCE5"; // 📥 - private final static String CANCEL = "\uD83D\uDEAB"; // 🚫 + private final static Emoji LOAD = Emoji.fromUnicode("\uD83D\uDCE5"); // 📥 + private final static Emoji CANCEL = Emoji.fromUnicode("\uD83D\uDEAB"); // 🚫 private final String loadingEmoji; @@ -110,7 +111,7 @@ private void loadSingle(AudioTrack track, AudioPlaylist playlist) { .setEventWaiter(bot.getWaiter()) .setTimeout(30, TimeUnit.SECONDS) .setAction(re -> { - if (re.getName().equals(LOAD)) + if (re.equals(LOAD)) m.editMessage(addMsg + "\n" + event.getClient().getSuccess() + " Loaded **" + loadPlaylist(playlist, track) + "** additional tracks!").queue(); else m.editMessage(addMsg).queue(); diff --git a/src/main/java/hayashi/raiko/commands/music/QueueCmd.java b/src/main/java/hayashi/raiko/commands/music/QueueCmd.java index 58220afac..cb9cfe468 100644 --- a/src/main/java/hayashi/raiko/commands/music/QueueCmd.java +++ b/src/main/java/hayashi/raiko/commands/music/QueueCmd.java @@ -28,10 +28,10 @@ import hayashi.raiko.settings.RepeatMode; import hayashi.raiko.settings.Settings; import hayashi.raiko.utils.FormatUtil; -import net.dv8tion.jda.api.MessageBuilder; import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.exceptions.PermissionException; +import net.dv8tion.jda.api.utils.messages.MessageEditBuilder; +import net.dv8tion.jda.api.utils.messages.MessageEditData; public class QueueCmd extends MusicCommand { private final Paginator.Builder builder; @@ -69,10 +69,11 @@ public void doCommand(CommandEvent event) { AudioHandler ah = (AudioHandler) event.getGuild().getAudioManager().getSendingHandler(); Deque deque = ah.getQueue().getDeque(); if (deque.isEmpty()) { - Message nowp = ah.getNowPlaying(event.getJDA()); - event.reply(new MessageBuilder() + MessageEditData nowp = ah.getNowPlaying(event.getJDA()); + event.reply(new MessageEditBuilder() .setContent(event.getClient().getWarning() + " There is no music in the queue!") - .setEmbeds((nowp == null ? ah.getNoMusicPlaying(event.getJDA()) : nowp).getEmbeds().get(0)).build(), m -> { + .setEmbeds((nowp == null ? ah.getNoMusicPlaying(event.getJDA()) : nowp).getEmbeds().get(0)).build().getContent() + , m -> { if (nowp != null) bot.getNowplayingHandler().setLastNPMessage(m); }); diff --git a/src/main/java/hayashi/raiko/commands/music/ShuffleCmd.java b/src/main/java/hayashi/raiko/commands/music/ShuffleCmd.java index 7c2925fcb..4d9a561da 100644 --- a/src/main/java/hayashi/raiko/commands/music/ShuffleCmd.java +++ b/src/main/java/hayashi/raiko/commands/music/ShuffleCmd.java @@ -43,8 +43,10 @@ public void doCommand(CommandEvent event) { } else { if ((s = handler.getQueue().size()) < 2) event.replyWarning("There aren't enough songs in the queue!"); - else + else { + handler.getQueue().shuffle(); event.replySuccess("You successfully shuffled all " + s + " entries."); + } } } diff --git a/src/main/java/hayashi/raiko/commands/owner/DebugCmd.java b/src/main/java/hayashi/raiko/commands/owner/DebugCmd.java index 775d49ab3..56a7130f9 100644 --- a/src/main/java/hayashi/raiko/commands/owner/DebugCmd.java +++ b/src/main/java/hayashi/raiko/commands/owner/DebugCmd.java @@ -21,7 +21,8 @@ import com.sedmelluq.discord.lavaplayer.tools.PlayerLibrary; import net.dv8tion.jda.api.JDAInfo; import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.ChannelType; +import net.dv8tion.jda.api.entities.channel.ChannelType; +import net.dv8tion.jda.api.utils.FileUpload; public class DebugCmd extends OwnerCommand { private final static String[] PROPERTIES = {"java.version", "java.vm.name", "java.vm.specification.version", @@ -69,7 +70,7 @@ protected void execute(CommandEvent event) { if (event.isFromType(ChannelType.PRIVATE) || event.getSelfMember().hasPermission(event.getTextChannel(), Permission.MESSAGE_ATTACH_FILES)) - event.getChannel().sendFile(sb.toString().getBytes(), "debug_information.txt").queue(); + event.getChannel().sendFiles(FileUpload.fromData(sb.toString().getBytes(), "debug_information.txt")).queue(); else event.reply("Debug Information: " + sb); } diff --git a/src/main/java/hayashi/raiko/settings/Settings.java b/src/main/java/hayashi/raiko/settings/Settings.java index 623917478..dc39132eb 100644 --- a/src/main/java/hayashi/raiko/settings/Settings.java +++ b/src/main/java/hayashi/raiko/settings/Settings.java @@ -21,8 +21,7 @@ import java.util.Collections; import net.dv8tion.jda.api.entities.Guild; -import net.dv8tion.jda.api.entities.TextChannel; -import net.dv8tion.jda.api.entities.VoiceChannel; +import net.dv8tion.jda.api.entities.channel.concrete.*; public class Settings implements GuildSettingsProvider { private final SettingsManager manager; diff --git a/src/main/java/hayashi/raiko/utils/FormatUtil.java b/src/main/java/hayashi/raiko/utils/FormatUtil.java index 93f5c6379..cb6792d34 100644 --- a/src/main/java/hayashi/raiko/utils/FormatUtil.java +++ b/src/main/java/hayashi/raiko/utils/FormatUtil.java @@ -18,8 +18,7 @@ import java.util.List; import net.dv8tion.jda.api.entities.Role; -import net.dv8tion.jda.api.entities.TextChannel; -import net.dv8tion.jda.api.entities.VoiceChannel; +import net.dv8tion.jda.api.entities.channel.concrete.*; public class FormatUtil { diff --git a/src/test/java/hayashi/raiko/CTest.java b/src/test/java/hayashi/raiko/CTest.java index f17f83dbb..5782dee28 100644 --- a/src/test/java/hayashi/raiko/CTest.java +++ b/src/test/java/hayashi/raiko/CTest.java @@ -31,7 +31,7 @@ public static void main(String[] args) throws IOException { try { String reply = (new JSONObject(client.newCall(new Request.Builder() .url("https://api.openai.com/v1/chat/completions") - .post(RequestBody.create(mediaType, jsonhead + "]}")) + .post(RequestBody.create( jsonhead + "]}",mediaType)) .addHeader("Authorization", "Bearer " + apiKey) .addHeader("Content-Type", "application/json") .build())