From 7fc3932f4391b6c9c1e88d6323942fdd7726157d Mon Sep 17 00:00:00 2001 From: Salmonllama Date: Fri, 13 Nov 2020 19:27:23 -0500 Subject: [PATCH] WIP admin command --- .../commands/staff/ForceDeleteCommand.java | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/main/java/dev/salmonllama/fsbot/commands/staff/ForceDeleteCommand.java diff --git a/src/main/java/dev/salmonllama/fsbot/commands/staff/ForceDeleteCommand.java b/src/main/java/dev/salmonllama/fsbot/commands/staff/ForceDeleteCommand.java new file mode 100644 index 0000000..78e5166 --- /dev/null +++ b/src/main/java/dev/salmonllama/fsbot/commands/staff/ForceDeleteCommand.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2020. Aleksei Gryczewski + * All rights reserved. + */ + +package dev.salmonllama.fsbot.commands.staff; + +import dev.salmonllama.fsbot.database.controllers.OutfitController; +import dev.salmonllama.fsbot.guthix.*; +import dev.salmonllama.fsbot.listeners.ForceDeleteAttachedListener; +import org.javacord.api.entity.message.MessageBuilder; +import org.javacord.api.entity.message.embed.EmbedBuilder; +import org.javacord.api.event.message.MessageCreateEvent; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.TimeUnit; + +public class ForceDeleteCommand extends Command { + @Override public String name() { return "Force Delete"; } + @Override public String description() { return "Forcefully deletes the given outfit from the database. Destructive action"; } + @Override public String usage() { return "forcedelete "; } + @Override public CommandCategory category() { return CommandCategory.STAFF; } + @Override public CommandPermission permission() { return new CommandPermission(PermissionType.STATIC, "owner"); } + @Override public List aliases() { return Arrays.asList("forcedelete", "sudorm"); } + + @Override + public void onCommand(CommandContext ctx) { + // Send a confirmation, confirming the outfit to delete. + // Confirmation will be done via DM for special confirmation of a destructive action. + + if (ctx.getArgs().length == 0) { + ctx.reply("You must supply a valid ID"); + } + + var outfitId = ctx.getArgs()[0]; + + MessageBuilder builder = new MessageBuilder(); + builder.setContent( + ":warning: THIS IS A DESTRUCTIVE ACTION :warning:\n\n" + + "You are about to destroy an entry from the database.\n\n" + + "This is unrecoverable, if the entry in question does not\n" + + "break Discord, Fashionscape, or FSBot TOS, please consider using\n" + + "`~remove` instead.\n\n" + + "Verify the entry's information below and respond with `YES` to proceed\n" + + "or `NO` to cancel.\n\n" + + "*After 5 minutes, the response window will close and you will have to re-run the command*" + ); + + OutfitController.findById(outfitId).thenAcceptAsync(possibleOutfit -> possibleOutfit.ifPresentOrElse(outfit -> { + // DM the user with confirmation message, disclaimer, and info embed + // Attach a 5 minute listener looking for YES or NO + EmbedBuilder embed = new EmbedBuilder() + .setTitle("Outift Information |" + outfit.getId()) + .setUrl(outfit.getLink()) + .addField("Submitter:", outfit.getSubmitter()) + .addField("Meta:", outfit.getMeta()) + .addField("Link:", outfit.getLink()) + .addField("Submitted:", outfit.getCreated().toString()) + .setThumbnail(outfit.getLink()) + .setFooter(String.format("%s | %s", outfit.getTag(), outfit.getId())); + + builder.setEmbed(embed); + + builder.send(ctx.getChannel()).thenAcceptAsync(msg -> { + // Add the event listeners and check for YES/NO + var fdal = new ForceDeleteAttachedListener(ctx); + ctx.getChannel().addMessageCreateListener(fdal); + + ctx.getChannel().addMessageCreateListener(event -> { + if (event.getMessageAuthor().getIdAsString().equals(ctx.getAuthor().getIdAsString())) { + // If it's the same user, do the things + if (event.getMessageContent().equals("YES")) { + // ForceRemove the outfit + } else if (event.getMessageContent().equals("NO")) { + // Abort the operation. Delete the message. + + } else { + ctx.reply("Response must be YES or NO. In caps. Because shouting increases security."); + } + } + }).removeAfter(5, TimeUnit.MINUTES); + }); + }, () -> ctx.reply("An outfit with that ID was not found."))); + } +}