From 0a966d013527edc7238fe6378a8b98ebbeaae631 Mon Sep 17 00:00:00 2001 From: JensC Date: Fri, 9 Jun 2023 23:54:21 +0200 Subject: [PATCH 1/6] overhaul bot code --- .../discordbot/commands/DownloadCommand.java | 19 --- .../discordbot/commands/HelpCommand.java | 10 +- .../discordbot/commands/IssueCommand.java | 13 -- .../commands/LeaderboardCommand.java | 7 - .../discordbot/commands/LevelCommand.java | 27 ---- .../commands/MemberCountCommand.java | 7 - .../discordbot/commands/PingCommand.java | 17 --- .../discordbot/commands/QueueCommand.java | 6 - .../discordbot/commands/RankCommand.java | 21 +-- .../discordbot/commands/TagCommand.java | 127 ++++++++++++++---- .../discordbot/commands/TagsCommand.java | 105 --------------- .../discordbot/commands/WhoisCommand.java | 22 +-- .../commands/moderation/BanCommand.java | 63 --------- .../commands/moderation/KickCommand.java | 49 ------- .../commands/moderation/LogCommand.java | 15 --- .../commands/moderation/MuteCommand.java | 45 ------- .../commands/moderation/PurgeCommand.java | 58 +------- .../commands/moderation/ReasonCommand.java | 21 --- .../commands/moderation/RenameCommand.java | 14 -- .../commands/moderation/SlowmodeCommand.java | 21 --- .../commands/moderation/UnbanCommand.java | 48 +------ .../commands/moderation/UnmuteCommand.java | 55 -------- .../commands/search/ProviderCommand.java | 13 -- .../commands/search/WikiCommand.java | 52 ++----- .../discordbot/listeners/BadLinksHandler.java | 2 +- .../discordbot/listeners/DumpHandler.java | 2 - .../discordbot/listeners/FileHandler.java | 1 - .../discordbot/listeners/LogHandler.java | 18 +-- .../discordbot/listeners/SwearHandler.java | 8 +- .../storage/AbstractStorageManager.java | 8 -- .../storage/MySQLStorageManager.java | 2 +- .../geysermc/discordbot/tags/TagsManager.java | 22 ++- .../geysermc/discordbot/util/BotHelpers.java | 104 -------------- 33 files changed, 143 insertions(+), 859 deletions(-) delete mode 100644 src/main/java/org/geysermc/discordbot/commands/TagsCommand.java diff --git a/src/main/java/org/geysermc/discordbot/commands/DownloadCommand.java b/src/main/java/org/geysermc/discordbot/commands/DownloadCommand.java index 903257be..5f1eec0e 100644 --- a/src/main/java/org/geysermc/discordbot/commands/DownloadCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/DownloadCommand.java @@ -72,25 +72,6 @@ public DownloadCommand() { ); } - @Override - protected void execute(CommandEvent event) { - List args = new ArrayList<>(Arrays.asList(event.getArgs().split(" "))); - - String program = "geyser"; - if (!args.get(0).isEmpty()) { - program = args.get(0); - } - - DownloadOption downloadOption = optionsToRepository.getOrDefault(program.toLowerCase(Locale.ROOT), this.defaultDownloadOption); - - event.getMessage().replyEmbeds(new EmbedBuilder() - .setTitle("Download " + downloadOption.friendlyName) - .setDescription("Download at " + downloadOption.downloadUrl) - .setThumbnail(downloadOption.imageUrl) - .setColor(BotColors.SUCCESS.getColor()) - .build()).queue(); - } - @Override protected void execute(SlashCommandEvent event) { String program = event.optString("program", "geyser"); diff --git a/src/main/java/org/geysermc/discordbot/commands/HelpCommand.java b/src/main/java/org/geysermc/discordbot/commands/HelpCommand.java index abbcd459..887f14df 100644 --- a/src/main/java/org/geysermc/discordbot/commands/HelpCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/HelpCommand.java @@ -26,17 +26,14 @@ package org.geysermc.discordbot.commands; import com.jagrosh.jdautilities.command.Command; -import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.jdautilities.command.SlashCommand; import com.jagrosh.jdautilities.command.SlashCommandEvent; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.MessageEmbed; import org.geysermc.discordbot.GeyserBot; import org.geysermc.discordbot.util.BotColors; -import org.geysermc.discordbot.util.PropertiesManager; import java.util.Comparator; -import java.util.stream.Collectors; /** * Handle the help command @@ -54,17 +51,12 @@ protected void execute(SlashCommandEvent event) { event.replyEmbeds(handle("/")).queue(); } - @Override - protected void execute(CommandEvent event) { - event.getMessage().replyEmbeds(handle(PropertiesManager.getPrefix())).queue(); - } - private MessageEmbed handle(String prefix) { EmbedBuilder helpEmbed = new EmbedBuilder() .setColor(BotColors.SUCCESS.getColor()) .setTitle("Geyser Bot Help"); - for (Command command : GeyserBot.COMMANDS.stream().sorted(Comparator.comparing(Command::getName)).collect(Collectors.toList())) { + for (Command command : GeyserBot.COMMANDS.stream().sorted(Comparator.comparing(Command::getName)).toList()) { if (!command.isHidden()) { helpEmbed.addField("`" + prefix + command.getName() + (command.getArguments() != null ? " " + command.getArguments() : "") + "`", command.getHelp(), true); } diff --git a/src/main/java/org/geysermc/discordbot/commands/IssueCommand.java b/src/main/java/org/geysermc/discordbot/commands/IssueCommand.java index e6b24566..0b2ae7aa 100644 --- a/src/main/java/org/geysermc/discordbot/commands/IssueCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/IssueCommand.java @@ -25,7 +25,6 @@ package org.geysermc.discordbot.commands; -import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.jdautilities.command.SlashCommand; import com.jagrosh.jdautilities.command.SlashCommandEvent; import net.dv8tion.jda.api.EmbedBuilder; @@ -78,18 +77,6 @@ protected void execute(SlashCommandEvent event) { event.replyEmbeds(handle(issue, repo)).queue(); } - @Override - protected void execute(CommandEvent event) { - Matcher matcherIssue = ISSUE_PATTERN.matcher(event.getArgs()); - - if (!matcherIssue.find()) { - MessageHelper.errorResponse(event, "Invalid Issue Format", "Please specify the issue you wish to locate.\nEG: `#100` or `100`"); - return; - } - - event.getMessage().replyEmbeds(handle(Integer.parseInt(matcherIssue.group(2)), event.getArgs().replace(matcherIssue.group(0), ""))).queue(); - } - private MessageEmbed handle(int issueNumber, String repoString) { GHIssue issue; GHUser user; diff --git a/src/main/java/org/geysermc/discordbot/commands/LeaderboardCommand.java b/src/main/java/org/geysermc/discordbot/commands/LeaderboardCommand.java index ad54e6ed..0182176d 100644 --- a/src/main/java/org/geysermc/discordbot/commands/LeaderboardCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/LeaderboardCommand.java @@ -43,13 +43,6 @@ public LeaderboardCommand() { this.help = "Sends a link to the leaderboard for the current server"; } - @Override - protected void execute(CommandEvent event) { - event.getMessage().replyEmbeds(getEmbed(event.getGuild())) - .addActionRow(Button.link(Server.getUrl(event.getGuild().getIdLong()), "Leaderboard")) - .queue(); - } - @Override protected void execute(SlashCommandEvent event) { event.replyEmbeds(getEmbed(event.getGuild())) diff --git a/src/main/java/org/geysermc/discordbot/commands/LevelCommand.java b/src/main/java/org/geysermc/discordbot/commands/LevelCommand.java index 9d584469..d5e27d8b 100644 --- a/src/main/java/org/geysermc/discordbot/commands/LevelCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/LevelCommand.java @@ -25,7 +25,6 @@ package org.geysermc.discordbot.commands; -import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.jdautilities.command.SlashCommand; import com.jagrosh.jdautilities.command.SlashCommandEvent; import net.dv8tion.jda.api.entities.Member; @@ -44,17 +43,13 @@ import org.geysermc.discordbot.storage.LevelInfo; import org.geysermc.discordbot.util.BotHelpers; import org.geysermc.discordbot.util.InkscapeCssParser; -import org.geysermc.discordbot.util.MessageHelper; import org.w3c.dom.Document; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; -import java.util.List; public class LevelCommand extends SlashCommand { @@ -79,27 +74,6 @@ protected void execute(SlashCommandEvent event) { interactionHook.editOriginalAttachments(FileUpload.fromData(levelFile)).queue(message -> levelFile.delete()); } - @Override - protected void execute(CommandEvent event) { - List args = new ArrayList<>(Arrays.asList(event.getArgs().split(" "))); - - Member member; - if (args.size() == 0 || args.get(0).isEmpty()) { - member = event.getMember(); - } else { - member = BotHelpers.getMember(event.getGuild(), args.remove(0)); - } - - // Check user is valid - if (member == null) { - MessageHelper.errorResponse(event, "Invalid user", "The user ID specified doesn't link with any valid user in this server."); - return; - } - - File levelFile = handle(member); - event.getMessage().replyFiles(FileUpload.fromData(levelFile)).queue(message -> levelFile.delete()); - } - protected File handle(Member member) { // Get the user from the member User user = member.getUser(); @@ -117,7 +91,6 @@ protected File handle(Member member) { // Set the text for the svg fields doc.getElementById("level").getFirstChild().setTextContent(String.valueOf(levelInfo.getLevel())); doc.getElementById("name").getFirstChild().setTextContent(user.getName()); - doc.getElementById("discriminator").getFirstChild().setTextContent("#" + user.getDiscriminator()); doc.getElementById("xp").getFirstChild().setTextContent(BotHelpers.coolFormat(levelInfo.getXp())); doc.getElementById("xpnext").getFirstChild().setTextContent(BotHelpers.coolFormat(levelInfo.getXpForNextLevel())); doc.getElementById("avatar").setAttributeNS("http://www.w3.org/1999/xlink", "href", user.getAvatarUrl().replace(".gif", ".png")); diff --git a/src/main/java/org/geysermc/discordbot/commands/MemberCountCommand.java b/src/main/java/org/geysermc/discordbot/commands/MemberCountCommand.java index 95f8051a..967d826a 100644 --- a/src/main/java/org/geysermc/discordbot/commands/MemberCountCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/MemberCountCommand.java @@ -25,7 +25,6 @@ package org.geysermc.discordbot.commands; -import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.jdautilities.command.SlashCommand; import com.jagrosh.jdautilities.command.SlashCommandEvent; import net.dv8tion.jda.api.EmbedBuilder; @@ -35,7 +34,6 @@ import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.geysermc.discordbot.util.BotColors; -import org.geysermc.discordbot.util.BotHelpers; import java.time.Instant; import java.util.Collections; @@ -61,11 +59,6 @@ protected void execute(SlashCommandEvent event) { event.replyEmbeds(handle(event.getGuild(), role)).queue(); } - @Override - protected void execute(CommandEvent event) { - event.getMessage().replyEmbeds(handle(event.getGuild(), BotHelpers.getRole(event.getGuild(), event.getArgs()))).queue(); - } - protected MessageEmbed handle(Guild guild, Role role) { return new EmbedBuilder() .addField("Members" + (role != null ? " in " + role.getName() : ""), String.format("%,d", role != null ? guild.getMembersWithRoles(role).size() : guild.getMemberCount()), false) diff --git a/src/main/java/org/geysermc/discordbot/commands/PingCommand.java b/src/main/java/org/geysermc/discordbot/commands/PingCommand.java index 131fb552..7706d526 100644 --- a/src/main/java/org/geysermc/discordbot/commands/PingCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/PingCommand.java @@ -29,7 +29,6 @@ import br.com.azalim.mcserverping.MCPingOptions; import br.com.azalim.mcserverping.MCPingResponse; import br.com.azalim.mcserverping.MCPingUtil; -import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.jdautilities.command.SlashCommand; import com.jagrosh.jdautilities.command.SlashCommandEvent; import com.nukkitx.protocol.bedrock.BedrockClient; @@ -46,10 +45,7 @@ import java.io.IOException; import java.net.InetSocketAddress; import java.time.Instant; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; -import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -77,19 +73,6 @@ protected void execute(SlashCommandEvent event) { interactionHook.editOriginalEmbeds(handle(ip)).queue(); } - @Override - protected void execute(CommandEvent event) { - List args = new ArrayList<>(Arrays.asList(event.getArgs().split(" "))); - - // Check they specified an ip - if (args.get(0).isEmpty()) { - MessageHelper.errorResponse(event, "Missing IP", "Please specify an IP to ping."); - return; - } - - event.getMessage().replyEmbeds(handle(args.get(0))).queue(); - } - private MessageEmbed handle(String ip) { // Check we were given a valid IP/domain if (!ip.matches("[\\w.\\-:]+")) { diff --git a/src/main/java/org/geysermc/discordbot/commands/QueueCommand.java b/src/main/java/org/geysermc/discordbot/commands/QueueCommand.java index 222baa13..73088c4d 100644 --- a/src/main/java/org/geysermc/discordbot/commands/QueueCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/QueueCommand.java @@ -25,7 +25,6 @@ package org.geysermc.discordbot.commands; -import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.jdautilities.command.SlashCommand; import com.jagrosh.jdautilities.command.SlashCommandEvent; import net.dv8tion.jda.api.EmbedBuilder; @@ -55,11 +54,6 @@ protected void execute(SlashCommandEvent event) { interactionHook.editOriginalEmbeds(handle()).queue(); } - @Override - protected void execute(CommandEvent event) { - event.getMessage().replyEmbeds(handle()).queue(); - } - protected MessageEmbed handle() { JSONObject stats = RestClient.simpleGetJsonObject("https://api.geysermc.org/v2/stats"); if (stats.has("error")) { diff --git a/src/main/java/org/geysermc/discordbot/commands/RankCommand.java b/src/main/java/org/geysermc/discordbot/commands/RankCommand.java index 4ca55225..b013bbc3 100644 --- a/src/main/java/org/geysermc/discordbot/commands/RankCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/RankCommand.java @@ -25,7 +25,6 @@ package org.geysermc.discordbot.commands; -import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.jdautilities.command.SlashCommand; import com.jagrosh.jdautilities.command.SlashCommandEvent; import net.dv8tion.jda.api.EmbedBuilder; @@ -35,15 +34,12 @@ import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.OptionData; +import net.dv8tion.jda.internal.utils.Checks; import org.geysermc.discordbot.storage.ServerSettings; import org.geysermc.discordbot.util.BotColors; -import org.geysermc.discordbot.util.MessageHelper; import java.time.Instant; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; -import java.util.List; import java.util.Map; public class RankCommand extends SlashCommand { @@ -62,23 +58,10 @@ public RankCommand() { @Override protected void execute(SlashCommandEvent event) { String role = event.optString("role", ""); - + Checks.notNull(event.getGuild(), "server"); event.replyEmbeds(handle(event.getGuild(), event.getMember(), role)).queue(); } - @Override - protected void execute(CommandEvent event) { - List args = new ArrayList<>(Arrays.asList(event.getArgs().split(" "))); - - // Check they specified an role - if (args.get(0).isEmpty()) { - MessageHelper.errorResponse(event, "Missing role", "Please specify an role to get."); - return; - } - - event.getMessage().replyEmbeds(handle(event.getGuild(), event.getMember(), args.get(0))).queue(); - } - protected MessageEmbed handle(Guild guild, Member member, String wantedRole) { Map roles = ServerSettings.getMap(guild.getIdLong(), "roles"); for (Map.Entry roleData : roles.entrySet()) { diff --git a/src/main/java/org/geysermc/discordbot/commands/TagCommand.java b/src/main/java/org/geysermc/discordbot/commands/TagCommand.java index 207bd150..1dde984b 100644 --- a/src/main/java/org/geysermc/discordbot/commands/TagCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/TagCommand.java @@ -25,61 +25,134 @@ package org.geysermc.discordbot.commands; +import com.jagrosh.jdautilities.command.Command; import com.jagrosh.jdautilities.command.SlashCommand; import com.jagrosh.jdautilities.command.SlashCommandEvent; import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.geysermc.discordbot.tags.SlashTag; import org.geysermc.discordbot.tags.TagsManager; import org.geysermc.discordbot.util.BotColors; +import org.geysermc.discordbot.util.PropertiesManager; +import java.util.ArrayList; import java.util.Collections; +import java.util.List; public class TagCommand extends SlashCommand { public TagCommand() { this.name = "tag"; - this.help = "Fetch a tag"; - this.arguments = ""; - this.guildOnly = false; - - this.options = Collections.singletonList( - new OptionData(OptionType.STRING, "name", "The tag to get (Supports aliases)", true) - ); + this.help = "Tags"; + this.hidden = true; + this.guildOnly = true; + this.children = new SlashCommand[]{ + new FetchTag(), + new TagsList() + }; } @Override protected void execute(SlashCommandEvent event) { - String tagName = event.getOption("name").getAsString(); - SlashTag tag = null; + // unused + } - for (SlashTag slashTag : TagsManager.getEmbedTags()) { - if (slashTag.getName().equalsIgnoreCase(tagName)) { - tag = slashTag; - break; - } + public static class FetchTag extends SlashCommand { + public FetchTag() { + this.name = "fetch"; + this.help = "Fetch a tag"; + this.arguments = ""; + this.guildOnly = false; + + this.options = Collections.singletonList( + new OptionData(OptionType.STRING, "name", "The tag to get (Supports aliases)", true) + ); + } + + + @Override + protected void execute(SlashCommandEvent event) { + String tagName = event.getOption("name").getAsString(); + SlashTag tag = null; - if (slashTag.getAliases() != null && !slashTag.getAliases().isEmpty()) { - for (String alias : slashTag.getAliases().split(",")) { - if (alias.equalsIgnoreCase(tagName)) { - tag = slashTag; - break; + for (SlashTag slashTag : TagsManager.getEmbedTags()) { + if (slashTag.getName().equalsIgnoreCase(tagName)) { + tag = slashTag; + break; + } + + if (slashTag.getAliases() != null && !slashTag.getAliases().isEmpty()) { + for (String alias : slashTag.getAliases().split(",")) { + if (alias.equalsIgnoreCase(tagName)) { + tag = slashTag; + break; + } } } } + + if (tag != null) { + tag.replyWithTag(event); + } else { + event.replyEmbeds(new EmbedBuilder() + .setColor(BotColors.FAILURE.getColor()) + .setTitle("Invalid tag") + .setDescription("Missing requested tag") + .build()).queue(); + } + + } + } + + public static class TagsList extends SlashCommand { + public TagsList() { + this.name = "list"; + this.arguments = "[search]"; + this.help = "List all the known (non-alias) tags"; + this.guildOnly = false; + + this.options = Collections.singletonList( + new OptionData(OptionType.STRING, "search", "The term you want to search for") + ); + } + + @Override + protected void execute(SlashCommandEvent event) { + String search = event.optString("search", ""); - if (tag != null) { - tag.replyWithTag(event); - } else { - event.replyEmbeds(new EmbedBuilder() - .setColor(BotColors.FAILURE.getColor()) - .setTitle("Invalid tag") - .setDescription("Missing requested tag") - .build()).queue(); + event.replyEmbeds(handle(search)).queue(); } + protected MessageEmbed handle(String search) { + EmbedBuilder embed = new EmbedBuilder(); + + // Get tag names based on search + List tagNames = new ArrayList<>(); + for (Command tag : TagsManager.getTags()) { + if (!tag.getName().equals("alias") && tag.getName().contains(search)) { + tagNames.add(tag.getName()); + } + } + + // Sort the tag names + Collections.sort(tagNames); + if (tagNames.isEmpty()) { + embed.setColor(BotColors.FAILURE.getColor()); + embed.setTitle("No tags found"); + embed.setDescription("No tags were found for your search."); + embed.setFooter("Use `" + PropertiesManager.getPrefix() + "tag aliases ` to see all the aliases for a certain tag"); + } else { + embed.setColor(BotColors.SUCCESS.getColor()); + embed.setTitle("Tags (" + tagNames.size() + ")"); + embed.setDescription("`" + String.join("`, `", tagNames) + "`"); + embed.setFooter("Use `" + PropertiesManager.getPrefix() + "tag ` to show a tag"); + } + + return embed.build(); + } } } diff --git a/src/main/java/org/geysermc/discordbot/commands/TagsCommand.java b/src/main/java/org/geysermc/discordbot/commands/TagsCommand.java deleted file mode 100644 index 28a3c4b4..00000000 --- a/src/main/java/org/geysermc/discordbot/commands/TagsCommand.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2020-2022 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/GeyserDiscordBot - */ - -package org.geysermc.discordbot.commands; - -import com.jagrosh.jdautilities.command.Command; -import com.jagrosh.jdautilities.command.CommandEvent; -import com.jagrosh.jdautilities.command.SlashCommand; -import com.jagrosh.jdautilities.command.SlashCommandEvent; -import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.entities.MessageEmbed; -import net.dv8tion.jda.api.interactions.commands.OptionType; -import net.dv8tion.jda.api.interactions.commands.build.OptionData; -import org.geysermc.discordbot.tags.TagsManager; -import org.geysermc.discordbot.util.BotColors; -import org.geysermc.discordbot.util.PropertiesManager; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -public class TagsCommand extends SlashCommand { - public TagsCommand() { - this.name = "tags"; - this.arguments = "[search]"; - this.help = "List all the known (non-alias) tags"; - this.guildOnly = false; - - this.options = Collections.singletonList( - new OptionData(OptionType.STRING, "search", "The term you want to search for") - ); - } - - @Override - protected void execute(SlashCommandEvent event) { - String search = event.optString("search", ""); - - event.replyEmbeds(handle(search)).queue(); - } - - @Override - protected void execute(CommandEvent event) { - List args = new ArrayList<>(Arrays.asList(event.getArgs().split(" "))); - - // Check they specified an ip - String search = ""; - if (!args.get(0).isEmpty()) { - search = args.get(0); - } - - event.getMessage().replyEmbeds(handle(search)).queue(); - } - - protected MessageEmbed handle(String search) { - EmbedBuilder embed = new EmbedBuilder(); - - // Get tag names based on search - List tagNames = new ArrayList<>(); - for (Command tag : TagsManager.getTags()) { - if (!tag.getName().equals("alias") && tag.getName().contains(search)) { - tagNames.add(tag.getName()); - } - } - - // Sort the tag names - Collections.sort(tagNames); - - if (tagNames.isEmpty()) { - embed.setColor(BotColors.FAILURE.getColor()); - embed.setTitle("No tags found"); - embed.setDescription("No tags were found for your search."); - embed.setFooter("Use `" + PropertiesManager.getPrefix() + "tag aliases ` to see all the aliases for a certain tag"); - } else { - embed.setColor(BotColors.SUCCESS.getColor()); - embed.setTitle("Tags (" + tagNames.size() + ")"); - embed.setDescription("`" + String.join("`, `", tagNames) + "`"); - embed.setFooter("Use `" + PropertiesManager.getPrefix() + "tag ` to show a tag"); - } - - return embed.build(); - } -} diff --git a/src/main/java/org/geysermc/discordbot/commands/WhoisCommand.java b/src/main/java/org/geysermc/discordbot/commands/WhoisCommand.java index 0efed30e..f242e3f8 100644 --- a/src/main/java/org/geysermc/discordbot/commands/WhoisCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/WhoisCommand.java @@ -68,26 +68,6 @@ protected void execute(SlashCommandEvent event) { event.replyEmbeds(handle(member)).queue(); } - @Override - protected void execute(CommandEvent event) { - List args = new ArrayList<>(Arrays.asList(event.getArgs().split(" "))); - - Member member; - if (args.size() == 0 || args.get(0).isEmpty()) { - member = event.getMember(); - } else { - member = BotHelpers.getMember(event.getGuild(), args.remove(0)); - } - - // Check user is valid - if (member == null) { - MessageHelper.errorResponse(event, "Invalid user", "The user ID specified doesn't link with any valid user in this server."); - return; - } - - event.getMessage().replyEmbeds(handle(member)).queue(); - } - protected MessageEmbed handle(Member member) { // Get the user from the member User user = member.getUser(); @@ -99,7 +79,7 @@ protected MessageEmbed handle(Member member) { } return new EmbedBuilder() - .setAuthor(user.getAsTag(), null, user.getAvatarUrl()) + .setAuthor(user.getName(), null, user.getAvatarUrl()) .setDescription(user.getAsMention()) .addField("Joined", TimeFormat.DATE_TIME_LONG.format(member.getTimeJoined()), true) .addField("Registered", TimeFormat.DATE_TIME_LONG.format(member.getTimeCreated()), true) diff --git a/src/main/java/org/geysermc/discordbot/commands/moderation/BanCommand.java b/src/main/java/org/geysermc/discordbot/commands/moderation/BanCommand.java index c2017f8e..c65307d6 100644 --- a/src/main/java/org/geysermc/discordbot/commands/moderation/BanCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/moderation/BanCommand.java @@ -25,7 +25,6 @@ package org.geysermc.discordbot.commands.moderation; -import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.jdautilities.command.SlashCommand; import com.jagrosh.jdautilities.command.SlashCommandEvent; import net.dv8tion.jda.api.EmbedBuilder; @@ -43,9 +42,7 @@ import org.geysermc.discordbot.util.BotHelpers; import java.time.Instant; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; import java.util.concurrent.TimeUnit; public class BanCommand extends SlashCommand { @@ -79,66 +76,6 @@ protected void execute(SlashCommandEvent event) { event.replyEmbeds(handle(member, moderator, event.getGuild(), days, silent, reason)).queue(); } - @Override - protected void execute(CommandEvent event) { - List args = new ArrayList<>(Arrays.asList(event.getArgs().split(" "))); - - // Fetch the user - String selectorString = args.remove(0); - Member member = BotHelpers.getMember(event.getGuild(), selectorString); - Member moderator = event.getMember(); - - // Maybe worth getting rid of this depends on how many times its used - int delDays = 0; - boolean silent = false; - - // Handle all the option args - // We clone the args here to prevent a CME - for (String arg : args.toArray(new String[0])) { - if (!arg.startsWith("-") || arg.length() < 2) { - break; - } - - switch (arg.toCharArray()[1]) { - // Check for silent flag - case 's': - silent = true; - break; - - // Check the delete days flag - case 'd': - try { - delDays = Integer.parseInt(arg.replace("-d", "")); - } catch (NumberFormatException ignored) { - event.getMessage().reply("Please specify an integer for days to delete messages!").queue(); - return; - } - break; - - default: - event.getMessage().replyEmbeds(new EmbedBuilder() - .setTitle("Invalid option") - .setDescription("The option `" + arg + "` is invalid") - .setColor(BotColors.FAILURE.getColor()) - .build()).queue(); - break; - } - - args.remove(0); - } - - // Get the reason or use None - String reasonParts = String.join(" ", args); - String reason; - if (reasonParts.trim().isEmpty()) { - reason = "*None*"; - } else { - reason = reasonParts; - } - - event.getMessage().replyEmbeds(handle(member, moderator, event.getGuild(),delDays, silent, reason)).queue(); - } - private MessageEmbed handle(Member member, Member moderator, Guild guild, int days, boolean silent, String reason) { // Check the user exists if (member == null) { diff --git a/src/main/java/org/geysermc/discordbot/commands/moderation/KickCommand.java b/src/main/java/org/geysermc/discordbot/commands/moderation/KickCommand.java index f24ba41c..e95a11d2 100644 --- a/src/main/java/org/geysermc/discordbot/commands/moderation/KickCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/moderation/KickCommand.java @@ -25,7 +25,6 @@ package org.geysermc.discordbot.commands.moderation; -import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.jdautilities.command.SlashCommand; import com.jagrosh.jdautilities.command.SlashCommandEvent; import net.dv8tion.jda.api.EmbedBuilder; @@ -42,9 +41,7 @@ import org.geysermc.discordbot.util.BotHelpers; import java.time.Instant; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; public class KickCommand extends SlashCommand { @@ -85,52 +82,6 @@ protected void execute(SlashCommandEvent event) { event.replyEmbeds(handle(member, moderator, event.getGuild(), silent, reason)).queue(); } - @Override - protected void execute(CommandEvent event) { - List args = new ArrayList<>(Arrays.asList(event.getArgs().split(" "))); - - // Fetch the user - Member member = BotHelpers.getMember(event.getGuild(), args.remove(0)); - - //Fetch the user that issued the command - Member moderator = event.getMember(); - - // Maybe worth getting rid of this depends on how many times its used - boolean silent = false; - - // Handle all the option args - // We clone the args here to prevent a CME - for (String arg : args.toArray(new String[0])) { - if (!arg.startsWith("-") || arg.length() < 2) { - break; - } - - // Check for silent flag - if (arg.toCharArray()[1] == 's') { - silent = true; - } else { - event.getMessage().replyEmbeds(new EmbedBuilder() - .setTitle("Invalid option") - .setDescription("The option `" + arg + "` is invalid") - .setColor(BotColors.FAILURE.getColor()) - .build()).queue(); - } - - args.remove(0); - } - - // Get the reason or use None - String reasonParts = String.join(" ", args); - String reason; - if (reasonParts.trim().isEmpty()) { - reason = "*None*"; - } else { - reason = reasonParts; - } - - event.getMessage().replyEmbeds(handle(member, moderator, event.getGuild(), silent, reason)).queue(); - } - private MessageEmbed handle(Member member, Member moderator, Guild guild, boolean silent, String reason) { // Check user is valid if (member == null) { diff --git a/src/main/java/org/geysermc/discordbot/commands/moderation/LogCommand.java b/src/main/java/org/geysermc/discordbot/commands/moderation/LogCommand.java index 89ac79e4..132cf28a 100644 --- a/src/main/java/org/geysermc/discordbot/commands/moderation/LogCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/moderation/LogCommand.java @@ -25,7 +25,6 @@ package org.geysermc.discordbot.commands.moderation; -import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.jdautilities.command.SlashCommand; import com.jagrosh.jdautilities.command.SlashCommandEvent; import net.dv8tion.jda.api.EmbedBuilder; @@ -39,13 +38,10 @@ import org.geysermc.discordbot.GeyserBot; import org.geysermc.discordbot.storage.ModLog; import org.geysermc.discordbot.util.BotColors; -import org.geysermc.discordbot.util.BotHelpers; import java.time.Instant; import java.time.OffsetDateTime; import java.time.ZoneOffset; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -74,17 +70,6 @@ protected void execute(SlashCommandEvent event) { event.replyEmbeds(handle(user, event.getGuild())).queue(); } - @Override - protected void execute(CommandEvent event) { - List args = new ArrayList<>(Arrays.asList(event.getArgs().split(" "))); - - // Fetch the user - User user = BotHelpers.getUser(args.remove(0)); - - // Send the embed as a reply - event.getMessage().replyEmbeds(handle(user, event.getGuild())).queue(); - } - private MessageEmbed handle(User user, Guild guild) { // Check user is valid if (user == null) { diff --git a/src/main/java/org/geysermc/discordbot/commands/moderation/MuteCommand.java b/src/main/java/org/geysermc/discordbot/commands/moderation/MuteCommand.java index 2baa5662..9791ecea 100644 --- a/src/main/java/org/geysermc/discordbot/commands/moderation/MuteCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/moderation/MuteCommand.java @@ -73,51 +73,6 @@ protected void execute(SlashCommandEvent event) { event.replyEmbeds(handle(member, moderator, event.getGuild(), silent, reason)).queue(); } - @Override - protected void execute(CommandEvent event) { - List args = new ArrayList<>(Arrays.asList(event.getArgs().split(" "))); - - // Fetch the user - Member member = BotHelpers.getMember(event.getGuild(), args.remove(0)); - - //Fetch the user that issued the command - Member moderator = event.getMember(); - - boolean silent = false; - - // Handle all the option args - // We clone the args here to prevent a CME - for (String arg : args.toArray(new String[0])) { - if (!arg.startsWith("-") || arg.length() < 2) { - break; - } - - // Check for silent flag - if (arg.toCharArray()[1] == 's') { - silent = true; - } else { - event.getMessage().replyEmbeds(new EmbedBuilder() - .setTitle("Invalid option") - .setDescription("The option `" + arg + "` is invalid") - .setColor(BotColors.FAILURE.getColor()) - .build()).queue(); - } - - args.remove(0); - } - - // Get the reason or use None - String reasonParts = String.join(" ", args); - String reason; - if (reasonParts.trim().isEmpty()) { - reason = "*None*"; - } else { - reason = reasonParts; - } - - event.getMessage().replyEmbeds(handle(member, moderator, event.getGuild(), silent, reason)).queue(); - } - private MessageEmbed handle(Member member, Member moderator, Guild guild, boolean silent, String reason) { // Check user is valid if (member == null) { diff --git a/src/main/java/org/geysermc/discordbot/commands/moderation/PurgeCommand.java b/src/main/java/org/geysermc/discordbot/commands/moderation/PurgeCommand.java index afd39250..6fbf84b0 100644 --- a/src/main/java/org/geysermc/discordbot/commands/moderation/PurgeCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/moderation/PurgeCommand.java @@ -25,7 +25,6 @@ package org.geysermc.discordbot.commands.moderation; -import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.jdautilities.command.SlashCommand; import com.jagrosh.jdautilities.command.SlashCommandEvent; import net.dv8tion.jda.api.EmbedBuilder; @@ -36,8 +35,6 @@ import org.geysermc.discordbot.listeners.LogHandler; import org.geysermc.discordbot.storage.ServerSettings; import org.geysermc.discordbot.util.BotColors; -import org.geysermc.discordbot.util.BotHelpers; -import org.geysermc.discordbot.util.MessageHelper; import java.time.Instant; import java.util.ArrayList; @@ -84,7 +81,7 @@ protected void execute(SlashCommandEvent event) { } } - List delList = handle(user, moderator, event.getGuild(), history, count, true); + List delList = handle(user, moderator, event.getGuild(), history, count); if (delList == null) { // Should only return null when it's a single entry @@ -101,50 +98,7 @@ protected void execute(SlashCommandEvent event) { } - @Override - protected void execute(CommandEvent event) { - List args = new ArrayList<>(Arrays.asList(event.getArgs().split(" "))); - - // Get the count and validate it - int count; - try { - count = Integer.parseInt(args.get(0)); - } catch (NumberFormatException e) { - MessageHelper.errorResponse(event, "Invalid count", "Please specify a positive integer for the number of messages to delete!"); - return; - } - - // Make sure we dont have a invalid number - if (count <= 0) { - MessageHelper.errorResponse(event, "Invalid count", "Please specify a positive integer for the number of messages to delete!"); - return; - } - - // Fetch the user - User user = null; - if (args.size() >= 2) { - user = BotHelpers.getUser(args.get(1)); - - // Check user is valid - if (user == null) { - MessageHelper.errorResponse(event, "Invalid user", "The user ID specified doesn't link with any valid user in this server."); - return; - } - } - - LogHandler.PURGED_MESSAGES.add(event.getMessage().getId()); - event.getMessage().delete().queue(); - - MessageHistory history = event.getChannel().getHistory(); - - List delList = handle(user, event.getMember(), event.getGuild(), history, count, false); - - if (delList != null) { - event.getTextChannel().deleteMessagesByIds(delList).queue(); - } - } - - private List handle(User user, Member mod, Guild guild, MessageHistory history, int count, boolean isSlash) { + private List handle(User user, Member mod, Guild guild, MessageHistory history, int count) { int totalMessages = 0; while (totalMessages < count) { List messagesToDelete = new ArrayList<>(); @@ -155,12 +109,6 @@ private List handle(User user, Member mod, Guild guild, MessageHistory h continue; } -/* - if (message.getIdLong() == event.getMessage().getIdLong()) { - continue; - } -*/ - messagesToDelete.add(message); totalMessages++; @@ -191,7 +139,7 @@ private List handle(User user, Member mod, Guild guild, MessageHistory h // Send the embed as a reply and to the log ServerSettings.getLogChannel(guild).sendMessageEmbeds(bannedEmbed).queue(); - if (isSlash) { + if (true) { // If slash command, add purge message count messagesToDeleteIds.add(totalMessages+"/"+count); } diff --git a/src/main/java/org/geysermc/discordbot/commands/moderation/ReasonCommand.java b/src/main/java/org/geysermc/discordbot/commands/moderation/ReasonCommand.java index 207f4d67..44cef490 100644 --- a/src/main/java/org/geysermc/discordbot/commands/moderation/ReasonCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/moderation/ReasonCommand.java @@ -25,7 +25,6 @@ package org.geysermc.discordbot.commands.moderation; -import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.jdautilities.command.SlashCommand; import com.jagrosh.jdautilities.command.SlashCommandEvent; import net.dv8tion.jda.api.EmbedBuilder; @@ -42,9 +41,7 @@ import java.time.Instant; import java.time.OffsetDateTime; import java.time.ZoneOffset; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; public class ReasonCommand extends SlashCommand { @@ -71,24 +68,6 @@ protected void execute(SlashCommandEvent event) { event.replyEmbeds(handle(logID, updatedReason, event.getGuild())).queue(); } - @Override - protected void execute(CommandEvent event) { - MessageEmbed embed; - List args = new ArrayList<>(Arrays.asList(event.getArgs().split(" "))); - - // Fetch the entry - int logId = Integer.parseInt(args.remove(0)); - String newReason = String.join(" ", args); - - if (newReason.trim().isEmpty()) { - embed = handle(logId, null, event.getGuild()); - } else { - embed = handle(logId, newReason, event.getGuild()); - } - - event.getMessage().replyEmbeds(embed).queue(); - } - private MessageEmbed handle(int logId, String updatedReason, Guild guild) { // Fetch log ModLog log = GeyserBot.storageManager.getLog(guild, logId); diff --git a/src/main/java/org/geysermc/discordbot/commands/moderation/RenameCommand.java b/src/main/java/org/geysermc/discordbot/commands/moderation/RenameCommand.java index cb1ceab0..7fd63d03 100644 --- a/src/main/java/org/geysermc/discordbot/commands/moderation/RenameCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/moderation/RenameCommand.java @@ -25,7 +25,6 @@ package org.geysermc.discordbot.commands.moderation; -import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.jdautilities.command.SlashCommand; import com.jagrosh.jdautilities.command.SlashCommandEvent; import net.dv8tion.jda.api.EmbedBuilder; @@ -42,10 +41,7 @@ import org.geysermc.discordbot.util.BotHelpers; import java.time.Instant; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; -import java.util.List; public class RenameCommand extends SlashCommand { @@ -71,16 +67,6 @@ protected void execute(SlashCommandEvent event) { event.replyEmbeds(handle(member, event.getMember(), event.getGuild())).queue(); } - @Override - protected void execute(CommandEvent event) { - List args = new ArrayList<>(Arrays.asList(event.getArgs().split(" "))); - - // Fetch the user - Member member = BotHelpers.getMember(event.getGuild(), args.remove(0)); - - event.getMessage().replyEmbeds(handle(member, event.getMember(), event.getGuild())).queue(); - } - private MessageEmbed handle(Member member, Member moderator, Guild guild) { // Check the user exists if (member == null) { diff --git a/src/main/java/org/geysermc/discordbot/commands/moderation/SlowmodeCommand.java b/src/main/java/org/geysermc/discordbot/commands/moderation/SlowmodeCommand.java index 7e5c77f2..f5e42f22 100644 --- a/src/main/java/org/geysermc/discordbot/commands/moderation/SlowmodeCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/moderation/SlowmodeCommand.java @@ -25,7 +25,6 @@ package org.geysermc.discordbot.commands.moderation; -import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.jdautilities.command.SlashCommand; import com.jagrosh.jdautilities.command.SlashCommandEvent; import net.dv8tion.jda.api.EmbedBuilder; @@ -43,10 +42,7 @@ import org.geysermc.discordbot.util.BotHelpers; import java.time.Instant; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; -import java.util.List; public class SlowmodeCommand extends SlashCommand { @@ -80,23 +76,6 @@ protected void execute(SlashCommandEvent event) { event.replyEmbeds(handle(event.getMember(), event.getGuild(), event.getTextChannel(), arg)).queue(); } - @Override - protected void execute(CommandEvent event) { - List args = new ArrayList<>(Arrays.asList(event.getArgs().split(" "))); - - // Check if a time string was specified - if (args.size() >= 1 && args.get(0).trim().isEmpty()) { - event.getMessage().replyEmbeds(new EmbedBuilder() - .setTitle("Invalid usage") - .setDescription("Please specify a time in the correct format `1h2m3s`.") - .setColor(BotColors.FAILURE.getColor()) - .build()).queue(); - return; - } - - event.getMessage().replyEmbeds(handle(event.getMember(), event.getGuild(), event.getTextChannel(), args.get(0))).queue(); - } - private MessageEmbed handle(Member mod, Guild guild, TextChannel channel, String string) { MessageEmbed slowmodeEmbed; diff --git a/src/main/java/org/geysermc/discordbot/commands/moderation/UnbanCommand.java b/src/main/java/org/geysermc/discordbot/commands/moderation/UnbanCommand.java index 29df7e68..f7c4acc5 100644 --- a/src/main/java/org/geysermc/discordbot/commands/moderation/UnbanCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/moderation/UnbanCommand.java @@ -25,7 +25,6 @@ package org.geysermc.discordbot.commands.moderation; -import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.jdautilities.command.SlashCommand; import com.jagrosh.jdautilities.command.SlashCommandEvent; import net.dv8tion.jda.api.EmbedBuilder; @@ -37,12 +36,9 @@ import org.geysermc.discordbot.GeyserBot; import org.geysermc.discordbot.storage.ServerSettings; import org.geysermc.discordbot.util.BotColors; -import org.geysermc.discordbot.util.BotHelpers; import java.time.Instant; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; public class UnbanCommand extends SlashCommand { @@ -64,7 +60,7 @@ public UnbanCommand() { @Override protected void execute(SlashCommandEvent event) { // Fetch users - User user = BotHelpers.getUser(event.getOption("member").getAsString()); + User user = event.getOption("member").getAsUser(); Member moderator = event.getMember(); // Fetch args @@ -74,48 +70,6 @@ protected void execute(SlashCommandEvent event) { event.replyEmbeds(handle(user, moderator, event.getGuild(), silent, reason)).queue(); } - @Override - protected void execute(CommandEvent event) { - List args = new ArrayList<>(Arrays.asList(event.getArgs().split(" "))); - - // Fetch the user - User user = BotHelpers.getUser(args.remove(0)); - - boolean silent = false; - - // Handle all the option args - // We clone the args here to prevent a CME - for (String arg : args.toArray(new String[0])) { - if (!arg.startsWith("-") || arg.length() < 2) { - break; - } - - if (arg.toCharArray()[1] == 's') { - // Check for silent flag - silent = true; - } else { - event.getMessage().replyEmbeds(new EmbedBuilder() - .setTitle("Invalid option") - .setDescription("The option `" + arg + "` is invalid") - .setColor(BotColors.FAILURE.getColor()) - .build()).queue(); - } - - args.remove(0); - } - - // Get the reason or use None - String reasonParts = String.join(" ", args); - String reason; - if (reasonParts.trim().isEmpty()) { - reason = "*None*"; - } else { - reason = reasonParts; - } - - event.getMessage().replyEmbeds(handle(user, event.getMember(), event.getGuild(), silent, reason)).queue(); - } - private MessageEmbed handle(User user, Member mod, Guild guild, boolean silent, String reason) { // Check user is valid if (user == null) { diff --git a/src/main/java/org/geysermc/discordbot/commands/moderation/UnmuteCommand.java b/src/main/java/org/geysermc/discordbot/commands/moderation/UnmuteCommand.java index a375abd1..15b59122 100644 --- a/src/main/java/org/geysermc/discordbot/commands/moderation/UnmuteCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/moderation/UnmuteCommand.java @@ -25,7 +25,6 @@ package org.geysermc.discordbot.commands.moderation; -import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.jdautilities.command.SlashCommand; import com.jagrosh.jdautilities.command.SlashCommandEvent; import net.dv8tion.jda.api.EmbedBuilder; @@ -39,9 +38,7 @@ import org.geysermc.discordbot.util.BotHelpers; import java.time.Instant; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; public class UnmuteCommand extends SlashCommand { @@ -72,58 +69,6 @@ protected void execute(SlashCommandEvent event) { event.replyEmbeds(handle(member, event.getMember(), event.getGuild(), silent, reason)).queue(); } - @Override - protected void execute(CommandEvent event) { - List args = new ArrayList<>(Arrays.asList(event.getArgs().split(" "))); - - // Fetch the user - Member member = BotHelpers.getMember(event.getGuild(), args.remove(0)); - - // Check user is valid - if (member == null) { - event.getMessage().replyEmbeds(new EmbedBuilder() - .setTitle("Invalid user") - .setDescription("The user ID specified doesn't link with any valid user in this server.") - .setColor(BotColors.FAILURE.getColor()) - .build()).queue(); - return; - } - - boolean silent = false; - - // Handle all the option args - // We clone the args here to prevent a CME - for (String arg : args.toArray(new String[0])) { - if (!arg.startsWith("-") || arg.length() < 2) { - break; - } - - if (arg.toCharArray()[1] == 's') { - // Check for silent flag - silent = true; - } else { - event.getMessage().replyEmbeds(new EmbedBuilder() - .setTitle("Invalid option") - .setDescription("The option `" + arg + "` is invalid") - .setColor(BotColors.FAILURE.getColor()) - .build()).queue(); - } - - args.remove(0); - } - - // Get the reason or use None - String reasonParts = String.join(" ", args); - String reason; - if (reasonParts.trim().isEmpty()) { - reason = "*None*"; - } else { - reason = reasonParts; - } - - event.getMessage().replyEmbeds(handle(member, event.getMember(), event.getGuild(), silent, reason)).queue(); - } - private MessageEmbed handle(Member member, Member moderator, Guild guild, boolean silent, String reason) { // Check we can target the user if (!BotHelpers.canTarget(moderator, member)) { diff --git a/src/main/java/org/geysermc/discordbot/commands/search/ProviderCommand.java b/src/main/java/org/geysermc/discordbot/commands/search/ProviderCommand.java index f64b1505..4660cf72 100644 --- a/src/main/java/org/geysermc/discordbot/commands/search/ProviderCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/search/ProviderCommand.java @@ -67,19 +67,6 @@ protected void execute(SlashCommandEvent event) { event.replyEmbeds(handle(event.optString("provider", ""))).queue(); } - @Override - protected void execute(CommandEvent event) { - String query = event.getArgs(); - - // Check to make sure we have a provider - if (query.isEmpty()) { - MessageHelper.errorResponse(event, "Invalid usage", "Missing provider to check. `" + event.getPrefix() + name + " `"); - return; - } - - event.getMessage().replyEmbeds(handle(query)).queue(); - } - /** * Returns a list of potential providers based on a few factors: *
    diff --git a/src/main/java/org/geysermc/discordbot/commands/search/WikiCommand.java b/src/main/java/org/geysermc/discordbot/commands/search/WikiCommand.java index 3b0d5955..d26cbd43 100644 --- a/src/main/java/org/geysermc/discordbot/commands/search/WikiCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/search/WikiCommand.java @@ -25,7 +25,6 @@ package org.geysermc.discordbot.commands.search; -import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.jdautilities.command.SlashCommand; import com.jagrosh.jdautilities.command.SlashCommandEvent; import net.dv8tion.jda.api.EmbedBuilder; @@ -70,13 +69,6 @@ protected void execute(SlashCommandEvent event) { if (response != null) event.replyEmbeds(response).queue(); } - // !wiki - @Override - protected void execute(CommandEvent event) { - MessageEmbed response = handle(event.getArgs()); - if (response != null) event.getMessage().replyEmbeds(response).queue(); - } - public MessageEmbed handle(String query) { EmbedBuilder embed = new EmbedBuilder(); @@ -102,7 +94,7 @@ public MessageEmbed handle(String query) { if (results.size() >= 1) { // Replace the results with the identical title match for (WikiResult result : results) { - if (result.getTitle().equalsIgnoreCase(query)) { + if (result.title().equalsIgnoreCase(query)) { results = new ArrayList<>(); results.add(result); } @@ -110,12 +102,12 @@ public MessageEmbed handle(String query) { for (WikiResult result : results) { // Ignore pages starting with `_` which are usually meta pages - if (result.getTitle().startsWith("_")) { + if (result.title().startsWith("_")) { continue; } // Add the result as a field - embed.addField(result.getTitle(), result.getUrl() + "\n" + result.getDescription(), false); + embed.addField(result.title(), result.url() + "\n" + result.description(), false); } } else { // We found no results @@ -164,35 +156,17 @@ public List doSearch(String query) { return results; } - private static class WikiResult { - private final String title, description, updated, url; - - public WikiResult(String title, String description, String updated, String url) { - this.title = title; - this.description = description; - this.updated = updated; - - // Fix last character breaking urls - String lastChar = url.substring(url.length() - 1); - lastChar = URLEncoder.encode(lastChar, StandardCharsets.UTF_8); - - this.url = url.substring(0, url.length() - 1) + lastChar; - } - - public String getTitle() { - return title; - } + private record WikiResult(String title, String description, String updated, String url) { + private WikiResult(String title, String description, String updated, String url) { + this.title = title; + this.description = description; + this.updated = updated; - public String getDescription() { - return description; - } + // Fix last character breaking urls + String lastChar = url.substring(url.length() - 1); + lastChar = URLEncoder.encode(lastChar, StandardCharsets.UTF_8); - public String getUpdated() { - return updated; - } - - public String getUrl() { - return url; + this.url = url.substring(0, url.length() - 1) + lastChar; + } } - } } diff --git a/src/main/java/org/geysermc/discordbot/listeners/BadLinksHandler.java b/src/main/java/org/geysermc/discordbot/listeners/BadLinksHandler.java index d5be3037..eec318c3 100644 --- a/src/main/java/org/geysermc/discordbot/listeners/BadLinksHandler.java +++ b/src/main/java/org/geysermc/discordbot/listeners/BadLinksHandler.java @@ -116,7 +116,7 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) { if (foundMatch) { ServerSettings.getLogChannel(event.getGuild()).sendMessageEmbeds(new EmbedBuilder() - .setAuthor(event.getAuthor().getAsTag(), null, event.getAuthor().getAvatarUrl()) + .setAuthor(event.getAuthor().getName(), null, event.getAuthor().getAvatarUrl()) .setDescription("**Link removed, sent by** " + event.getAuthor().getAsMention() + " **deleted in** " + event.getChannel().getAsMention() + "\n" + event.getMessage().getContentRaw()) .addField("Link", link, false) .addField("Matched domain", foundDomain, false) diff --git a/src/main/java/org/geysermc/discordbot/listeners/DumpHandler.java b/src/main/java/org/geysermc/discordbot/listeners/DumpHandler.java index ecf5e52c..b516c38f 100644 --- a/src/main/java/org/geysermc/discordbot/listeners/DumpHandler.java +++ b/src/main/java/org/geysermc/discordbot/listeners/DumpHandler.java @@ -51,8 +51,6 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.net.InetSocketAddress; -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; import java.time.Instant; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/org/geysermc/discordbot/listeners/FileHandler.java b/src/main/java/org/geysermc/discordbot/listeners/FileHandler.java index ae7275a5..d67c1216 100644 --- a/src/main/java/org/geysermc/discordbot/listeners/FileHandler.java +++ b/src/main/java/org/geysermc/discordbot/listeners/FileHandler.java @@ -42,7 +42,6 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutionException; diff --git a/src/main/java/org/geysermc/discordbot/listeners/LogHandler.java b/src/main/java/org/geysermc/discordbot/listeners/LogHandler.java index 7d621dd5..b867162f 100644 --- a/src/main/java/org/geysermc/discordbot/listeners/LogHandler.java +++ b/src/main/java/org/geysermc/discordbot/listeners/LogHandler.java @@ -29,16 +29,12 @@ import com.google.common.cache.CacheBuilder; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.audit.ActionType; -import net.dv8tion.jda.api.audit.AuditLogEntry; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Invite; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.UserSnowflake; import net.dv8tion.jda.api.events.guild.GuildAuditLogEntryCreateEvent; -import net.dv8tion.jda.api.events.guild.GuildBanEvent; -import net.dv8tion.jda.api.events.guild.GuildUnbanEvent; import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent; import net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent; import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent; @@ -164,7 +160,7 @@ public void onGuildMemberJoin(@NotNull GuildMemberJoinEvent event) { try { ServerSettings.getLogChannel(event.getGuild()).sendMessageEmbeds(new EmbedBuilder() .setAuthor("Member Joined", null, event.getUser().getAvatarUrl()) - .setDescription(event.getUser().getAsMention() + " " + event.getUser().getAsTag()) + .setDescription(event.getUser().getAsMention()) .addField("Account Created", TimeFormat.RELATIVE.format(event.getUser().getTimeCreated().toInstant()), false) .setThumbnail(event.getUser().getAvatarUrl()) .setFooter("ID: " + event.getUser().getId()) @@ -179,7 +175,7 @@ public void onGuildMemberRemove(@NotNull GuildMemberRemoveEvent event) { try { ServerSettings.getLogChannel(event.getGuild()).sendMessageEmbeds(new EmbedBuilder() .setAuthor("Member Left", null, event.getUser().getAvatarUrl()) - .setDescription(event.getUser().getAsMention() + " " + event.getUser().getAsTag()) + .setDescription(event.getUser().getName()) .setFooter("ID: " + event.getUser().getId()) .setTimestamp(Instant.now()) .setColor(BotColors.WARNING.getColor()) @@ -207,7 +203,7 @@ public void onMessageUpdate(@NotNull MessageUpdateEvent event) { try { ServerSettings.getLogChannel(event.getGuild()).sendMessageEmbeds(new EmbedBuilder() - .setAuthor(event.getAuthor().getAsTag(), null, event.getAuthor().getAvatarUrl()) + .setAuthor(event.getAuthor().getName(), null, event.getAuthor().getAvatarUrl()) .setDescription("**Message edited in **" + event.getChannel().getAsMention() + " [Jump to Message](" + event.getMessage().getJumpUrl() + ")") .addField("Before", cachedMessage != null ? BotHelpers.trim(cachedMessage.getContentRaw(), 450) : "*Old message not cached*", false) .addField("After", BotHelpers.trim(event.getMessage().getContentRaw(), 450), false) @@ -239,9 +235,9 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) { try { ServerSettings.getLogChannel(event.getGuild()).sendMessageEmbeds(new EmbedBuilder() - .setAuthor(event.getAuthor().getAsTag(), null, event.getAuthor().getAvatarUrl()) + .setAuthor(event.getAuthor().getName(), null, event.getAuthor().getAvatarUrl()) .setDescription("**Invite posted for " + invite.getGuild().getName() + "** " + event.getChannel().getAsMention() + "\n" + invite.getUrl()) - .addField("Inviter", invite.getInviter() != null ? invite.getInviter().getAsTag() : "Unknown", true) + .addField("Inviter", invite.getInviter() != null ? invite.getInviter().getName() : "Unknown", true) .addField("Channel", invite.getChannel() != null ? invite.getChannel().getName() : "Group", true) .addField("Members", invite.getGuild().getOnlineCount() + "/" + invite.getGuild().getMemberCount(), true) .setFooter("ID: " + event.getAuthor().getId()) @@ -283,7 +279,7 @@ public void onMessageDelete(@NotNull MessageDeleteEvent event) { return; } - authorTag = cachedMessage.getAuthor().getAsTag(); + authorTag = cachedMessage.getAuthor().getName(); authorMention = cachedMessage.getAuthor().getAsMention(); authorAvatar = cachedMessage.getAuthor().getAvatarUrl(); authorId = cachedMessage.getAuthor().getId(); @@ -321,7 +317,7 @@ public void onGuildVoiceUpdate(@NotNull GuildVoiceUpdateEvent event) { try { ServerSettings.getLogChannel(event.getGuild()).sendMessageEmbeds(new EmbedBuilder() - .setAuthor(event.getMember().getUser().getAsTag(), null, event.getMember().getUser().getAvatarUrl()) + .setAuthor(event.getMember().getUser().getName(), null, event.getMember().getUser().getAvatarUrl()) .setDescription(description) .setFooter("ID: " + event.getMember().getId()) .setTimestamp(Instant.now()) diff --git a/src/main/java/org/geysermc/discordbot/listeners/SwearHandler.java b/src/main/java/org/geysermc/discordbot/listeners/SwearHandler.java index f0a4511f..0cd97068 100644 --- a/src/main/java/org/geysermc/discordbot/listeners/SwearHandler.java +++ b/src/main/java/org/geysermc/discordbot/listeners/SwearHandler.java @@ -63,7 +63,7 @@ public class SwearHandler extends ListenerAdapter { static { // Add some standard replacement tokens // TODO: Find a better way of doing this if we get duplicate chars - REPLACE_TOKENS.put("\u0430", "a"); + REPLACE_TOKENS.put("а", "a"); REPLACE_TOKENS.put("\u043A", "k"); REPLACE_TOKENS.put("\u0441", "c"); REPLACE_TOKENS.put("\u0443", "y"); @@ -131,7 +131,7 @@ public static String getRandomNick() { @Override public void onMessageReceived(@NotNull MessageReceivedEvent event) { - handleMessageEvent(event.getMessage(), true); + handleMessageEvent(event.getMessage()); } // Disabled for now @@ -140,7 +140,7 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) { // handleMessageEvent(event.getMessage(), false); // } - private void handleMessageEvent(Message message, boolean notifyUser) { + private void handleMessageEvent(Message message) { if (message.getAuthor().isBot() || !message.isFromGuild()) { return; } @@ -156,7 +156,7 @@ private void handleMessageEvent(Message message, boolean notifyUser) { // Delete message message.delete().queue(unused -> { - if (notifyUser) { + if (true) { // Alert the user message message.getChannel().sendMessage(message.getAuthor().getAsMention() + " your message has been removed because it contains profanity! Please read our rules for more information.").queue(); diff --git a/src/main/java/org/geysermc/discordbot/storage/AbstractStorageManager.java b/src/main/java/org/geysermc/discordbot/storage/AbstractStorageManager.java index 7f3c3bc0..0406fbfe 100644 --- a/src/main/java/org/geysermc/discordbot/storage/AbstractStorageManager.java +++ b/src/main/java/org/geysermc/discordbot/storage/AbstractStorageManager.java @@ -28,7 +28,6 @@ import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Role; -import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.UserSnowflake; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; @@ -151,13 +150,6 @@ public List getLogs(Guild guild, UserSnowflake target) { */ public abstract void setLevel(Member user, LevelInfo levelInfo); - /** - * @see AbstractStorageManager#getLevels(long) - */ - public List getLevels(Guild guild) { - return getLevels(guild.getIdLong()); - } - /** * Get the top 100 levels for a given guild id * diff --git a/src/main/java/org/geysermc/discordbot/storage/MySQLStorageManager.java b/src/main/java/org/geysermc/discordbot/storage/MySQLStorageManager.java index 0fd26f57..1045c314 100644 --- a/src/main/java/org/geysermc/discordbot/storage/MySQLStorageManager.java +++ b/src/main/java/org/geysermc/discordbot/storage/MySQLStorageManager.java @@ -73,7 +73,7 @@ public void closeStorage() { private void checkConnection() { try { if (connection.isValid(0)) return; - } catch (SQLException e) { } + } catch (SQLException ignored) { } try { setupStorage(); diff --git a/src/main/java/org/geysermc/discordbot/tags/TagsManager.java b/src/main/java/org/geysermc/discordbot/tags/TagsManager.java index 0bdbb4da..8dfb5a63 100644 --- a/src/main/java/org/geysermc/discordbot/tags/TagsManager.java +++ b/src/main/java/org/geysermc/discordbot/tags/TagsManager.java @@ -142,7 +142,7 @@ private static void loadTags() { // Create the tag from the stored data switch (tagData.get("type")) { - case "text": + case "text" -> { try { TAGS.add(new EmbedTag(tagName, content.toString().trim(), tagData.get("image"), tagData.get("aliases"), buttons)); SLASH_TAGS.add(new SlashTag(tagName, content.toString().trim(), tagData.get("image"), tagData.get("aliases"), buttons, 0)); @@ -150,35 +150,31 @@ private static void loadTags() { GeyserBot.LOGGER.warn("Failed to create tag: " + e.getMessage()); continue; } - break; - - case "text-raw": + } + case "text-raw" -> { try { TAGS.add(new RawTag(tagName, content.toString().trim(), tagData.get("aliases"), buttons)); - SLASH_TAGS.add(new SlashTag(tagName, content.toString().trim(), null, tagData.get("aliases"), buttons, 1)); + SLASH_TAGS.add(new SlashTag(tagName, content.toString().trim(), null, tagData.get("aliases"), buttons, 1)); } catch (IllegalArgumentException e) { GeyserBot.LOGGER.warn("Failed to create tag: " + e.getMessage()); continue; } - break; - - case "issue-only": + } + case "issue-only" -> { if (tagData.containsKey("aliases")) { GeyserBot.LOGGER.warn("Tag '" + tagName + "' has aliases listed but is of type 'issue-only'. Ignoring aliases."); } - if (tagData.containsKey("image")) { GeyserBot.LOGGER.warn("Tag '" + tagName + "' has image listed but is of type 'issue-only'. Ignoring image."); } - if (issueTriggers == null) { GeyserBot.LOGGER.warn("Tag '" + tagName + "' has no issues listed but is of type 'issue-only'."); } - break; - - default: + } + default -> { GeyserBot.LOGGER.warn("Invalid tag type '" + tagData.get("type") + "' for tag '" + tagName + "'! Ignoring tag."); continue; + } } if (issueTriggers != null) { diff --git a/src/main/java/org/geysermc/discordbot/util/BotHelpers.java b/src/main/java/org/geysermc/discordbot/util/BotHelpers.java index d2515547..7d2a71c2 100644 --- a/src/main/java/org/geysermc/discordbot/util/BotHelpers.java +++ b/src/main/java/org/geysermc/discordbot/util/BotHelpers.java @@ -27,14 +27,10 @@ import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.Role; -import net.dv8tion.jda.api.entities.User; -import net.dv8tion.jda.api.exceptions.ErrorResponseException; import org.geysermc.discordbot.GeyserBot; import org.kohsuke.github.GHRepository; import org.kohsuke.github.PagedSearchIterable; -import javax.annotation.Nullable; import java.io.BufferedInputStream; import java.io.File; import java.io.IOException; @@ -45,7 +41,6 @@ import java.nio.charset.StandardCharsets; import java.util.Enumeration; import java.util.HashSet; -import java.util.List; import java.util.Set; import java.util.jar.JarEntry; import java.util.jar.JarFile; @@ -57,105 +52,6 @@ public class BotHelpers { private static final Pattern REPO_PATTERN = Pattern.compile("(^| )([\\w.\\-]+/)?([\\w.\\-]+)( |$)", Pattern.CASE_INSENSITIVE); - /** - * Get a guild member from a given id string - * - * @param guild Guild to get the member for - * @param userTag The tag to use to find the member - * @return The found Member or null - */ - @Nullable - public static Member getMember(Guild guild, String userTag) { - try { - User user = getUser(userTag); - - if (user == null) { - // Try and find a member by name using the passed string - List members = guild.getMembersByEffectiveName(userTag, true); - if (!members.isEmpty()) { - return members.get(0); - } - } else { - return guild.getMember(user); - } - } catch (IllegalArgumentException ignored) { } - - return null; - } - - /** - * Get a discord user from a given id string - * Input examples: - * <@!1234> - * 1234 - * abc#1234 - * - * @param userTag The tag to use to find the member - * @return The found User or null - */ - @Nullable - public static User getUser(String userTag) { - if (userTag.isEmpty()) return null; - - // If it's a mention of a non-user then ignore - if (userTag.startsWith("<") && !userTag.startsWith("<@")) { - return null; - } - - try { - // Check for a mention (<@!1234>) - if (userTag.startsWith("<@") && userTag.endsWith(">")) { - userTag = userTag.replace("!", ""); - userTag = userTag.substring(2, userTag.length() - 1); - } else { - // Check for a user tag (example#1234) - Matcher m = User.USER_TAG.matcher(userTag); - if (m.matches()) { - return GeyserBot.getJDA().getUserByTag(m.group(1), m.group(2)); - } - } - - // Try to get the member by ID - return GeyserBot.getJDA().retrieveUserById(userTag).complete(); - } catch (NumberFormatException | ErrorResponseException ignored) { - return null; - } - } - - /** - * Get a discord role from a given id string - * Input examples: - * <@&1234> - * 1234 - * admin - * - * @param guild The guild to find the role in - * @param roleTag The tag to use to find the member - * @return The found User or null - */ - @Nullable - public static Role getRole(Guild guild, String roleTag) { - if (roleTag.isEmpty()) return null; - - try { - // Check for a mention (<@&1234>) - if (roleTag.startsWith("<@&") && roleTag.endsWith(">")) { - roleTag = roleTag.substring(3, roleTag.length() - 1); - } else { - // Find the role by name - List foundRole = guild.getRolesByName(roleTag, false); - if (!foundRole.isEmpty()) { - return foundRole.get(0); - } - } - - // Try to get the role by ID - return guild.getRoleById(roleTag); - } catch (NumberFormatException | ErrorResponseException ignored) { - return null; - } - } - private static final char[] FORMAT_CHARS = new char[]{'k', 'm', 'b', 't'}; public static String coolFormat(int n) { From b25f3f300533953e01cdb57508ed4e043e40f7b2 Mon Sep 17 00:00:00 2001 From: JensC Date: Sat, 10 Jun 2023 00:07:22 +0200 Subject: [PATCH 2/6] remove older prefix code --- src/main/java/org/geysermc/discordbot/GeyserBot.java | 4 ---- .../java/org/geysermc/discordbot/commands/TagCommand.java | 5 ++--- .../geysermc/discordbot/commands/search/WikiCommand.java | 3 +-- .../java/org/geysermc/discordbot/tags/TagAliasCommand.java | 7 +++---- .../org/geysermc/discordbot/util/PropertiesManager.java | 7 ------- 5 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/geysermc/discordbot/GeyserBot.java b/src/main/java/org/geysermc/discordbot/GeyserBot.java index 369e7059..051a84f3 100644 --- a/src/main/java/org/geysermc/discordbot/GeyserBot.java +++ b/src/main/java/org/geysermc/discordbot/GeyserBot.java @@ -165,7 +165,6 @@ public static void main(String[] args) throws IOException, LoginException { CommandClientBuilder client = new CommandClientBuilder(); client.setActivity(null); client.setOwnerId("0"); // No owner - client.setPrefix(PropertiesManager.getPrefix()); client.useHelpBuilder(false); client.addCommands(COMMANDS.toArray(new Command[0])); client.addSlashCommands(SLASH_COMMANDS.toArray(new SlashCommand[0])); @@ -176,9 +175,6 @@ public static void main(String[] args) throws IOException, LoginException { CommandClientBuilder tagClient = new CommandClientBuilder(); tagClient.setActivity(null); tagClient.setOwnerId("0"); // No owner - String tagPrefix = PropertiesManager.getPrefix() + PropertiesManager.getPrefix(); - tagClient.setPrefix(tagPrefix); - tagClient.setPrefixes(new String[] {"!tag "}); tagClient.useHelpBuilder(false); tagClient.addCommands(TagsManager.getTags().toArray(new Command[0])); tagClient.setListener(new TagsListener()); diff --git a/src/main/java/org/geysermc/discordbot/commands/TagCommand.java b/src/main/java/org/geysermc/discordbot/commands/TagCommand.java index 1dde984b..d3d29a42 100644 --- a/src/main/java/org/geysermc/discordbot/commands/TagCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/TagCommand.java @@ -35,7 +35,6 @@ import org.geysermc.discordbot.tags.SlashTag; import org.geysermc.discordbot.tags.TagsManager; import org.geysermc.discordbot.util.BotColors; -import org.geysermc.discordbot.util.PropertiesManager; import java.util.ArrayList; import java.util.Collections; @@ -144,12 +143,12 @@ protected MessageEmbed handle(String search) { embed.setColor(BotColors.FAILURE.getColor()); embed.setTitle("No tags found"); embed.setDescription("No tags were found for your search."); - embed.setFooter("Use `" + PropertiesManager.getPrefix() + "tag aliases ` to see all the aliases for a certain tag"); + embed.setFooter("Use `/tag list aliases ` to see all the aliases for a certain tag"); } else { embed.setColor(BotColors.SUCCESS.getColor()); embed.setTitle("Tags (" + tagNames.size() + ")"); embed.setDescription("`" + String.join("`, `", tagNames) + "`"); - embed.setFooter("Use `" + PropertiesManager.getPrefix() + "tag ` to show a tag"); + embed.setFooter("Use `/tag fetch ` to show a tag"); } return embed.build(); diff --git a/src/main/java/org/geysermc/discordbot/commands/search/WikiCommand.java b/src/main/java/org/geysermc/discordbot/commands/search/WikiCommand.java index d26cbd43..fec61f06 100644 --- a/src/main/java/org/geysermc/discordbot/commands/search/WikiCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/search/WikiCommand.java @@ -33,7 +33,6 @@ import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.geysermc.discordbot.util.BotColors; import org.geysermc.discordbot.util.MessageHelper; -import org.geysermc.discordbot.util.PropertiesManager; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; @@ -74,7 +73,7 @@ public MessageEmbed handle(String query) { // Check to make sure we have a search term if (query.isEmpty()) { - return MessageHelper.errorResponse(null, "Invalid usage", "Missing search term. `" + PropertiesManager.getPrefix() + name + " `"); + return MessageHelper.errorResponse(null, "Invalid usage", "Missing search term. `/" + name + " `"); } if (query.length() > 128) { diff --git a/src/main/java/org/geysermc/discordbot/tags/TagAliasCommand.java b/src/main/java/org/geysermc/discordbot/tags/TagAliasCommand.java index 306061d9..f57fd751 100644 --- a/src/main/java/org/geysermc/discordbot/tags/TagAliasCommand.java +++ b/src/main/java/org/geysermc/discordbot/tags/TagAliasCommand.java @@ -30,7 +30,6 @@ import net.dv8tion.jda.api.EmbedBuilder; import org.geysermc.discordbot.listeners.SwearHandler; import org.geysermc.discordbot.util.BotColors; -import org.geysermc.discordbot.util.PropertiesManager; import java.util.Arrays; @@ -55,7 +54,7 @@ protected void execute(CommandEvent event) { if (args.length == 0) { embed.setTitle("Invalid usage"); - embed.setDescription("Missing tag name. `" + PropertiesManager .getPrefix() + "tag alias `"); + embed.setDescription("Missing tag name. `/tag alias `"); embed.setColor(BotColors.FAILURE.getColor()); event.getMessage().replyEmbeds(embed.build()).queue(); @@ -72,7 +71,7 @@ protected void execute(CommandEvent event) { if (foundTag == null) { embed.setTitle("Missing tag"); - embed.setDescription("No tag with the name `" + args[0] + "`, do `" + PropertiesManager.getPrefix() + "tags` for the full list."); + embed.setDescription("No tag with the name `" + args[0] + "`, do `/tags` for the full list."); embed.setColor(BotColors.FAILURE.getColor()); event.getMessage().replyEmbeds(embed.build()).queue(); return; @@ -81,7 +80,7 @@ protected void execute(CommandEvent event) { if (foundTag.getAliases().length > 0) { embed.setTitle("Aliases for " + foundTag.getName() + " (" + foundTag.getAliases().length + ")"); embed.setDescription("`" + String.join("`, `", foundTag.getAliases()) + "`"); - embed.setFooter("Use `" + PropertiesManager.getPrefix() + "tag ` to show a tag"); + embed.setFooter("Use `/tag ` to show a tag"); embed.setColor(BotColors.SUCCESS.getColor()); } else { embed.setTitle("No aliases for " + foundTag.getName()); diff --git a/src/main/java/org/geysermc/discordbot/util/PropertiesManager.java b/src/main/java/org/geysermc/discordbot/util/PropertiesManager.java index 2d23a095..3a422427 100644 --- a/src/main/java/org/geysermc/discordbot/util/PropertiesManager.java +++ b/src/main/java/org/geysermc/discordbot/util/PropertiesManager.java @@ -42,13 +42,6 @@ public static String getToken() { return properties.getProperty("token"); } - /** - * @return Bot prefix - */ - public static String getPrefix() { - return properties.getProperty("prefix"); - } - /** * @return Database connection type */ From fe84ccd11774c39da7236929b9148318660c5d3c Mon Sep 17 00:00:00 2001 From: JensC Date: Sat, 10 Jun 2023 00:21:55 +0200 Subject: [PATCH 3/6] oops --- .../java/org/geysermc/discordbot/listeners/SwearHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/geysermc/discordbot/listeners/SwearHandler.java b/src/main/java/org/geysermc/discordbot/listeners/SwearHandler.java index 0cd97068..73828922 100644 --- a/src/main/java/org/geysermc/discordbot/listeners/SwearHandler.java +++ b/src/main/java/org/geysermc/discordbot/listeners/SwearHandler.java @@ -63,7 +63,7 @@ public class SwearHandler extends ListenerAdapter { static { // Add some standard replacement tokens // TODO: Find a better way of doing this if we get duplicate chars - REPLACE_TOKENS.put("а", "a"); + REPLACE_TOKENS.put("\u0430", "a"); REPLACE_TOKENS.put("\u043A", "k"); REPLACE_TOKENS.put("\u0441", "c"); REPLACE_TOKENS.put("\u0443", "y"); From 9d2092f22a50bf9fc2b622cf9023004e3bbfc864 Mon Sep 17 00:00:00 2001 From: JensC Date: Sat, 10 Jun 2023 09:28:16 +0200 Subject: [PATCH 4/6] Revert changes for other pr --- .../discordbot/commands/LevelCommand.java | 1 + .../discordbot/commands/WhoisCommand.java | 2 +- .../commands/search/WikiCommand.java | 46 +++++--- .../discordbot/listeners/BadLinksHandler.java | 2 +- .../discordbot/listeners/LogHandler.java | 16 +-- .../storage/AbstractStorageManager.java | 9 +- .../geysermc/discordbot/util/BotHelpers.java | 106 +++++++++++++++++- 7 files changed, 156 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/geysermc/discordbot/commands/LevelCommand.java b/src/main/java/org/geysermc/discordbot/commands/LevelCommand.java index d5e27d8b..fbfc5642 100644 --- a/src/main/java/org/geysermc/discordbot/commands/LevelCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/LevelCommand.java @@ -91,6 +91,7 @@ protected File handle(Member member) { // Set the text for the svg fields doc.getElementById("level").getFirstChild().setTextContent(String.valueOf(levelInfo.getLevel())); doc.getElementById("name").getFirstChild().setTextContent(user.getName()); + doc.getElementById("discriminator").getFirstChild().setTextContent("#" + user.getDiscriminator()); doc.getElementById("xp").getFirstChild().setTextContent(BotHelpers.coolFormat(levelInfo.getXp())); doc.getElementById("xpnext").getFirstChild().setTextContent(BotHelpers.coolFormat(levelInfo.getXpForNextLevel())); doc.getElementById("avatar").setAttributeNS("http://www.w3.org/1999/xlink", "href", user.getAvatarUrl().replace(".gif", ".png")); diff --git a/src/main/java/org/geysermc/discordbot/commands/WhoisCommand.java b/src/main/java/org/geysermc/discordbot/commands/WhoisCommand.java index f242e3f8..74dd783e 100644 --- a/src/main/java/org/geysermc/discordbot/commands/WhoisCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/WhoisCommand.java @@ -79,7 +79,7 @@ protected MessageEmbed handle(Member member) { } return new EmbedBuilder() - .setAuthor(user.getName(), null, user.getAvatarUrl()) + .setAuthor(user.getAsTag(), null, user.getAvatarUrl()) .setDescription(user.getAsMention()) .addField("Joined", TimeFormat.DATE_TIME_LONG.format(member.getTimeJoined()), true) .addField("Registered", TimeFormat.DATE_TIME_LONG.format(member.getTimeCreated()), true) diff --git a/src/main/java/org/geysermc/discordbot/commands/search/WikiCommand.java b/src/main/java/org/geysermc/discordbot/commands/search/WikiCommand.java index fec61f06..0390c5a3 100644 --- a/src/main/java/org/geysermc/discordbot/commands/search/WikiCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/search/WikiCommand.java @@ -93,7 +93,7 @@ public MessageEmbed handle(String query) { if (results.size() >= 1) { // Replace the results with the identical title match for (WikiResult result : results) { - if (result.title().equalsIgnoreCase(query)) { + if (result.getTitle().equalsIgnoreCase(query)) { results = new ArrayList<>(); results.add(result); } @@ -101,12 +101,12 @@ public MessageEmbed handle(String query) { for (WikiResult result : results) { // Ignore pages starting with `_` which are usually meta pages - if (result.title().startsWith("_")) { + if (result.getTitle().startsWith("_")) { continue; } // Add the result as a field - embed.addField(result.title(), result.url() + "\n" + result.description(), false); + embed.addField(result.getTitle(), result.getUrl() + "\n" + result.getDescription(), false); } } else { // We found no results @@ -155,17 +155,35 @@ public List doSearch(String query) { return results; } - private record WikiResult(String title, String description, String updated, String url) { - private WikiResult(String title, String description, String updated, String url) { - this.title = title; - this.description = description; - this.updated = updated; + private static class WikiResult { + private final String title, description, updated, url; - // Fix last character breaking urls - String lastChar = url.substring(url.length() - 1); - lastChar = URLEncoder.encode(lastChar, StandardCharsets.UTF_8); + public WikiResult(String title, String description, String updated, String url) { + this.title = title; + this.description = description; + this.updated = updated; - this.url = url.substring(0, url.length() - 1) + lastChar; - } + // Fix last character breaking urls + String lastChar = url.substring(url.length() - 1); + lastChar = URLEncoder.encode(lastChar, StandardCharsets.UTF_8); + + this.url = url.substring(0, url.length() - 1) + lastChar; + } + + public String getTitle() { + return title; + } + + public String getDescription() { + return description; } -} + + public String getUpdated() { + return updated; + } + + public String getUrl() { + return url; + } + } +} \ No newline at end of file diff --git a/src/main/java/org/geysermc/discordbot/listeners/BadLinksHandler.java b/src/main/java/org/geysermc/discordbot/listeners/BadLinksHandler.java index eec318c3..d5be3037 100644 --- a/src/main/java/org/geysermc/discordbot/listeners/BadLinksHandler.java +++ b/src/main/java/org/geysermc/discordbot/listeners/BadLinksHandler.java @@ -116,7 +116,7 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) { if (foundMatch) { ServerSettings.getLogChannel(event.getGuild()).sendMessageEmbeds(new EmbedBuilder() - .setAuthor(event.getAuthor().getName(), null, event.getAuthor().getAvatarUrl()) + .setAuthor(event.getAuthor().getAsTag(), null, event.getAuthor().getAvatarUrl()) .setDescription("**Link removed, sent by** " + event.getAuthor().getAsMention() + " **deleted in** " + event.getChannel().getAsMention() + "\n" + event.getMessage().getContentRaw()) .addField("Link", link, false) .addField("Matched domain", foundDomain, false) diff --git a/src/main/java/org/geysermc/discordbot/listeners/LogHandler.java b/src/main/java/org/geysermc/discordbot/listeners/LogHandler.java index b867162f..497604f7 100644 --- a/src/main/java/org/geysermc/discordbot/listeners/LogHandler.java +++ b/src/main/java/org/geysermc/discordbot/listeners/LogHandler.java @@ -160,7 +160,7 @@ public void onGuildMemberJoin(@NotNull GuildMemberJoinEvent event) { try { ServerSettings.getLogChannel(event.getGuild()).sendMessageEmbeds(new EmbedBuilder() .setAuthor("Member Joined", null, event.getUser().getAvatarUrl()) - .setDescription(event.getUser().getAsMention()) + .setDescription(event.getUser().getAsMention() + " " + event.getUser().getAsTag()) .addField("Account Created", TimeFormat.RELATIVE.format(event.getUser().getTimeCreated().toInstant()), false) .setThumbnail(event.getUser().getAvatarUrl()) .setFooter("ID: " + event.getUser().getId()) @@ -175,7 +175,7 @@ public void onGuildMemberRemove(@NotNull GuildMemberRemoveEvent event) { try { ServerSettings.getLogChannel(event.getGuild()).sendMessageEmbeds(new EmbedBuilder() .setAuthor("Member Left", null, event.getUser().getAvatarUrl()) - .setDescription(event.getUser().getName()) + .setDescription(event.getUser().getAsMention() + " " + event.getUser().getAsTag()) .setFooter("ID: " + event.getUser().getId()) .setTimestamp(Instant.now()) .setColor(BotColors.WARNING.getColor()) @@ -203,7 +203,7 @@ public void onMessageUpdate(@NotNull MessageUpdateEvent event) { try { ServerSettings.getLogChannel(event.getGuild()).sendMessageEmbeds(new EmbedBuilder() - .setAuthor(event.getAuthor().getName(), null, event.getAuthor().getAvatarUrl()) + .setAuthor(event.getAuthor().getAsTag(), null, event.getAuthor().getAvatarUrl()) .setDescription("**Message edited in **" + event.getChannel().getAsMention() + " [Jump to Message](" + event.getMessage().getJumpUrl() + ")") .addField("Before", cachedMessage != null ? BotHelpers.trim(cachedMessage.getContentRaw(), 450) : "*Old message not cached*", false) .addField("After", BotHelpers.trim(event.getMessage().getContentRaw(), 450), false) @@ -235,9 +235,9 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) { try { ServerSettings.getLogChannel(event.getGuild()).sendMessageEmbeds(new EmbedBuilder() - .setAuthor(event.getAuthor().getName(), null, event.getAuthor().getAvatarUrl()) + .setAuthor(event.getAuthor().getAsTag(), null, event.getAuthor().getAvatarUrl()) .setDescription("**Invite posted for " + invite.getGuild().getName() + "** " + event.getChannel().getAsMention() + "\n" + invite.getUrl()) - .addField("Inviter", invite.getInviter() != null ? invite.getInviter().getName() : "Unknown", true) + .addField("Inviter", invite.getInviter() != null ? invite.getInviter().getAsTag() : "Unknown", true) .addField("Channel", invite.getChannel() != null ? invite.getChannel().getName() : "Group", true) .addField("Members", invite.getGuild().getOnlineCount() + "/" + invite.getGuild().getMemberCount(), true) .setFooter("ID: " + event.getAuthor().getId()) @@ -279,7 +279,7 @@ public void onMessageDelete(@NotNull MessageDeleteEvent event) { return; } - authorTag = cachedMessage.getAuthor().getName(); + authorTag = cachedMessage.getAuthor().getAsTag(); authorMention = cachedMessage.getAuthor().getAsMention(); authorAvatar = cachedMessage.getAuthor().getAvatarUrl(); authorId = cachedMessage.getAuthor().getId(); @@ -317,7 +317,7 @@ public void onGuildVoiceUpdate(@NotNull GuildVoiceUpdateEvent event) { try { ServerSettings.getLogChannel(event.getGuild()).sendMessageEmbeds(new EmbedBuilder() - .setAuthor(event.getMember().getUser().getName(), null, event.getMember().getUser().getAvatarUrl()) + .setAuthor(event.getMember().getUser().getAsTag(), null, event.getMember().getUser().getAvatarUrl()) .setDescription(description) .setFooter("ID: " + event.getMember().getId()) .setTimestamp(Instant.now()) @@ -325,4 +325,4 @@ public void onGuildVoiceUpdate(@NotNull GuildVoiceUpdateEvent event) { .build()).queue(); } catch (IllegalArgumentException ignored) { } } -} +} \ No newline at end of file diff --git a/src/main/java/org/geysermc/discordbot/storage/AbstractStorageManager.java b/src/main/java/org/geysermc/discordbot/storage/AbstractStorageManager.java index 0406fbfe..05a766fe 100644 --- a/src/main/java/org/geysermc/discordbot/storage/AbstractStorageManager.java +++ b/src/main/java/org/geysermc/discordbot/storage/AbstractStorageManager.java @@ -150,6 +150,13 @@ public List getLogs(Guild guild, UserSnowflake target) { */ public abstract void setLevel(Member user, LevelInfo levelInfo); + /** + * @see AbstractStorageManager#getLevels(long) + */ + public List getLevels(Guild guild) { + return getLevels(guild.getIdLong()); + } + /** * Get the top 100 levels for a given guild id * @@ -173,4 +180,4 @@ public List getLogs(Guild guild, UserSnowflake target) { * @param delay Delay between messages in seconds */ public abstract void setSlowModeChannel(TextChannel channel, int delay); -} +} \ No newline at end of file diff --git a/src/main/java/org/geysermc/discordbot/util/BotHelpers.java b/src/main/java/org/geysermc/discordbot/util/BotHelpers.java index 7d2a71c2..572d2d99 100644 --- a/src/main/java/org/geysermc/discordbot/util/BotHelpers.java +++ b/src/main/java/org/geysermc/discordbot/util/BotHelpers.java @@ -27,10 +27,14 @@ import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.Role; +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.exceptions.ErrorResponseException; import org.geysermc.discordbot.GeyserBot; import org.kohsuke.github.GHRepository; import org.kohsuke.github.PagedSearchIterable; +import javax.annotation.Nullable; import java.io.BufferedInputStream; import java.io.File; import java.io.IOException; @@ -41,6 +45,7 @@ import java.nio.charset.StandardCharsets; import java.util.Enumeration; import java.util.HashSet; +import java.util.List; import java.util.Set; import java.util.jar.JarEntry; import java.util.jar.JarFile; @@ -52,6 +57,105 @@ public class BotHelpers { private static final Pattern REPO_PATTERN = Pattern.compile("(^| )([\\w.\\-]+/)?([\\w.\\-]+)( |$)", Pattern.CASE_INSENSITIVE); + /** + * Get a guild member from a given id string + * + * @param guild Guild to get the member for + * @param userTag The tag to use to find the member + * @return The found Member or null + */ + @Nullable + public static Member getMember(Guild guild, String userTag) { + try { + User user = getUser(userTag); + + if (user == null) { + // Try and find a member by name using the passed string + List members = guild.getMembersByEffectiveName(userTag, true); + if (!members.isEmpty()) { + return members.get(0); + } + } else { + return guild.getMember(user); + } + } catch (IllegalArgumentException ignored) { } + + return null; + } + + /** + * Get a discord user from a given id string + * Input examples: + * <@!1234> + * 1234 + * abc#1234 + * + * @param userTag The tag to use to find the member + * @return The found User or null + */ + @Nullable + public static User getUser(String userTag) { + if (userTag.isEmpty()) return null; + + // If it's a mention of a non-user then ignore + if (userTag.startsWith("<") && !userTag.startsWith("<@")) { + return null; + } + + try { + // Check for a mention (<@!1234>) + if (userTag.startsWith("<@") && userTag.endsWith(">")) { + userTag = userTag.replace("!", ""); + userTag = userTag.substring(2, userTag.length() - 1); + } else { + // Check for a user tag (example#1234) + Matcher m = User.USER_TAG.matcher(userTag); + if (m.matches()) { + return GeyserBot.getJDA().getUserByTag(m.group(1), m.group(2)); + } + } + + // Try to get the member by ID + return GeyserBot.getJDA().retrieveUserById(userTag).complete(); + } catch (NumberFormatException | ErrorResponseException ignored) { + return null; + } + } + + /** + * Get a discord role from a given id string + * Input examples: + * <@&1234> + * 1234 + * admin + * + * @param guild The guild to find the role in + * @param roleTag The tag to use to find the member + * @return The found User or null + */ + @Nullable + public static Role getRole(Guild guild, String roleTag) { + if (roleTag.isEmpty()) return null; + + try { + // Check for a mention (<@&1234>) + if (roleTag.startsWith("<@&") && roleTag.endsWith(">")) { + roleTag = roleTag.substring(3, roleTag.length() - 1); + } else { + // Find the role by name + List foundRole = guild.getRolesByName(roleTag, false); + if (!foundRole.isEmpty()) { + return foundRole.get(0); + } + } + + // Try to get the role by ID + return guild.getRoleById(roleTag); + } catch (NumberFormatException | ErrorResponseException ignored) { + return null; + } + } + private static final char[] FORMAT_CHARS = new char[]{'k', 'm', 'b', 't'}; public static String coolFormat(int n) { @@ -280,4 +384,4 @@ public static boolean canTarget(Member moderator, Member member) { Member botMember = moderator.getGuild().getMember(GeyserBot.getJDA().getSelfUser()); return moderator.canInteract(member) && botMember.canInteract(member) && !member.equals(botMember); } -} +} \ No newline at end of file From 162de47a393a09d6ec8fec2e50f4c9cade132aa7 Mon Sep 17 00:00:00 2001 From: JensC Date: Sat, 10 Jun 2023 09:42:39 +0200 Subject: [PATCH 5/6] remove these as we got rid of the prefixed commands --- .../geysermc/discordbot/util/BotHelpers.java | 66 ------------------- 1 file changed, 66 deletions(-) diff --git a/src/main/java/org/geysermc/discordbot/util/BotHelpers.java b/src/main/java/org/geysermc/discordbot/util/BotHelpers.java index 572d2d99..d6071251 100644 --- a/src/main/java/org/geysermc/discordbot/util/BotHelpers.java +++ b/src/main/java/org/geysermc/discordbot/util/BotHelpers.java @@ -56,72 +56,6 @@ public class BotHelpers { private static final Pattern REPO_PATTERN = Pattern.compile("(^| )([\\w.\\-]+/)?([\\w.\\-]+)( |$)", Pattern.CASE_INSENSITIVE); - - /** - * Get a guild member from a given id string - * - * @param guild Guild to get the member for - * @param userTag The tag to use to find the member - * @return The found Member or null - */ - @Nullable - public static Member getMember(Guild guild, String userTag) { - try { - User user = getUser(userTag); - - if (user == null) { - // Try and find a member by name using the passed string - List members = guild.getMembersByEffectiveName(userTag, true); - if (!members.isEmpty()) { - return members.get(0); - } - } else { - return guild.getMember(user); - } - } catch (IllegalArgumentException ignored) { } - - return null; - } - - /** - * Get a discord user from a given id string - * Input examples: - * <@!1234> - * 1234 - * abc#1234 - * - * @param userTag The tag to use to find the member - * @return The found User or null - */ - @Nullable - public static User getUser(String userTag) { - if (userTag.isEmpty()) return null; - - // If it's a mention of a non-user then ignore - if (userTag.startsWith("<") && !userTag.startsWith("<@")) { - return null; - } - - try { - // Check for a mention (<@!1234>) - if (userTag.startsWith("<@") && userTag.endsWith(">")) { - userTag = userTag.replace("!", ""); - userTag = userTag.substring(2, userTag.length() - 1); - } else { - // Check for a user tag (example#1234) - Matcher m = User.USER_TAG.matcher(userTag); - if (m.matches()) { - return GeyserBot.getJDA().getUserByTag(m.group(1), m.group(2)); - } - } - - // Try to get the member by ID - return GeyserBot.getJDA().retrieveUserById(userTag).complete(); - } catch (NumberFormatException | ErrorResponseException ignored) { - return null; - } - } - /** * Get a discord role from a given id string * Input examples: From a2474d5c92f648e63d8244269fe172ea755d8bab Mon Sep 17 00:00:00 2001 From: JensC Date: Sat, 10 Jun 2023 09:52:58 +0200 Subject: [PATCH 6/6] spacing was off --- src/main/java/org/geysermc/discordbot/commands/TagCommand.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/org/geysermc/discordbot/commands/TagCommand.java b/src/main/java/org/geysermc/discordbot/commands/TagCommand.java index d3d29a42..822fe16f 100644 --- a/src/main/java/org/geysermc/discordbot/commands/TagCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/TagCommand.java @@ -70,7 +70,6 @@ public FetchTag() { ); } - @Override protected void execute(SlashCommandEvent event) { String tagName = event.getOption("name").getAsString(); @@ -101,8 +100,6 @@ protected void execute(SlashCommandEvent event) { .setDescription("Missing requested tag") .build()).queue(); } - - } }