From 55fb22b5d68ece3323c6aa4dfad81d283ce5404e Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sat, 16 Mar 2024 00:09:46 +0000 Subject: [PATCH] Add quick ban to user context menu --- .../commands/moderation/BanCommand.java | 2 +- .../context_menus/QuickBanUserMenu.java | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/geysermc/discordbot/context_menus/QuickBanUserMenu.java 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 61d18b15..62acac8a 100644 --- a/src/main/java/org/geysermc/discordbot/commands/moderation/BanCommand.java +++ b/src/main/java/org/geysermc/discordbot/commands/moderation/BanCommand.java @@ -139,7 +139,7 @@ protected void execute(CommandEvent event) { 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) { + public static MessageEmbed handle(Member member, Member moderator, Guild guild, int days, boolean silent, String reason) { // Check the user exists if (member == null) { return new EmbedBuilder() diff --git a/src/main/java/org/geysermc/discordbot/context_menus/QuickBanUserMenu.java b/src/main/java/org/geysermc/discordbot/context_menus/QuickBanUserMenu.java new file mode 100644 index 00000000..0b0f9cf0 --- /dev/null +++ b/src/main/java/org/geysermc/discordbot/context_menus/QuickBanUserMenu.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024-2024 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.context_menus; + +import com.jagrosh.jdautilities.command.UserContextMenu; +import com.jagrosh.jdautilities.command.UserContextMenuEvent; +import net.dv8tion.jda.api.Permission; +import org.geysermc.discordbot.commands.moderation.BanCommand; + +public class QuickBanUserMenu extends UserContextMenu { + public QuickBanUserMenu() { + this.name = "Quick Ban"; + + this.userPermissions = new Permission[] { Permission.BAN_MEMBERS }; + this.botPermissions = new Permission[] { Permission.BAN_MEMBERS }; + } + + @Override + protected void execute(UserContextMenuEvent event) { + event.replyEmbeds(BanCommand.handle(event.getTargetMember(), event.getMember(), event.getGuild(), 1, false, "Scammer or compromised account")).setEphemeral(true).queue(); + } +}