diff --git a/build.gradle.kts b/build.gradle.kts index 6bf3b888..de420f34 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -27,6 +27,9 @@ dependencies { implementation ("com.github.Steveice10:MCProtocolLib:c5e4b66") implementation("mysql:mysql-connector-java:5.1.13") implementation("org.codehaus.groovy:groovy-jsr223:3.0.8") + implementation("net.kyori:adventure-api:4.16.0") + implementation("net.kyori:adventure-text-minimessage:4.16.0") + implementation("dev.vankka:mcdiscordreserializer:4.3.0") } tasks { 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 d21ec2d5..8fa27032 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 @@ -54,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()).addFiles(FileUpload.fromData(file)).queue(); + event.getChannel().sendMessageEmbeds(builder.build()).addFiles(FileUpload.fromData(file).setName("quote.png")).queue(); } @Override diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/PlotsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/PlotsCommand.java index d7e4a7c6..42c599f8 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/PlotsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/individualized/PlotsCommand.java @@ -69,7 +69,7 @@ protected void execute(CommandEvent event, Player player) { "Votes: " + plot.getInt("votes"), "Players: " + plot.getInt("player_count") }; - embed.addField(StringUtil.display(plot.getString("name")) + + embed.addField(StringUtil.fromMiniMessage(plot.getString("name")) + String.format(" **(%s)**", plot.getInt("id")), String.join("\n", stats), false); 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 c0d9647a..1ad39852 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 @@ -86,7 +86,7 @@ protected void execute(CommandEvent event, Player player) { embed.addField("Name", rankString + " " + StringUtil.display(playerName), false); embed.addField("UUID", playerUUID, false); - embed.addField("Whois", StringUtil.display(whois.isEmpty() ? "N/A" : whois).replace("\\n", "\n"), false); + embed.addField("Whois", StringUtil.fromMiniMessage(whois.isEmpty() ? "N/A" : whois).replace("\\n", "\n"), false); embed.addField("Pronouns", StringUtil.display(pronouns == null || pronouns.isEmpty() ? "N/A" : pronouns), false); Rank[] ranks = RankUtil.getRanks(set); diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/JoinsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/JoinsCommand.java index 3dce51b8..21aa02d3 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/JoinsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/metrics/JoinsCommand.java @@ -36,7 +36,7 @@ public void run(CommandEvent event) { // gets the total amount of players that have joined before new DatabaseQuery() - .query(new BasicQuery("SELECT COUNT(*) AS count FROM players")) + .query(new BasicQuery("SELECT COUNT(uuid) AS count FROM ranks")) .compile() .run((result) -> { String count = FormatUtil.formatNumber(result.getResult().getInt("count")); 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 0c7cc316..4ded2fe1 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 @@ -53,7 +53,7 @@ public void run(CommandEvent event) { PlotSize size = PlotSize.fromID(resultTablePlot.getInt("plotsize") - 1); embed.setTitle(String.format("Plot Information (%s)", plotID)); - embed.addField("Name", StringUtil.display(resultTablePlot.getString("name")), true); + embed.addField("Name", StringUtil.fromMiniMessage(resultTablePlot.getString("name")), true); embed.addField("Owner", resultTablePlot.getString("owner_name"), true); embed.addField("Node", "Node " + resultTablePlot.getInt("node"), true); embed.addField("Plot Size", StringUtil.smartCaps(size.name()), true); diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/ActivePlotsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/ActivePlotsCommand.java index ff9a1bf1..dd74fd4e 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/ActivePlotsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/ActivePlotsCommand.java @@ -55,7 +55,7 @@ public void run(CommandEvent event) { .compile() .run((result) -> { for (ResultSet set : result) { - embed.addField(StringUtil.display(set.getString("name")) + + embed.addField(StringUtil.fromMiniMessage(set.getString("name")) + String.format(" **(%s)**", set.getInt("id")), "Players: " + set.getInt("player_count"), false); } diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/TrendingPlotsCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/TrendingPlotsCommand.java index 3e25f3ee..7f9cfa25 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/TrendingPlotsCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/stats/top/TrendingPlotsCommand.java @@ -59,7 +59,7 @@ public void run(CommandEvent event) { stats.add("Players: " + count); } - embed.addField(StringUtil.display(set.getString("name")) + + embed.addField(StringUtil.fromMiniMessage(set.getString("name")) + String.format(" **(%s)**", set.getInt("id")), String.join("\n", stats), false); } 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 a516b34d..bf29e880 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/events/MessageEvent.java +++ b/src/main/java/com/diamondfire/helpbot/bot/events/MessageEvent.java @@ -2,7 +2,7 @@ import com.diamondfire.helpbot.sys.message.acceptors.*; import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.events.message.MessageReceivedEvent; +import net.dv8tion.jda.api.events.message.*; import net.dv8tion.jda.api.hooks.ListenerAdapter; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/embeds/IconEmbedBuilder.java b/src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/embeds/IconEmbedBuilder.java index 4f8bbfc4..18352881 100644 --- a/src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/embeds/IconEmbedBuilder.java +++ b/src/main/java/com/diamondfire/helpbot/df/codeinfo/viewables/embeds/IconEmbedBuilder.java @@ -53,7 +53,8 @@ default void generateInfo(T data, EmbedBuilder builder) { enum ParamConverter { ANY_TYPE("Any Value"), - TEXT("Text"), + TEXT("String"), + COMPONENT("Styled Text"), NUMBER("Number"), LOCATION("Location"), VECTOR("Vector"), 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 af5bd748..d67c2e7d 100644 --- a/src/main/java/com/diamondfire/helpbot/sys/rolereact/RoleReactListener.java +++ b/src/main/java/com/diamondfire/helpbot/sys/rolereact/RoleReactListener.java @@ -6,6 +6,7 @@ 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.ItemComponent; import net.dv8tion.jda.api.interactions.components.buttons.*; import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/diamondfire/helpbot/util/StringUtil.java b/src/main/java/com/diamondfire/helpbot/util/StringUtil.java index 3eae5405..390299db 100644 --- a/src/main/java/com/diamondfire/helpbot/util/StringUtil.java +++ b/src/main/java/com/diamondfire/helpbot/util/StringUtil.java @@ -1,11 +1,16 @@ package com.diamondfire.helpbot.util; import net.dv8tion.jda.api.utils.MarkdownSanitizer; +import net.kyori.adventure.text.*; +import net.kyori.adventure.text.minimessage.MiniMessage; import java.util.*; +import java.util.regex.*; public class StringUtil { + private static final Pattern UNICODE_PATTERN = Pattern.compile("§u([\\da-f]{5})"); + public static String listView(String pointer, boolean sanitize, Iterable array) { String view = listView(pointer, array); return sanitize ? StringUtil.display(view) : view; @@ -84,6 +89,18 @@ public static String display(String string) { return MarkdownSanitizer.escape(StringUtil.stripColorCodes(string)); } + public static String fromMiniMessage(String expression) { + Matcher matcher = UNICODE_PATTERN.matcher(expression); + StringBuilder builder = new StringBuilder(); + while (matcher.find()) { + int value = Integer.parseInt(matcher.group(1), 16); + matcher.appendReplacement(builder, Matcher.quoteReplacement(String.valueOf(Character.toChars(value)))); + } + matcher.appendTail(builder); + Component component = MiniMessage.miniMessage().deserialize(StringUtil.stripColorCodes(builder.toString())); + return MarkdownSanitizer.escape(PlainComponentSerializer.INSTANCE.serialize(component)); + } + public static String sCheck(String text, int number) { return number == 1 ? text : text + "s"; }