|
| 1 | +package net.javadiscord.javabot.systems.staff_commands.self_roles; |
| 2 | + |
| 3 | +import com.dynxsty.dih4jda.interactions.commands.SlashCommand; |
| 4 | +import net.dv8tion.jda.api.EmbedBuilder; |
| 5 | +import net.dv8tion.jda.api.entities.Message; |
| 6 | +import net.dv8tion.jda.api.entities.MessageEmbed; |
| 7 | +import net.dv8tion.jda.api.entities.User; |
| 8 | +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; |
| 9 | +import net.dv8tion.jda.api.interactions.commands.OptionMapping; |
| 10 | +import net.dv8tion.jda.api.interactions.commands.OptionType; |
| 11 | +import net.dv8tion.jda.api.interactions.commands.build.SubcommandData; |
| 12 | +import net.javadiscord.javabot.systems.notification.GuildNotificationService; |
| 13 | +import net.javadiscord.javabot.util.Responses; |
| 14 | +import org.jetbrains.annotations.NotNull; |
| 15 | + |
| 16 | +import java.time.Instant; |
| 17 | + |
| 18 | +/** |
| 19 | + * Subcommands that removes all Elements on all ActionRows. |
| 20 | + */ |
| 21 | +public class RemoveSelfRolesSubcommand extends SlashCommand.Subcommand { |
| 22 | + |
| 23 | + public RemoveSelfRolesSubcommand() { |
| 24 | + setSubcommandData(new SubcommandData("remove-all", "Removes all Self-Roles from a specified message.") |
| 25 | + .addOption(OptionType.STRING, "message-id", "Id of the message.", true)); |
| 26 | + } |
| 27 | + |
| 28 | + @Override |
| 29 | + public void execute(SlashCommandInteractionEvent event) { |
| 30 | + OptionMapping idMapping = event.getOption("message-id"); |
| 31 | + if (idMapping == null) { |
| 32 | + Responses.replyMissingArguments(event).queue(); |
| 33 | + return; |
| 34 | + } |
| 35 | + event.deferReply(true).queue(); |
| 36 | + event.getChannel().retrieveMessageById(idMapping.getAsLong()).queue(message -> { |
| 37 | + message.editMessageComponents().queue(); |
| 38 | + MessageEmbed embed = buildSelfRoleDeletedEmbed(event.getUser(), message); |
| 39 | + new GuildNotificationService(event.getGuild()).sendLogChannelNotification(embed); |
| 40 | + event.getHook().sendMessageEmbeds(embed).setEphemeral(true).queue(); |
| 41 | + }, e -> Responses.error(event.getHook(), e.getMessage())); |
| 42 | + } |
| 43 | + |
| 44 | + private @NotNull MessageEmbed buildSelfRoleDeletedEmbed(@NotNull User changedBy, @NotNull Message message) { |
| 45 | + return new EmbedBuilder() |
| 46 | + .setAuthor(changedBy.getAsTag(), message.getJumpUrl(), changedBy.getEffectiveAvatarUrl()) |
| 47 | + .setTitle("Self Roles Removed") |
| 48 | + .setColor(Responses.Type.DEFAULT.getColor()) |
| 49 | + .addField("Channel", message.getChannel().getAsMention(), true) |
| 50 | + .addField("Message", String.format("[Jump to Message](%s)", message.getJumpUrl()), true) |
| 51 | + .setTimestamp(Instant.now()) |
| 52 | + .build(); |
| 53 | + } |
| 54 | +} |
0 commit comments