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/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..fbfc5642 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(); 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..822fe16f 100644 --- a/src/main/java/org/geysermc/discordbot/commands/TagCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/TagCommand.java @@ -25,61 +25,130 @@ 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 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") + ); } - if (tag != null) { - tag.replyWithTag(event); - } else { - event.replyEmbeds(new EmbedBuilder() - .setColor(BotColors.FAILURE.getColor()) - .setTitle("Invalid tag") - .setDescription("Missing requested tag") - .build()).queue(); + @Override + protected void execute(SlashCommandEvent event) { + String search = event.optString("search", ""); + + 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 `/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 `/tag fetch ` 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..74dd783e 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(); 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..0390c5a3 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; @@ -34,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; @@ -70,19 +68,12 @@ 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(); // 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) { @@ -195,4 +186,4 @@ public String getUrl() { return url; } } -} +} \ No newline at end of file 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..497604f7 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; @@ -329,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/listeners/SwearHandler.java b/src/main/java/org/geysermc/discordbot/listeners/SwearHandler.java index f0a4511f..73828922 100644 --- a/src/main/java/org/geysermc/discordbot/listeners/SwearHandler.java +++ b/src/main/java/org/geysermc/discordbot/listeners/SwearHandler.java @@ -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..05a766fe 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; @@ -181,4 +180,4 @@ public List getLevels(Guild guild) { * @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/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/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/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..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: @@ -384,4 +318,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 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 */