From 8783ab438b55c2d1334198bd993d364074467bc7 Mon Sep 17 00:00:00 2001 From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com> Date: Tue, 16 Apr 2024 15:07:04 -0400 Subject: [PATCH] 5.0.0 --- build.gradle.kts | 4 +- .../helpbot/bot/HelpBotInstance.java | 10 +- .../codeblock/AbstractSingleQueryCommand.java | 16 +- .../command/impl/codeblock/CodeCommand.java | 5 +- .../command/impl/codeblock/RawCommand.java | 2 +- .../command/impl/codeblock/TagsCommand.java | 5 +- .../impl/other/dev/FetchDataCommand.java | 164 ++++++++---------- .../impl/other/dumps/ActionDumpCommand.java | 3 +- .../impl/other/dumps/ImageDumpCommand.java | 3 +- .../command/impl/other/fun/NbsCommand.java | 8 +- .../impl/other/fun/SamQuotesCommand.java | 3 +- .../impl/other/mod/ChannelMuteCommand.java | 3 +- .../command/impl/other/mod/PurgeCommand.java | 6 +- .../command/impl/other/mod/UnmuteCommand.java | 1 + .../other/util/AbstractFileListCommand.java | 3 +- .../command/impl/other/util/PollCommand.java | 3 +- .../command/impl/stats/BoostersCommand.java | 6 +- .../stats/graph/AbstractGraphCommand.java | 3 +- .../impl/stats/individualized/CpCommand.java | 5 +- .../stats/individualized/HistoryCommand.java | 11 +- .../stats/individualized/ProfileCommand.java | 2 +- .../impl/stats/metrics/JoinDataCommand.java | 2 +- .../impl/stats/plot/AbstractPlotCommand.java | 3 +- .../impl/stats/plot/PlotVoteGraphCommand.java | 5 +- .../support/AbstractSessionLogCommand.java | 3 +- .../stats/support/DailySessionsCommand.java | 5 +- .../stats/support/ExcusedStaffCommand.java | 2 +- .../support/FindSupporteeNamesCommand.java | 2 +- .../impl/stats/support/StatsGraphCommand.java | 5 +- .../bot/command/reply/ReplyHandler.java | 14 +- .../helpbot/bot/config/Config.java | 4 + .../helpbot/bot/events/ButtonEvent.java | 4 +- .../helpbot/bot/events/CommandEvent.java | 6 +- .../helpbot/bot/events/GuildJoinEvent.java | 4 +- .../helpbot/bot/events/MessageEditEvent.java | 5 +- .../helpbot/bot/events/MessageEvent.java | 9 +- .../helpbot/bot/events/ReadyEvent.java | 7 +- .../helpbot/bot/restart/RestartHandler.java | 2 +- .../df/codeinfo/viewables/BasicReaction.java | 49 ++---- .../viewables/constants/CodeBlockEnum.java | 6 +- .../embeds/CodeActionEmbedBuilder.java | 6 +- .../viewables/embeds/CodeDisplayBuilder.java | 3 +- .../diamondfire/helpbot/df/ranks/Rank.java | 8 +- .../sys/interaction/button/ButtonHandler.java | 13 +- .../sys/message/acceptors/TagAcceptor.java | 2 +- .../sys/message/acceptors/VerifyAcceptor.java | 3 +- .../sys/multiselector/MultiSelector.java | 9 +- .../sys/rolereact/RoleReactListener.java | 20 +-- .../com/diamondfire/helpbot/sys/tag/Tag.java | 1 + .../helpbot/sys/tag/TagHandler.java | 4 + .../helpbot/sys/tasks/LoopingTask.java | 2 +- .../helpbot/sys/tasks/TaskRegistry.java | 2 +- .../sys/tasks/impl/GraphChannelTask.java | 7 +- .../sys/tasks/impl/MuteExpireTask.java | 5 +- .../sys/tasks/impl/SupportUnexcuseTask.java | 2 +- .../util/PlainComponentSerializer.java | 9 +- .../com/diamondfire/helpbot/util/Util.java | 2 +- 57 files changed, 242 insertions(+), 259 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index eb98c31c..6bf3b888 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,14 +17,14 @@ repositories { } dependencies { - implementation("net.dv8tion:JDA:4.4.0_350") { + implementation ("net.dv8tion:JDA:5.0.0-beta.20") { exclude(module = "opus-java") } implementation("club.minnced:discord-webhooks:0.5.8") implementation("ch.qos.logback:logback-classic:1.2.5") implementation("com.google.code.gson:gson:2.8.6") - implementation("com.github.Steveice10:MCProtocolLib:c5e4b66") + implementation ("com.github.Steveice10:MCProtocolLib:c5e4b66") implementation("mysql:mysql-connector-java:5.1.13") implementation("org.codehaus.groovy:groovy-jsr223:3.0.8") } diff --git a/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java b/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java index e85db715..9c6bb118 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java +++ b/src/main/java/com/diamondfire/helpbot/bot/HelpBotInstance.java @@ -51,12 +51,12 @@ public static void initialize() throws LoginException { new SearchCommand(), new TagsCommand(), // others - new CowsayCommand(), + //new CowsayCommand(), new MimicCommand(), - new FetchDataCommand(), + //new FetchDataCommand(), new InfoCommand(), new EvalCommand(), - new GarfieldCommand(), + //new GarfieldCommand(), new HelpCommand(), new RestartCommand(), new ActionDumpCommand(), @@ -79,7 +79,7 @@ public static void initialize() throws LoginException { new VerifyCommand(), // new PollCommand(), - Unused new IdeaCommand(), - new StoreCommand(), + // new StoreCommand(), // new ChannelMuteCommand(), - not finished // statsbot new StatsCommand(), @@ -134,7 +134,7 @@ public static void initialize() throws LoginException { ); JDABuilder builder = JDABuilder.createDefault(config.getToken()) - .enableIntents(GatewayIntent.GUILD_MEMBERS) + .enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.MESSAGE_CONTENT, GatewayIntent.DIRECT_MESSAGES, GatewayIntent.DIRECT_MESSAGE_REACTIONS) .setStatus(OnlineStatus.ONLINE) .setMemberCachePolicy(MemberCachePolicy.NONE) .setActivity(Activity.watching("for " + getConfig().getPrefix() + "help")) diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/AbstractSingleQueryCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/AbstractSingleQueryCommand.java index df2e4856..f512dee2 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/AbstractSingleQueryCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/AbstractSingleQueryCommand.java @@ -13,7 +13,9 @@ import com.diamondfire.helpbot.sys.interaction.button.ButtonHandler; import com.diamondfire.helpbot.util.*; import net.dv8tion.jda.api.entities.*; -import net.dv8tion.jda.api.interactions.components.Button; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.entities.emoji.Emoji; +import net.dv8tion.jda.api.interactions.components.buttons.Button; import java.util.*; import java.util.function.BiConsumer; @@ -46,7 +48,7 @@ public static void sendMultipleMessage(List actions, TextChannel cha for (Map.Entry reaction : referenceData.getEnum().getEmbedBuilder().generateDupeEmojis(actions).entrySet()) { Button button = Button.secondary(reaction.getKey().toString(), reaction.getValue().getName()); - buttons.add(button.withEmoji(Emoji.fromEmote(reaction.getKey().getEmote()))); + buttons.add(button.withEmoji(Emoji.fromCustom(reaction.getKey().getEmote()))); buttonMap.put(button.getId(), reaction.getValue()); } } else { @@ -54,18 +56,18 @@ public static void sendMultipleMessage(List actions, TextChannel cha long emoji = data.getEnum().getEmoji(); Button button = Button.secondary(String.valueOf(data.getEnum().getEmoji()), data.getName()); - buttons.add(button.withEmoji(Emoji.fromEmote(HelpBotInstance.getJda().getEmoteById(emoji)))); + buttons.add(button.withEmoji(HelpBotInstance.getJda().getEmojiById(emoji))); buttonMap.put(button.getId(), data); } } - channel.sendMessageEmbeds(preset.getEmbed().build()).setActionRows(Util.of(buttons)).queue((message) -> { + channel.sendMessageEmbeds(preset.getEmbed().build()).setActionRow(buttons).queue((message) -> { ButtonHandler.addListener(userToWait, message, (event) -> { message.delete().queue(); // when msg is deleted causes nullpointer when tries to remove reactions! FIX CodeObject object = buttonMap.get(event.getComponentId()); - onChosen.accept(object, message.getTextChannel()); + onChosen.accept(object, message.getChannel().asTextChannel()); }); }); @@ -118,9 +120,9 @@ protected void getData(CommandEvent event, BiConsumer o // If none, proceed. Else we need to special case that. if (sameActions.size() == 1) { - onChosen.accept(sameActions.get(0), event.getChannel()); + onChosen.accept(sameActions.get(0), event.getChannel().asTextChannel()); } else if (sameActions.size() > 1) { - sendMultipleMessage(sameActions, event.getChannel(), event.getMember().getIdLong(), onChosen); + sendMultipleMessage(sameActions, event.getChannel().asTextChannel(), event.getMember().getIdLong(), onChosen); } return; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/CodeCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/CodeCommand.java index 04ddd6b3..759baba5 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/CodeCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/CodeCommand.java @@ -6,7 +6,8 @@ import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes.CodeObject; import com.diamondfire.helpbot.util.Util; import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.utils.FileUpload; import java.io.File; import java.util.function.BiConsumer; @@ -21,7 +22,7 @@ public static void sendHelpMessage(T data, TextChannel ch if (customHead == null) { File actionIcon = Util.fetchMinecraftTextureFile(data.getItem().getMaterial().toUpperCase()); builder.setThumbnail("attachment://" + actionIcon.getName()); - channel.sendMessageEmbeds(builder.build()).addFile(actionIcon).queue(); + channel.sendMessageEmbeds(builder.build()).addFiles(FileUpload.fromData(actionIcon)).queue(); } else { builder.setThumbnail(customHead); channel.sendMessageEmbeds(builder.build()).queue(); diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/RawCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/RawCommand.java index 8f4c5bd7..75d5c4be 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/RawCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/RawCommand.java @@ -6,7 +6,7 @@ import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes.CodeObject; import com.diamondfire.helpbot.util.StringUtil; import com.google.gson.*; -import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import java.util.function.BiConsumer; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/TagsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/TagsCommand.java index ae3fc2d4..92f84dee 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/TagsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/codeblock/TagsCommand.java @@ -6,7 +6,8 @@ import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes.*; import com.diamondfire.helpbot.util.Util; import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.utils.FileUpload; import java.io.File; import java.util.function.BiConsumer; @@ -52,7 +53,7 @@ private static void sendTagMessage(CodeObject data, TextChannel channel) { if (customHead == null) { File actionIcon = Util.fetchMinecraftTextureFile(data.getItem().getMaterial().toUpperCase()); builder.setThumbnail("attachment://" + actionIcon.getName()); - channel.sendMessageEmbeds(builder.build()).addFile(actionIcon).queue(); + channel.sendMessageEmbeds(builder.build()).addFiles(FileUpload.fromData(actionIcon)).queue(); } else { builder.setThumbnail(customHead); channel.sendMessageEmbeds(builder.build()).queue(); diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/FetchDataCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/FetchDataCommand.java index 33d1a49a..d868e11e 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/FetchDataCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dev/FetchDataCommand.java @@ -13,28 +13,15 @@ import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.CodeDatabase; import com.diamondfire.helpbot.sys.externalfile.ExternalFileUtil; import com.diamondfire.helpbot.sys.externalfile.ExternalFiles; -import com.diamondfire.helpbot.util.PlainComponentSerializer; -import com.github.steveice10.mc.auth.exception.request.RequestException; -import com.github.steveice10.mc.auth.service.AuthenticationService; -import com.github.steveice10.mc.protocol.MinecraftProtocol; -import com.github.steveice10.mc.protocol.data.game.MessageType; -import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket; -import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket; -import com.github.steveice10.packetlib.event.session.PacketReceivedEvent; -import com.github.steveice10.packetlib.event.session.SessionAdapter; -import com.github.steveice10.packetlib.packet.Packet; -import com.github.steveice10.packetlib.tcp.TcpClientSession; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.utils.FileUpload; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; +import java.io.*; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; +import java.nio.file.*; +import java.util.*; import java.util.concurrent.CompletableFuture; @@ -74,7 +61,7 @@ public Permission getPermission() { public void run(CommandEvent event) { List flags = event.getArgument("flag"); if (flags == null) { - setup(event.getChannel()); + setup(event.getChannel().asTextChannel()); } else { boolean includeColors = false; boolean updateDb = true; @@ -85,7 +72,7 @@ public void run(CommandEvent event) { updateDb = false; } } - setup(event.getChannel(), includeColors, updateDb); + setup(event.getChannel().asTextChannel(), includeColors, updateDb); } } @@ -100,7 +87,6 @@ public void setup(TextChannel channel, boolean includeColors, boolean updateDb) builder.setDescription("Please wait a moment!"); Message sentMessage = channel.sendMessageEmbeds(builder.build()).complete(); - fetchData(sentMessage, includeColors).thenAccept((queue) -> { status(sentMessage, String.format("Data has been received, parsing %s lines...", queue.size())); @@ -134,7 +120,7 @@ public void setup(TextChannel channel, boolean includeColors, boolean updateDb) status(sentMessage, "Finished!"); } else { status(sentMessage, "Finished!"); - sentMessage.getChannel().sendFile(file).queue(); + sentMessage.getChannel().sendFiles(FileUpload.fromData(file)).queue(); } }).exceptionally((exception) -> { error(sentMessage, exception); @@ -145,77 +131,69 @@ public void setup(TextChannel channel, boolean includeColors, boolean updateDb) private CompletableFuture> fetchData(Message message, boolean includeColors) { CompletableFuture> completableFuture = new CompletableFuture<>(); - - AuthenticationService authService = new AuthenticationService(); - authService.setUsername(USERNAME); - authService.setPassword(PASSWORD); - try { - authService.login(); - } catch (RequestException e) { - e.printStackTrace(); - } - - MinecraftProtocol protocol = new MinecraftProtocol(authService.getSelectedProfile(), authService.getAccessToken()); - TcpClientSession client = new TcpClientSession("beta.mcdiamondfire.com", 25565, protocol); - - status(message, "Connecting to DiamondFire..."); - - client.connect(); - - client.addListener(new SessionAdapter() { - - boolean ready = false; - List queue = new ArrayList<>(); - - @Override - public void packetReceived(PacketReceivedEvent event) { - Packet packet = event.getPacket(); - - if (packet instanceof ServerJoinGamePacket) { - status(message, "Joined server!"); - try { - Thread.sleep(2000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - event.getSession().send(new ClientChatPacket("/chat none")); - event.getSession().send(new ClientChatPacket(includeColors ? "/dumpactioninfo -c" : "/dumpactioninfo")); - } - - if (packet instanceof ServerChatPacket) { - ServerChatPacket chatPacket = event.getPacket(); - String text = PlainComponentSerializer.INSTANCE.serialize(chatPacket.getMessage()); - - if (chatPacket.getType() == MessageType.NOTIFICATION) return; - - if (text.contains("Unknown command!")) { - completableFuture.completeExceptionally(new IllegalStateException("Command not found!")); - } - - if (text.startsWith("{")) { - status(message, "Receiving data..."); - ready = true; - } else if (text.startsWith("}")) { - client.disconnect("HelpBot data collection has concluded. "); - - if (queue.isEmpty()) { - completableFuture.completeExceptionally(new IllegalStateException("Failed to retrieve data")); - return; - } - - queue.add("}"); - completableFuture.complete(queue); - return; - } - - if (ready) { - queue.add(new String(text.getBytes(StandardCharsets.UTF_8))); - } - - } - } - }); - + +// System.out.println("Logging in..."); +// +// +// +// TcpClientSession client = new TcpClientSession("beta.mcdiamondfire.com", 25565, new MinecraftProtocol(MinecraftCodec.CODEC, auth.getSelectedProfile(), auth.getAccessToken())); +// +// status(message, "Connecting to DiamondFire..."); +// +// client.connect(); +// +// client.addListener(new SessionAdapter() { +// +// boolean ready = false; +// List queue = new ArrayList<>(); +// +// @Override +// public void packetReceived(Session session, Packet packet) { +// if (packet instanceof ClientboundLoginPacket) { +// status(message, "Joined server!"); +// try { +// Thread.sleep(2000); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// session.send(new ServerboundChatCommandPacket("/chat none", System.currentTimeMillis(), System.currentTimeMillis(), List.of(), 0, new BitSet())); +// session.send(new ServerboundChatCommandPacket(includeColors ? "/dumpactioninfo -c" : "/dumpactioninfo", System.currentTimeMillis(), System.currentTimeMillis(), List.of(), 0, new BitSet())); +// } +// +// if (packet instanceof ClientboundSystemChatPacket chatPacket) { +// String text = PlainComponentSerializer.INSTANCE.serialize(chatPacket.getContent()); +// +// if (chatPacket.isOverlay()) return; +// +// if (text.contains("Unknown command!")) { +// completableFuture.completeExceptionally(new IllegalStateException("Command not found!")); +// } +// +// if (text.startsWith("{")) { +// status(message, "Receiving data..."); +// ready = true; +// } else if (text.startsWith("}")) { +// client.disconnect("HelpBot data collection has concluded. "); +// +// if (queue.isEmpty()) { +// completableFuture.completeExceptionally(new IllegalStateException("Failed to retrieve data")); +// return; +// } +// +// queue.add("}"); +// completableFuture.complete(queue); +// return; +// } +// +// if (ready) { +// queue.add(new String(text.getBytes(StandardCharsets.UTF_8))); +// } +// +// } +// } +// +// }); + return completableFuture; } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/ActionDumpCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/ActionDumpCommand.java index 1e48bcd0..c617c6f6 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/ActionDumpCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/ActionDumpCommand.java @@ -6,6 +6,7 @@ import com.diamondfire.helpbot.bot.command.permissions.Permission; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.sys.externalfile.ExternalFiles; +import net.dv8tion.jda.api.utils.FileUpload; public class ActionDumpCommand extends Command { @@ -33,7 +34,7 @@ public Permission getPermission() { @Override public void run(CommandEvent event) { - event.getChannel().sendFile(ExternalFiles.DB).queue(); + event.getChannel().sendFiles(FileUpload.fromData(ExternalFiles.DB)).queue(); } } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/ImageDumpCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/ImageDumpCommand.java index 9500c7b2..045fa9a2 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/ImageDumpCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/dumps/ImageDumpCommand.java @@ -9,6 +9,7 @@ import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.sys.externalfile.ExternalFiles; import com.diamondfire.helpbot.util.IOUtil; +import net.dv8tion.jda.api.utils.FileUpload; import java.io.*; @@ -44,7 +45,7 @@ public void run(CommandEvent event) { event.getReplyHandler().replyA(builder).queue((msg) -> { try { File zip = IOUtil.zipFile(images.toPath(), "images.zip"); - event.getChannel().sendFile(zip).queue((fileMsg) -> { + event.getChannel().sendFiles(FileUpload.fromData(zip)).queue((fileMsg) -> { msg.delete().queue(); }); } catch (IOException e) { diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/NbsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/NbsCommand.java index 90772bb8..9688bc54 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/NbsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/NbsCommand.java @@ -10,6 +10,8 @@ import com.diamondfire.helpbot.util.nbs.*; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.*; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.utils.FileUpload; import java.awt.*; import java.io.*; @@ -42,7 +44,7 @@ public Permission getPermission() { @Override public void run(CommandEvent event) { - TextChannel channel = event.getChannel(); + TextChannel channel = event.getChannel().asTextChannel(); PresetBuilder attachNbsMsg = new PresetBuilder().withPreset(new InformativeReply(InformativeReplyType.ERROR,"You need to attach an nbs file!")); PresetBuilder errorMsg = new PresetBuilder().withPreset(new InformativeReply(InformativeReplyType.ERROR,"Something went wrong while generating!")); @@ -59,7 +61,7 @@ public void run(CommandEvent event) { File file = new File("input.nbs"); - + attachment.downloadToFile(file).thenAccept(downloadedFile -> { try { byte[] b64 = new NBSToTemplate(NBSDecoder.parse(file)).convert(); @@ -77,7 +79,7 @@ public void run(CommandEvent event) { .addField("Information","You can copy the command above and give it to yourself in singleplayer. Use toolbars to transfer it to Diamondfire. You will need a [Music Player](https://dfonline.dev/edit/?template=nbs) function to play this song!", false); - channel.sendFile(templateOutputfile).setEmbeds(embed.build()).queue(); + channel.sendFiles(FileUpload.fromData(templateOutputfile)).setEmbeds(embed.build()).queue(); file.deleteOnExit(); } catch (OutdatedNBSException | IOException e) { e.printStackTrace(); diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/SamQuotesCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/SamQuotesCommand.java index 8bfc9488..d21ec2d5 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/SamQuotesCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/fun/SamQuotesCommand.java @@ -11,6 +11,7 @@ import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.sys.externalfile.ExternalFiles; import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.utils.FileUpload; import javax.imageio.ImageIO; import java.awt.*; @@ -53,7 +54,7 @@ public void run(CommandEvent event) { builder.setImage("attachment://quote.png"); builder.setColor(new Color(87, 177, 71)); - event.getChannel().sendMessageEmbeds(builder.build()).addFile(file, "quote.png").queue(); + event.getChannel().sendMessageEmbeds(builder.build()).addFiles(FileUpload.fromData(file)).queue(); } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/ChannelMuteCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/ChannelMuteCommand.java index 96491723..2bc6f32e 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/ChannelMuteCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/ChannelMuteCommand.java @@ -15,6 +15,7 @@ import com.diamondfire.helpbot.sys.tasks.impl.MuteExpireTask; import com.diamondfire.helpbot.util.*; import net.dv8tion.jda.api.entities.*; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import java.time.*; import java.util.Date; @@ -86,7 +87,7 @@ public void run(CommandEvent event) { Guild punishmentGuild = event.getGuild(); TextChannel textChannel = punishmentGuild.getTextChannelById(channel); punishmentGuild.retrieveMemberById(user).queue((member) -> { - textChannel.putPermissionOverride(member).deny(net.dv8tion.jda.api.Permission.MESSAGE_ADD_REACTION, net.dv8tion.jda.api.Permission.MESSAGE_WRITE).queue(); + textChannel.upsertPermissionOverride(member).deny(net.dv8tion.jda.api.Permission.MESSAGE_ADD_REACTION, net.dv8tion.jda.api.Permission.MESSAGE_SEND).queue(); }); HelpBotInstance.getScheduler().schedule(new MuteExpireTask(user, finalDuration)); diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/PurgeCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/PurgeCommand.java index 3d8f8064..f439efd8 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/PurgeCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/PurgeCommand.java @@ -11,6 +11,8 @@ import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.sys.externalfile.ExternalFileUtil; import net.dv8tion.jda.api.entities.*; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.utils.FileUpload; import java.io.File; import java.nio.file.*; @@ -55,7 +57,7 @@ public void run(CommandEvent event) { ); event.reply(builder); } else { - TextChannel channel = event.getChannel(); + TextChannel channel = event.getChannel().asTextChannel(); channel.getHistory().retrievePast(messagesToRemove).queue((messages) -> { // Adds the messages to the messageBuilder object StringBuilder stringBuilder = new StringBuilder(); @@ -97,7 +99,7 @@ public void run(CommandEvent event) { ); assert evidenceLog != null; - evidenceLog.sendFile(file).queue(); + evidenceLog.sendFiles(FileUpload.fromData(file)).queue(); } catch (Exception e) { throw new IllegalStateException(); diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/UnmuteCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/UnmuteCommand.java index 935f2a3e..d5bdb0f0 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/UnmuteCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/mod/UnmuteCommand.java @@ -12,6 +12,7 @@ import com.diamondfire.helpbot.sys.database.impl.DatabaseQuery; import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; import net.dv8tion.jda.api.entities.*; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import java.sql.ResultSet; diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/AbstractFileListCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/AbstractFileListCommand.java index 9b313df0..7d8172c4 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/AbstractFileListCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/AbstractFileListCommand.java @@ -7,6 +7,7 @@ import com.diamondfire.helpbot.df.codeinfo.codedatabase.db.datatypes.CodeObject; import com.diamondfire.helpbot.sys.externalfile.ExternalFileUtil; import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.utils.FileUpload; import java.io.*; import java.util.*; @@ -43,6 +44,6 @@ protected void generate(CommandEvent event, List data) { return; } - event.getChannel().sendMessage("File Generated").addFile(file).queue(); + event.getChannel().sendMessage("File Generated").addFiles(FileUpload.fromData(file)).queue(); } } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/PollCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/PollCommand.java index f8965927..7e4bd99d 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/PollCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/util/PollCommand.java @@ -10,6 +10,7 @@ import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.util.Util; import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.entities.emoji.Emoji; import java.awt.*; import java.util.*; @@ -104,7 +105,7 @@ public void run(CommandEvent event) { //add reactions Deque nums = Util.getUnicodeNumbers(); for (String option : pollOptions) { - message.addReaction(nums.pop()).queue(); + message.addReaction(Emoji.fromUnicode(nums.pop())).queue(); } }); diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/BoostersCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/BoostersCommand.java index a8dd705d..00b5543d 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/BoostersCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/BoostersCommand.java @@ -11,7 +11,7 @@ import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; import com.diamondfire.helpbot.util.*; import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.entities.Emote; +import net.dv8tion.jda.api.entities.emoji.Emoji; import java.sql.ResultSet; @@ -66,8 +66,8 @@ public void run(CommandEvent event) { int multiplier = set.getInt("multiplier"); String durationName = FormatUtil.formatMilliTime(set.getLong("end_time") - System.currentTimeMillis()); - Emote emote = event.getJDA().getEmoteById(emotes[Util.clamp(multiplier - 2, 0, emotes.length - 1)]); - embed.addField(String.format("%s %sx booster from %s ", emote.getAsMention(), multiplier, owner), String.format("Ends in: %s", durationName), false); + Emoji emote = event.getJDA().getEmojiById(emotes[Util.clamp(multiplier - 2, 0, emotes.length - 1)]); + embed.addField(String.format("%s %sx booster from %s ", emote.getFormatted(), multiplier, owner), String.format("Ends in: %s", durationName), false); } event.reply(preset); diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/graph/AbstractGraphCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/graph/AbstractGraphCommand.java index 2e868836..ebf43de6 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/graph/AbstractGraphCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/graph/AbstractGraphCommand.java @@ -6,6 +6,7 @@ import com.diamondfire.helpbot.bot.command.permissions.Permission; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.sys.graph.generators.*; +import net.dv8tion.jda.api.utils.FileUpload; public abstract class AbstractGraphCommand extends Command { @@ -27,7 +28,7 @@ public Permission getPermission() { public void run(CommandEvent event) { T context = createContext(event); - event.getChannel().sendFile(getGraphGenerator().createGraph(context)).queue(); + event.getChannel().sendFiles(FileUpload.fromData(getGraphGenerator().createGraph(context))).queue(); } public abstract GraphGenerator getGraphGenerator(); diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/CpCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/CpCommand.java index 5daab72a..968e282f 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/CpCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/CpCommand.java @@ -15,6 +15,7 @@ import com.diamondfire.helpbot.sys.graph.impl.ChartGraphBuilder; import com.diamondfire.helpbot.util.FormatUtil; import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.utils.FileUpload; import java.sql.ResultSet; import java.util.*; @@ -129,9 +130,9 @@ protected void execute(CommandEvent event, Player player) { embed.setImage("attachment://graph.png"); try { event.getReplyHandler().replyA(preset) - .addFile(new ChartGraphBuilder() + .addFiles(FileUpload.fromData(new ChartGraphBuilder() .setGraphName(player.name() + "'s CP Graph") - .createGraph(entries), "graph.png") + .createGraph(entries), "graph.png")) .queue(); } catch (Exception ignored) { event.reply(preset); diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/HistoryCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/HistoryCommand.java index c9219821..3db5b07b 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/HistoryCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/HistoryCommand.java @@ -13,7 +13,8 @@ import com.diamondfire.helpbot.sys.externalfile.ExternalFileUtil; import com.diamondfire.helpbot.util.*; import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.requests.restaction.MessageAction; +import net.dv8tion.jda.api.requests.restaction.MessageCreateAction; +import net.dv8tion.jda.api.utils.FileUpload; import java.awt.*; import java.io.*; @@ -65,7 +66,7 @@ protected void execute(CommandEvent event, Player player) { return; } - List msgs = new ArrayList<>(); + List msgs = new ArrayList<>(); List punishments = new PunishmentFetcher() .withUUID(player.uuidString()) .withAll() @@ -150,7 +151,7 @@ protected void execute(CommandEvent event, Player player) { try { File sendFile = ExternalFileUtil.generateFile("history.txt"); Files.writeString(sendFile.toPath(), String.join("\n", punishmentStrings)); - msgs.add(privateChannel.sendFile(sendFile)); + msgs.add(privateChannel.sendFiles(FileUpload.fromData(sendFile))); } catch (IOException exception) { exception.printStackTrace(); } @@ -158,7 +159,7 @@ protected void execute(CommandEvent event, Player player) { } - MessageAction action = msgs.get(0); + MessageCreateAction action = msgs.get(0); msgs.remove(0); action.queue((msg) -> { @@ -170,7 +171,7 @@ protected void execute(CommandEvent event, Player player) { event.reply(successMSG); - for (MessageAction msgAction : msgs) { + for (MessageCreateAction msgAction : msgs) { msgAction.queue(); } }, (error) -> { diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/ProfileCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/ProfileCommand.java index 5c79d7e3..c0d9647a 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/ProfileCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/ProfileCommand.java @@ -80,7 +80,7 @@ protected void execute(CommandEvent event, Player player) { if (highRank == null) { rankString = ""; } else { - rankString = highRank.getRankEmote().getAsMention(); + rankString = highRank.getRankEmote().getFormatted(); } } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/JoinDataCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/JoinDataCommand.java index c1070e35..b86d5f65 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/JoinDataCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/JoinDataCommand.java @@ -170,6 +170,6 @@ public void run(CommandEvent event) { } private String format(Rank rank) { - return rank.getRankEmote().getAsMention() + " "; + return rank.getRankEmote().getFormatted() + " "; } } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/plot/AbstractPlotCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/plot/AbstractPlotCommand.java index 3122439c..0c7cc316 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/plot/AbstractPlotCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/plot/AbstractPlotCommand.java @@ -6,6 +6,7 @@ import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.util.*; import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.utils.FileUpload; import java.io.File; import java.sql.*; @@ -92,7 +93,7 @@ public void run(CommandEvent event) { } else { File mcItem = Util.fetchMinecraftTextureFile(plotIcon.toUpperCase()); embed.setThumbnail("attachment://" + mcItem.getName()); - event.getReplyHandler().replyA(preset).addFile(mcItem).queue(); + event.getReplyHandler().replyA(preset).addFiles(FileUpload.fromData(mcItem)).queue(); } } catch (SQLException | IllegalStateException e) { diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/plot/PlotVoteGraphCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/plot/PlotVoteGraphCommand.java index 05f85ffb..6431a8a8 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/plot/PlotVoteGraphCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/plot/PlotVoteGraphCommand.java @@ -12,6 +12,7 @@ import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; import com.diamondfire.helpbot.sys.graph.graphable.*; import com.diamondfire.helpbot.sys.graph.impl.ChartGraphBuilder; +import net.dv8tion.jda.api.utils.FileUpload; import java.sql.ResultSet; import java.util.*; @@ -70,9 +71,9 @@ public void run(CommandEvent event) { entries.add(new StringEntry(set.getString("time"))); } - event.getChannel().sendFile(new ChartGraphBuilder() + event.getChannel().sendFiles(FileUpload.fromData(new ChartGraphBuilder() .setGraphName(String.format("Votes on plot %s this month", plotID)) - .createGraphFromCollection(entries)).queue(); + .createGraphFromCollection(entries))).queue(); }); } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/AbstractSessionLogCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/AbstractSessionLogCommand.java index e8eeeff7..7e9e14c4 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/AbstractSessionLogCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/AbstractSessionLogCommand.java @@ -6,6 +6,7 @@ import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.sys.externalfile.ExternalFileUtil; import com.diamondfire.helpbot.util.FormatUtil; +import net.dv8tion.jda.api.utils.FileUpload; import java.io.File; import java.nio.file.*; @@ -37,7 +38,7 @@ protected void execute(CommandEvent event, Player player) { File file = ExternalFileUtil.generateFile("session_log.txt"); Files.writeString(file.toPath(), builder.toString(), StandardOpenOption.WRITE); - event.getChannel().sendFile(file).queue(); + event.getChannel().sendFiles(FileUpload.fromData(file)).queue(); } catch (Exception e) { throw new IllegalStateException(); } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/DailySessionsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/DailySessionsCommand.java index b5517384..57311236 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/DailySessionsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/DailySessionsCommand.java @@ -12,6 +12,7 @@ import com.diamondfire.helpbot.sys.graph.graphable.*; import com.diamondfire.helpbot.sys.graph.impl.ChartGraphBuilder; import com.diamondfire.helpbot.util.DateUtil; +import net.dv8tion.jda.api.utils.FileUpload; import java.sql.ResultSet; import java.time.Instant; @@ -100,9 +101,9 @@ public void run(CommandEvent event) { } } - event.getChannel().sendFile(new ChartGraphBuilder() + event.getChannel().sendFiles(FileUpload.fromData(new ChartGraphBuilder() .setGraphName(String.format("Total sessions on %s", date)) - .createGraph(dates)).queue(); + .createGraph(dates))).queue(); }); diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/ExcusedStaffCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/ExcusedStaffCommand.java index a2279402..4412f595 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/ExcusedStaffCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/ExcusedStaffCommand.java @@ -83,7 +83,7 @@ public void run(CommandEvent event) { names.add(name); } - embed.addField(rank.getRankEmote().getAsMention() + " " + name, String.format("Until: ``%s``\nReason: %s (<@%s>)", FormatUtil.formatDate(date), reason, excused_by), false); + embed.addField(rank.getRankEmote().getFormatted() + " " + name, String.format("Until: ``%s``\nReason: %s (<@%s>)", FormatUtil.formatDate(date), reason, excused_by), false); } event.reply(builder); diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/FindSupporteeNamesCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/FindSupporteeNamesCommand.java index e40fdea9..fe316f24 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/FindSupporteeNamesCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/FindSupporteeNamesCommand.java @@ -131,7 +131,7 @@ protected void execute(CommandEvent event, Player player) { builder.getEmbed().addField("", "Player hasn't been helped by anybody!", false); } - msg.editMessageEmbeds(builder.getEmbed().build()).override(true).queue(); + msg.editMessageEmbeds(builder.getEmbed().build()).setReplace(true).queue(); }); } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/StatsGraphCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/StatsGraphCommand.java index 2a64900b..882bb556 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/StatsGraphCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/support/StatsGraphCommand.java @@ -9,6 +9,7 @@ import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; import com.diamondfire.helpbot.sys.graph.graphable.*; import com.diamondfire.helpbot.sys.graph.impl.ChartGraphBuilder; +import net.dv8tion.jda.api.utils.FileUpload; import java.sql.ResultSet; import java.util.*; @@ -64,9 +65,9 @@ SELECT dates.dt date, COALESCE(t.total, 0) AS total FROM all_dates dates LEFT JO dates.put(new DateEntry(set.getDate("date")), set.getInt("total")); } - event.getChannel().sendFile(new ChartGraphBuilder() + event.getChannel().sendFiles(FileUpload.fromData(new ChartGraphBuilder() .setGraphName(String.format("%s's sessions", player)) - .createGraph(dates)).queue(); + .createGraph(dates))).queue(); }); } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/reply/ReplyHandler.java b/src/main/java/com/diamondfire/helpbot/bot/command/reply/ReplyHandler.java index b47f9fff..5f7e2184 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/reply/ReplyHandler.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/reply/ReplyHandler.java @@ -2,7 +2,11 @@ import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.*; -import net.dv8tion.jda.api.requests.restaction.MessageAction; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; +import net.dv8tion.jda.api.requests.RestAction; +import net.dv8tion.jda.api.requests.restaction.MessageCreateAction; +import net.dv8tion.jda.api.utils.messages.MessageRequest; public class ReplyHandler { @@ -36,19 +40,19 @@ public void reply(EmbedBuilder builder, MessageChannel channel) { embedReply(builder, channel).queue(); } - public MessageAction replyA(PresetBuilder preset) { + public MessageCreateAction replyA(PresetBuilder preset) { return replyA(preset, getChannel()); } - public MessageAction replyA(PresetBuilder preset, MessageChannel channel) { + public MessageCreateAction replyA(PresetBuilder preset, MessageChannel channel) { return embedReply(preset.getEmbed(), channel); } - public MessageAction embedReply(EmbedBuilder embed, MessageChannel channel) { + public MessageCreateAction embedReply(EmbedBuilder embed, MessageChannel channel) { return channel.sendMessageEmbeds(embed.build()); } - public MessageAction textReply(String msg, MessageChannel channel) { + public MessageCreateAction textReply(String msg, MessageChannel channel) { return channel.sendMessage(msg); } diff --git a/src/main/java/com/diamondfire/helpbot/bot/config/Config.java b/src/main/java/com/diamondfire/helpbot/bot/config/Config.java index b14941aa..59fc8666 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/config/Config.java +++ b/src/main/java/com/diamondfire/helpbot/bot/config/Config.java @@ -95,6 +95,10 @@ public Map getPermissionRoleMap() { return HelpBotInstance.GSON.fromJson(config.get("permission_roles"), new TypeToken>(){}.getType()); } + public long getPermission(String role) { + return this.config.get("permission_roles").getAsJsonObject().get(role).getAsLong(); + } + private long getPropertyLong(String property) { return config.get(property).getAsLong(); } diff --git a/src/main/java/com/diamondfire/helpbot/bot/events/ButtonEvent.java b/src/main/java/com/diamondfire/helpbot/bot/events/ButtonEvent.java index f3155897..908833d8 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/events/ButtonEvent.java +++ b/src/main/java/com/diamondfire/helpbot/bot/events/ButtonEvent.java @@ -1,14 +1,14 @@ package com.diamondfire.helpbot.bot.events; import com.diamondfire.helpbot.sys.interaction.button.ButtonHandler; -import net.dv8tion.jda.api.events.interaction.ButtonClickEvent; +import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import org.jetbrains.annotations.NotNull; public class ButtonEvent extends ListenerAdapter { @Override - public void onButtonClick(@NotNull ButtonClickEvent event) { + public void onButtonInteraction(@NotNull ButtonInteractionEvent event) { ButtonHandler.handleEvent(event); } } diff --git a/src/main/java/com/diamondfire/helpbot/bot/events/CommandEvent.java b/src/main/java/com/diamondfire/helpbot/bot/events/CommandEvent.java index 4a5bcac7..6a980cef 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/events/CommandEvent.java +++ b/src/main/java/com/diamondfire/helpbot/bot/events/CommandEvent.java @@ -8,14 +8,14 @@ import com.diamondfire.helpbot.bot.command.impl.Command; import com.diamondfire.helpbot.bot.command.reply.*; import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import java.util.*; -public class CommandEvent extends GuildMessageReceivedEvent { +public class CommandEvent extends MessageReceivedEvent { private Command command; - private final ReplyHandler replyHandler = new ReplyHandler(getChannel()); + private final ReplyHandler replyHandler = new ReplyHandler(getChannel().asTextChannel()); //TODO Cleanup and refactor this. // I'd like to see stuff like replying be put into it's whole own section and refactored as well. private ParsedArgumentSet parsedArgumentSet = null; diff --git a/src/main/java/com/diamondfire/helpbot/bot/events/GuildJoinEvent.java b/src/main/java/com/diamondfire/helpbot/bot/events/GuildJoinEvent.java index 0080879d..71e23123 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/events/GuildJoinEvent.java +++ b/src/main/java/com/diamondfire/helpbot/bot/events/GuildJoinEvent.java @@ -7,12 +7,10 @@ import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; -import javax.annotation.Nonnull; - public class GuildJoinEvent extends ListenerAdapter { @Override - public void onGuildMemberJoin(@Nonnull GuildMemberJoinEvent event) { + public void onGuildMemberJoin(GuildMemberJoinEvent event) { if (event.getGuild().getIdLong() == HelpBotInstance.DF_GUILD) { Member member = event.getMember(); Util.updateMember(member); diff --git a/src/main/java/com/diamondfire/helpbot/bot/events/MessageEditEvent.java b/src/main/java/com/diamondfire/helpbot/bot/events/MessageEditEvent.java index 395e48b9..1c6c5e8d 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/events/MessageEditEvent.java +++ b/src/main/java/com/diamondfire/helpbot/bot/events/MessageEditEvent.java @@ -5,9 +5,6 @@ import net.dv8tion.jda.api.events.message.MessageUpdateEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; - -import javax.annotation.Nonnull; - public class MessageEditEvent extends ListenerAdapter { private static final MessageAcceptor[] acceptors = { @@ -15,7 +12,7 @@ public class MessageEditEvent extends ListenerAdapter { }; @Override - public void onMessageUpdate(@Nonnull MessageUpdateEvent event) { + public void onMessageUpdate(MessageUpdateEvent event) { Message message = event.getMessage(); for (MessageAcceptor acceptor : acceptors) { if (acceptor.accept(message)) { diff --git a/src/main/java/com/diamondfire/helpbot/bot/events/MessageEvent.java b/src/main/java/com/diamondfire/helpbot/bot/events/MessageEvent.java index 072929ea..a516b34d 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/events/MessageEvent.java +++ b/src/main/java/com/diamondfire/helpbot/bot/events/MessageEvent.java @@ -2,10 +2,9 @@ import com.diamondfire.helpbot.sys.message.acceptors.*; import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; - -import javax.annotation.Nonnull; +import org.jetbrains.annotations.NotNull; public class MessageEvent extends ListenerAdapter { @@ -18,14 +17,12 @@ public class MessageEvent extends ListenerAdapter { }; @Override - public void onGuildMessageReceived(@Nonnull GuildMessageReceivedEvent event) { + public void onMessageReceived(@NotNull MessageReceivedEvent event) { Message message = event.getMessage(); for (MessageAcceptor acceptor : acceptors) { if (acceptor.accept(message)) { break; } } - } - } diff --git a/src/main/java/com/diamondfire/helpbot/bot/events/ReadyEvent.java b/src/main/java/com/diamondfire/helpbot/bot/events/ReadyEvent.java index 8f356ba4..56ac7f28 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/events/ReadyEvent.java +++ b/src/main/java/com/diamondfire/helpbot/bot/events/ReadyEvent.java @@ -4,15 +4,12 @@ import com.diamondfire.helpbot.bot.restart.RestartHandler; import com.diamondfire.helpbot.sys.rolereact.RoleReactListener; import net.dv8tion.jda.api.hooks.ListenerAdapter; - -import javax.annotation.Nonnull; +import org.jetbrains.annotations.NotNull; public class ReadyEvent extends ListenerAdapter { @Override - public void onReady(@Nonnull net.dv8tion.jda.api.events.ReadyEvent event) { - super.onReady(event); - + public void onReady(@NotNull net.dv8tion.jda.api.events.session.ReadyEvent event) { RestartHandler.recover(event.getJDA()); HelpBotInstance.getScheduler().initialize(); diff --git a/src/main/java/com/diamondfire/helpbot/bot/restart/RestartHandler.java b/src/main/java/com/diamondfire/helpbot/bot/restart/RestartHandler.java index 2e1015d9..e68ec8c6 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/restart/RestartHandler.java +++ b/src/main/java/com/diamondfire/helpbot/bot/restart/RestartHandler.java @@ -36,7 +36,7 @@ public static void recover(JDA jda) { builder.setTitle("Restart Successful!"); builder.setDescription("Restarted in " + FormatUtil.formatMilliTime(System.currentTimeMillis() - Long.parseLong(restartMSG[2]))); - jda.getTextChannelById(restartMSG[1]).editMessageEmbedsById(restartMSG[0], builder.build()).override(true).queue(); + jda.getTextChannelById(restartMSG[1]).editMessageEmbedsById(restartMSG[0], builder.build()).setReplace(true).queue(); restart.delete(); } catch (IOException | ArrayIndexOutOfBoundsException ignored) { } diff --git a/src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/BasicReaction.java b/src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/BasicReaction.java index 74c2b571..ab48cacf 100644 --- a/src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/BasicReaction.java +++ b/src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/BasicReaction.java @@ -2,66 +2,41 @@ import com.diamondfire.helpbot.bot.HelpBotInstance; import net.dv8tion.jda.api.entities.*; +import net.dv8tion.jda.api.entities.emoji.*; import net.dv8tion.jda.api.requests.RestAction; public class BasicReaction { - final boolean isUnicode; - String unicode; - long id; + private final Emoji emoji; - public BasicReaction(String unicode) { - isUnicode = true; - this.unicode = unicode; + public BasicReaction(Emoji emoji) { + this.emoji = emoji; } - public BasicReaction(long emoteID) { - isUnicode = false; - this.id = emoteID; - } public String getUnicode() { - if (!isUnicode) { + if (emoji.getType() != Emoji.Type.UNICODE) { throw new IllegalStateException("Emoji is not a unicode char!"); } - return unicode; + return emoji.getName(); } - public Emote getEmote() { - if (isUnicode) { - throw new IllegalStateException("Emoji is a unicode char!"); + public CustomEmoji getEmote() { + if (emoji.getType() != Emoji.Type.CUSTOM) { + throw new IllegalStateException("Emoji is not a unicode char!"); } - return HelpBotInstance.getJda().getEmoteById(id); + return (CustomEmoji) emoji; } public RestAction react(Message message) { - if (isUnicode) { - return message.addReaction(getUnicode()); - } - - return message.addReaction(getEmote()); + return message.addReaction(emoji); } @Override public String toString() { - if (isUnicode) { - return getUnicode(); - } - - return getEmote().getAsMention(); - } - - public boolean equalToReaction(MessageReaction.ReactionEmote reaction) { - // if reaction is emoji yet this isn't unicode error is thrown. - if (reaction.isEmoji() != isUnicode) { - return false; - } - - if (reaction.isEmoji()) return getUnicode().equals(reaction.getEmoji()); - if (!reaction.isEmoji()) return getEmote().getIdLong() == reaction.getIdLong(); - return false; + return this.emoji.getFormatted(); } } diff --git a/src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/constants/CodeBlockEnum.java b/src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/constants/CodeBlockEnum.java index 71fbde28..aed8acf0 100644 --- a/src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/constants/CodeBlockEnum.java +++ b/src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/constants/CodeBlockEnum.java @@ -1,7 +1,7 @@ package com.diamondfire.helpbot.df.codeinfo.viewables.constants; import com.diamondfire.helpbot.bot.HelpBotInstance; -import net.dv8tion.jda.api.entities.Emote; +import net.dv8tion.jda.api.entities.emoji.*; import java.awt.*; import java.util.Map; @@ -53,7 +53,7 @@ public String getID() { } - public Emote getEmoji() { - return HelpBotInstance.getJda().getEmotesByName(getID(), true).get(0); + public CustomEmoji getEmoji() { + return HelpBotInstance.getJda().getEmojisByName(getID(), true).get(0); } } diff --git a/src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/embeds/CodeActionEmbedBuilder.java b/src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/embeds/CodeActionEmbedBuilder.java index 60bf79ff..02e791f2 100644 --- a/src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/embeds/CodeActionEmbedBuilder.java +++ b/src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/embeds/CodeActionEmbedBuilder.java @@ -5,7 +5,7 @@ import com.diamondfire.helpbot.df.codeinfo.viewables.BasicReaction; import com.diamondfire.helpbot.util.StringUtil; import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.entities.Emote; +import net.dv8tion.jda.api.entities.emoji.*; import java.util.*; @@ -13,7 +13,7 @@ public class CodeActionEmbedBuilder implements IconEmbedBuilder { @Override public EmbedBuilder buildDataEmbed(ActionData data) { - Emote emote = data.getCodeBlockData().getCodeblockEnum().getEmoji(); + CustomEmoji emote = data.getCodeBlockData().getCodeblockEnum().getEmoji(); EmbedBuilder builder = new EmbedBuilder() .setColor(data.getCodeBlockData().getCodeblockEnum().getColor()) .setAuthor(StringUtil.smartCaps(data.getCodeblockName()), null, emote.getImageUrl()); @@ -34,7 +34,7 @@ public LinkedHashMap generateDupeEmojis(List dataHashed = new LinkedHashMap<>(); for (CodeObject data : dataArrayList) { ActionData actionData = (ActionData) data; - dataHashed.put(new BasicReaction(actionData.getCodeBlockData().getCodeblockEnum().getEmoji().getIdLong()), data); + dataHashed.put(new BasicReaction(actionData.getCodeBlockData().getCodeblockEnum().getEmoji()), data); } return dataHashed; diff --git a/src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/embeds/CodeDisplayBuilder.java b/src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/embeds/CodeDisplayBuilder.java index 601585b5..164261a4 100644 --- a/src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/embeds/CodeDisplayBuilder.java +++ b/src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/embeds/CodeDisplayBuilder.java @@ -5,6 +5,7 @@ import com.diamondfire.helpbot.df.codeinfo.viewables.BasicReaction; import com.diamondfire.helpbot.util.Util; import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.entities.emoji.Emoji; import java.util.*; @@ -57,7 +58,7 @@ default LinkedHashMap generateDupeEmojis(List nums = Util.getUnicodeNumbers(); LinkedHashMap dataHashed = new LinkedHashMap<>(); for (CodeObject data : dataArrayList) { - dataHashed.put(new BasicReaction(nums.pop()), data); + dataHashed.put(new BasicReaction(Emoji.fromUnicode(nums.pop())), data); } return dataHashed; diff --git a/src/main/java/com/diamondfire/helpbot/df/ranks/Rank.java b/src/main/java/com/diamondfire/helpbot/df/ranks/Rank.java index 64c0658d..fa6b48a3 100644 --- a/src/main/java/com/diamondfire/helpbot/df/ranks/Rank.java +++ b/src/main/java/com/diamondfire/helpbot/df/ranks/Rank.java @@ -1,7 +1,7 @@ package com.diamondfire.helpbot.df.ranks; import com.diamondfire.helpbot.bot.HelpBotInstance; -import net.dv8tion.jda.api.entities.Emote; +import net.dv8tion.jda.api.entities.emoji.Emoji; public enum Rank { // Ranks @@ -31,13 +31,13 @@ public enum Rank { private final String rankName; private final int number; private final RankBranch category; - private final Emote emote; + private final Emoji emote; Rank(String rankName, int number, RankBranch category, String emote) { this.rankName = rankName; this.number = number; this.category = category; - this.emote = HelpBotInstance.getJda().getGuildById(615846886414483465L).getEmotesByName(emote, false).get(0); + this.emote = HelpBotInstance.getJda().getGuildById(615846886414483465L).getEmojiById(emote); } public String getRankName() { @@ -62,7 +62,7 @@ public static Rank fromBranch(RankBranch branch, int rankNum) { return null; } - public Emote getRankEmote() { + public Emoji getRankEmote() { return emote; } } diff --git a/src/main/java/com/diamondfire/helpbot/sys/interaction/button/ButtonHandler.java b/src/main/java/com/diamondfire/helpbot/sys/interaction/button/ButtonHandler.java index 82d7dc01..26f0657e 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/interaction/button/ButtonHandler.java +++ b/src/main/java/com/diamondfire/helpbot/sys/interaction/button/ButtonHandler.java @@ -5,7 +5,8 @@ import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.util.TemporaryRunnableStorage; import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.events.interaction.ButtonClickEvent; +import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; +import net.dv8tion.jda.api.utils.messages.MessageEditData; import java.util.Collections; import java.util.function.Consumer; @@ -14,20 +15,20 @@ public class ButtonHandler { private static final TemporaryRunnableStorage BUTTON_CONSUMERS = new TemporaryRunnableStorage<>(); - public static void addListener(long user, Message message, Consumer consumer, boolean persistent) { + public static void addListener(long user, Message message, Consumer consumer, boolean persistent) { BUTTON_CONSUMERS.put(message.getIdLong(), new ButtonListener(user, consumer), () -> { HelpBotInstance.getJda() .getTextChannelById(message.getChannel().getIdLong()).retrieveMessageById(message.getIdLong()) - .flatMap((msg) -> persistent, (msg) -> message.editMessage(message).setActionRows(Collections.emptyList())) + .flatMap((msg) -> persistent, (msg) -> message.editMessage(MessageEditData.fromMessage(message)).setActionRow(Collections.emptyList())) .queue(); }, persistent); } - public static void addListener(long user, Message message, Consumer consumer) { + public static void addListener(long user, Message message, Consumer consumer) { addListener(user, message, consumer, false); } - public static void handleEvent(ButtonClickEvent event) { + public static void handleEvent(ButtonInteractionEvent event) { ButtonListener listener = BUTTON_CONSUMERS.get(event.getMessageIdLong()); if (listener != null) { if (event.getUser().getIdLong() != listener.user) { @@ -45,7 +46,7 @@ public static void handleEvent(ButtonClickEvent event) { } } - private record ButtonListener(long user, Consumer consumer) { + private record ButtonListener(long user, Consumer consumer) { } diff --git a/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/TagAcceptor.java b/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/TagAcceptor.java index f1658aa2..05cdc074 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/TagAcceptor.java +++ b/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/TagAcceptor.java @@ -21,7 +21,7 @@ public boolean accept(Message message) { try { // Get Tag and send response TagHandler.getTag(parsedText) - .sendResponse(message.getTextChannel(), message.getAuthor()); + .sendResponse(message.getChannel().asTextChannel(), message.getAuthor()); } catch (TagDoesNotExistException | IOException ignored) { return false; diff --git a/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/VerifyAcceptor.java b/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/VerifyAcceptor.java index b1493bf9..fbdc1f2f 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/VerifyAcceptor.java +++ b/src/main/java/com/diamondfire/helpbot/sys/message/acceptors/VerifyAcceptor.java @@ -7,6 +7,7 @@ import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; import com.diamondfire.helpbot.util.Util; import net.dv8tion.jda.api.entities.*; +import net.dv8tion.jda.api.entities.emoji.Emoji; import java.sql.ResultSet; @@ -32,7 +33,7 @@ public boolean accept(Message message) { .compile() .run((result) -> { if (result.isEmpty()) { - message.addReaction("❌").queue(); + message.addReaction(Emoji.fromUnicode("❌")).queue(); } else { ResultSet set = result.getResult(); Member author = message.getMember(); diff --git a/src/main/java/com/diamondfire/helpbot/sys/multiselector/MultiSelector.java b/src/main/java/com/diamondfire/helpbot/sys/multiselector/MultiSelector.java index 890de253..96f6eb60 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/multiselector/MultiSelector.java +++ b/src/main/java/com/diamondfire/helpbot/sys/multiselector/MultiSelector.java @@ -3,8 +3,9 @@ import com.diamondfire.helpbot.sys.interaction.button.ButtonHandler; import com.diamondfire.helpbot.util.Util; import net.dv8tion.jda.api.*; -import net.dv8tion.jda.api.entities.Emoji; -import net.dv8tion.jda.api.interactions.components.Button; +import net.dv8tion.jda.api.entities.emoji.Emoji; +import net.dv8tion.jda.api.interactions.components.ItemComponent; +import net.dv8tion.jda.api.interactions.components.buttons.Button; import java.util.*; @@ -42,10 +43,10 @@ public void send(JDA jda) { buttons.add(button); } - jda.getTextChannelById(channel).sendMessageEmbeds(pages[0].getPage().build()).setActionRows(Util.of(buttons)).queue((message) -> { + jda.getTextChannelById(channel).sendMessageEmbeds(pages[0].getPage().build()).setActionRow(buttons).queue((message) -> { ButtonHandler.addListener(user, message, event -> { event.deferEdit().queue(); - message.editMessageEmbeds(pageMap.get(event.getComponentId()).getPage().build()).setActionRows(message.getActionRows()).queue(); + message.editMessageEmbeds(pageMap.get(event.getComponentId()).getPage().build()).setComponents(message.getComponents()).queue(); }, true); }); } diff --git a/src/main/java/com/diamondfire/helpbot/sys/rolereact/RoleReactListener.java b/src/main/java/com/diamondfire/helpbot/sys/rolereact/RoleReactListener.java index 6d00930e..a80494ad 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/rolereact/RoleReactListener.java +++ b/src/main/java/com/diamondfire/helpbot/sys/rolereact/RoleReactListener.java @@ -3,10 +3,11 @@ import com.diamondfire.helpbot.bot.HelpBotInstance; import com.diamondfire.helpbot.util.*; import net.dv8tion.jda.api.entities.*; -import net.dv8tion.jda.api.events.interaction.ButtonClickEvent; +import net.dv8tion.jda.api.entities.emoji.Emoji; +import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; -import net.dv8tion.jda.api.interactions.components.Button; -import net.dv8tion.jda.api.requests.restaction.interactions.ReplyAction; +import net.dv8tion.jda.api.interactions.components.buttons.*; +import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction; import org.jetbrains.annotations.NotNull; import java.util.*; @@ -34,13 +35,13 @@ public RoleReactListener() { roleMap.put(button.getId(), role.getRoleID()); } - msg.editMessage("__**Reaction Roles**__ \nClick to add/remove roles from yourself").setActionRows(Util.of(buttons)).queue(); + msg.editMessage("__**Reaction Roles**__ \nClick to add/remove roles from yourself").setActionRow(buttons).queue(); }); } @Override - public void onButtonClick(@NotNull ButtonClickEvent event) { + public void onButtonInteraction(@NotNull ButtonInteractionEvent event) { if (!roleMap.containsKey(event.getComponentId())) { return; } @@ -49,16 +50,15 @@ public void onButtonClick(@NotNull ButtonClickEvent event) { Guild guild = event.getGuild(); Role guildRole = event.getGuild().getRoleById(role); Member member = event.getMember(); - - ReplyAction action = event.deferReply(true); + + ReplyCallbackAction action = event.deferReply(true); if (member.getRoles().contains(guildRole)) { action.setContent("Removed the " + guildRole.getAsMention() + " role from you!"); - guild.removeRoleFromMember(member.getIdLong(), guildRole).reason("User unsubscribed to announcement!").queue(); + guild.removeRoleFromMember(UserSnowflake.fromId(member.getIdLong()), guildRole).reason("User unsubscribed to announcement!").queue(); } else { action.setContent("Added the " + guildRole.getAsMention() + " role to you!"); - guild.addRoleToMember(member.getIdLong(), guildRole).reason("User subscribed to announcement!").queue(); + guild.addRoleToMember(UserSnowflake.fromId(member.getIdLong()), guildRole).reason("User subscribed to announcement!").queue(); } action.queue(); } - } diff --git a/src/main/java/com/diamondfire/helpbot/sys/tag/Tag.java b/src/main/java/com/diamondfire/helpbot/sys/tag/Tag.java index 681d5d1d..4f47f71d 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/tag/Tag.java +++ b/src/main/java/com/diamondfire/helpbot/sys/tag/Tag.java @@ -4,6 +4,7 @@ import com.google.gson.JsonObject; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.*; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import org.jetbrains.annotations.NotNull; import java.io.Serializable; diff --git a/src/main/java/com/diamondfire/helpbot/sys/tag/TagHandler.java b/src/main/java/com/diamondfire/helpbot/sys/tag/TagHandler.java index 5784dd9f..e565cbab 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/tag/TagHandler.java +++ b/src/main/java/com/diamondfire/helpbot/sys/tag/TagHandler.java @@ -82,6 +82,10 @@ public static void deleteTag(Tag tag) throws TagDoesNotExistException, IOExcepti } public static @NotNull Tag getTag(String activator) throws TagDoesNotExistException, IOException { + if (TAGS.isEmpty()) { + throw new TagDoesNotExistException("Empty"); + } + Tag tag = TAGS.stream() .filter(t -> t.getActivator().equals(activator)) .collect(Collectors.toList()) diff --git a/src/main/java/com/diamondfire/helpbot/sys/tasks/LoopingTask.java b/src/main/java/com/diamondfire/helpbot/sys/tasks/LoopingTask.java index 0c7a98ba..fb83401a 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/tasks/LoopingTask.java +++ b/src/main/java/com/diamondfire/helpbot/sys/tasks/LoopingTask.java @@ -1,7 +1,7 @@ package com.diamondfire.helpbot.sys.tasks; import com.diamondfire.helpbot.bot.HelpBotInstance; -import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; public interface LoopingTask extends Runnable { diff --git a/src/main/java/com/diamondfire/helpbot/sys/tasks/TaskRegistry.java b/src/main/java/com/diamondfire/helpbot/sys/tasks/TaskRegistry.java index ed290d18..324c0f1c 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/tasks/TaskRegistry.java +++ b/src/main/java/com/diamondfire/helpbot/sys/tasks/TaskRegistry.java @@ -13,7 +13,7 @@ public void initialize() { if (HelpBotInstance.getConfig().isDevBot()) return; register( - new CodeDatabaseTask(), + //new CodeDatabaseTask(), new GraphChannelTask(), //new RefreshCreditsTask(), new SupporterClassTask(), diff --git a/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/GraphChannelTask.java b/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/GraphChannelTask.java index b43d1a34..caf74175 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/GraphChannelTask.java +++ b/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/GraphChannelTask.java @@ -4,7 +4,8 @@ import com.diamondfire.helpbot.sys.graph.generators.*; import com.diamondfire.helpbot.sys.graph.generators.context.TimeGraphContext; import com.diamondfire.helpbot.sys.tasks.MidnightTask; -import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.utils.FileUpload; public class GraphChannelTask implements MidnightTask { @@ -14,7 +15,7 @@ public void run() { channel.getHistoryFromBeginning(50).queue(messageHistory -> channel.purgeMessages(messageHistory.getRetrievedHistory())); TimeGraphContext context = new TimeGraphContext(TimeMode.DAILY, 14); - channel.sendFile(GraphGenerators.NEW_PLAYERS.createGraph(context)).queue(); - channel.sendFile(GraphGenerators.UNIQUE_JOINS.createGraph(context)).queue(); + channel.sendFiles(FileUpload.fromData(GraphGenerators.NEW_PLAYERS.createGraph(context))).queue(); + channel.sendFiles(FileUpload.fromData(GraphGenerators.UNIQUE_JOINS.createGraph(context))).queue(); } } diff --git a/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/MuteExpireTask.java b/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/MuteExpireTask.java index bd71dbaa..41213885 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/MuteExpireTask.java +++ b/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/MuteExpireTask.java @@ -6,6 +6,7 @@ import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; import com.diamondfire.helpbot.sys.tasks.OneTimeTask; import net.dv8tion.jda.api.entities.*; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import java.sql.*; import java.time.*; @@ -29,8 +30,8 @@ public long getExecution() { @Override public void run() { Guild guild = HelpBotInstance.getJda().getGuildById(HelpBotInstance.DF_GUILD); - - guild.removeRoleFromMember(member, guild.getRoleById(MuteCommand.ROLE_ID)).queue(); + + guild.removeRoleFromMember(UserSnowflake.fromId(member), guild.getRoleById(MuteCommand.ROLE_ID)).queue(); new DatabaseQuery() .query(new BasicQuery("UPDATE owen.muted_members SET handled = true WHERE member = ?", (statement) -> statement.setLong(1, member))) diff --git a/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/SupportUnexcuseTask.java b/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/SupportUnexcuseTask.java index dd59273c..7893929d 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/SupportUnexcuseTask.java +++ b/src/main/java/com/diamondfire/helpbot/sys/tasks/impl/SupportUnexcuseTask.java @@ -10,7 +10,7 @@ import com.diamondfire.helpbot.sys.database.impl.queries.BasicQuery; import com.diamondfire.helpbot.sys.tasks.OneTimeTask; import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.entities.TextChannel; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;; import java.sql.ResultSet; import java.time.*; diff --git a/src/main/java/com/diamondfire/helpbot/util/PlainComponentSerializer.java b/src/main/java/com/diamondfire/helpbot/util/PlainComponentSerializer.java index 3bc2586a..b15db61e 100644 --- a/src/main/java/com/diamondfire/helpbot/util/PlainComponentSerializer.java +++ b/src/main/java/com/diamondfire/helpbot/util/PlainComponentSerializer.java @@ -2,7 +2,6 @@ import net.kyori.adventure.text.*; import net.kyori.adventure.text.serializer.ComponentSerializer; -import org.checkerframework.checker.nullness.qual.NonNull; import java.util.function.Function; @@ -18,23 +17,23 @@ public PlainComponentSerializer() { this(component -> ""); } - public PlainComponentSerializer(final @NonNull Function translatable) { + public PlainComponentSerializer(final Function translatable) { this.translatable = translatable; } @Override - public @NonNull TextComponent deserialize(final @NonNull String input) { + public TextComponent deserialize(final String input) { return Component.text(input); } @Override - public @NonNull String serialize(final @NonNull Component component) { + public String serialize(final Component component) { final StringBuilder sb = new StringBuilder(); this.serialize(sb, component); return sb.toString(); } - public void serialize(final @NonNull StringBuilder sb, final @NonNull Component component) { + public void serialize(final StringBuilder sb, final Component component) { if (component instanceof TextComponent) { sb.append(((TextComponent) component).content()); } else if (component instanceof TranslatableComponent) { diff --git a/src/main/java/com/diamondfire/helpbot/util/Util.java b/src/main/java/com/diamondfire/helpbot/util/Util.java index 0d2ee005..f8a3a559 100644 --- a/src/main/java/com/diamondfire/helpbot/util/Util.java +++ b/src/main/java/com/diamondfire/helpbot/util/Util.java @@ -15,7 +15,7 @@ import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.interactions.components.ActionRow; -import net.dv8tion.jda.api.interactions.components.Button; +import net.dv8tion.jda.api.interactions.components.buttons.Button; import java.io.BufferedReader; import java.io.File;