Added Restore Command
This commit is contained in:
parent
437512b0b9
commit
7d0b20b2c6
@ -0,0 +1,98 @@
|
||||
package dev.salmonllama.fsbot.commands.staff;
|
||||
|
||||
import com.vdurmont.emoji.EmojiParser;
|
||||
import dev.salmonllama.fsbot.config.BotConfig;
|
||||
import dev.salmonllama.fsbot.database.controllers.OutfitController;
|
||||
import dev.salmonllama.fsbot.guthix.*;
|
||||
import org.javacord.api.entity.channel.TextChannel;
|
||||
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
public class RestoreOutfitCommand extends Command {
|
||||
@Override public String name() { return "Restore Outfit"; }
|
||||
@Override public String description() { return "Restores a previously deleted outfit"; }
|
||||
@Override public String usage() { return "restore [outfit ID]"; }
|
||||
@Override public CommandCategory category() { return CommandCategory.STAFF; }
|
||||
@Override public CommandPermission permission() { return new CommandPermission(PermissionType.STATIC, "staff"); }
|
||||
@Override public List<String> aliases() { return Arrays.asList("restoreoutfit", "restore"); }
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandContext ctx) {
|
||||
String[] args = ctx.getArgs();
|
||||
TextChannel channel = ctx.getChannel();
|
||||
long authorId = ctx.getUser().getId();
|
||||
|
||||
if (args.length != 1) {
|
||||
channel.sendMessage("You must supply a valid outfit ID.");
|
||||
return;
|
||||
}
|
||||
|
||||
// get the outfit, confirm restoration through reaction.
|
||||
String outfitId = args[0];
|
||||
OutfitController.findById(outfitId).thenAcceptAsync(possibleOutfit -> possibleOutfit.ifPresentOrElse(outfit -> {
|
||||
// Send outfit info, react with selectors, add a listener to the message
|
||||
EmbedBuilder embed = new EmbedBuilder()
|
||||
.setTitle("Really restore this outfit?")
|
||||
.setThumbnail(outfit.getLink())
|
||||
.setAuthor(ctx.getApi().getUserById(outfit.getSubmitter()).join())
|
||||
.setUrl(outfit.getLink())
|
||||
.setFooter(String.format("Tag: %s", outfit.getTag()))
|
||||
.addField("Added", outfit.getCreated().toString(), true)
|
||||
.addField("Updated", outfit.getUpdated().toString(), true)
|
||||
.addField("Submitted by:", ctx.getApi().getUserById(outfit.getSubmitter()).join().getDiscriminatedName())
|
||||
.addField("Deleted", outfit.isDeleted() ? "True" : "False", true)
|
||||
.addField("Featured", outfit.isFeatured() ? "True" : "False", true)
|
||||
.addField("Deleted by:", "Lily <3", true);
|
||||
|
||||
ctx.reply(embed).thenAcceptAsync(msg -> {
|
||||
msg.addReaction(EmojiParser.parseToUnicode(":white_check_mark:"));
|
||||
msg.addReaction(EmojiParser.parseToUnicode(":octagonal_sign:"));
|
||||
|
||||
msg.addReactionAddListener(event -> {
|
||||
if (event.getUserId() != authorId) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getEmoji().equalsEmoji(EmojiParser.parseToUnicode(":white_check_mark:"))) {
|
||||
// Restore the outfit
|
||||
OutfitController.restore(outfit);
|
||||
|
||||
EmbedBuilder response = new EmbedBuilder()
|
||||
.setTitle("Outfit Restored!")
|
||||
.setDescription(String.format("Outfit %s is now active again!", outfit.getId()));
|
||||
|
||||
msg.delete();
|
||||
ctx.reply(response);
|
||||
|
||||
EmbedBuilder log = new EmbedBuilder()
|
||||
.setTitle("Outfit Restored as Active")
|
||||
.setThumbnail(outfit.getLink())
|
||||
.setColor(Color.BLUE)
|
||||
.addField("Restored By:", ctx.getAuthor().getDiscriminatedName());
|
||||
|
||||
ctx.getApi().getServerTextChannelById(BotConfig.OUTFIT_LOG).ifPresent(
|
||||
chnl -> chnl.sendMessage(log)
|
||||
);
|
||||
|
||||
} else if (event.getEmoji().equalsEmoji(EmojiParser.parseToUnicode(":octagonal_sign:"))) {
|
||||
// Do nothing
|
||||
EmbedBuilder response = new EmbedBuilder()
|
||||
.setTitle("Restoration Aborted")
|
||||
.setDescription(String.format("No modifications were made to %s", outfit.getId()));
|
||||
|
||||
ctx.reply(response);
|
||||
}
|
||||
});
|
||||
});
|
||||
}, () -> {
|
||||
EmbedBuilder response = new EmbedBuilder()
|
||||
.setTitle("Outfit not Found")
|
||||
.setDescription(String.format("ID %s does not exist", outfitId));
|
||||
|
||||
ctx.reply(response);
|
||||
}));
|
||||
}
|
||||
}
|
@ -200,6 +200,18 @@ public class OutfitController {
|
||||
});
|
||||
}
|
||||
|
||||
public static CompletableFuture<Void> restore(Outfit outfit) {
|
||||
return CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
Outfit newOutfit = new Outfit.OutfitBuilder(outfit).setDeleted(false).build();
|
||||
System.out.println(newOutfit.isDeleted());
|
||||
updateExec(newOutfit);
|
||||
} catch (SQLException e) {
|
||||
throw new CompletionException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static CompletableFuture<Void> forceRemove(String id) {
|
||||
return CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
@ -363,6 +375,7 @@ public class OutfitController {
|
||||
"meta = ?," +
|
||||
"updated = ?," +
|
||||
"featured = ?," +
|
||||
"deleted = ?," +
|
||||
"display_count = ?" +
|
||||
"WHERE id = ?",
|
||||
outfit.getLink(),
|
||||
@ -371,6 +384,7 @@ public class OutfitController {
|
||||
outfit.getMeta(),
|
||||
outfit.getUpdated(),
|
||||
outfit.isFeatured(),
|
||||
outfit.isDeleted(),
|
||||
outfit.getDisplayCount(),
|
||||
outfit.getId());
|
||||
}
|
||||
|
@ -66,6 +66,7 @@ public class Guthix implements MessageCreateListener {
|
||||
addCommand(new ShowGalleriesCommand());
|
||||
addCommand(new EditMetaCommand());
|
||||
addCommand(new BlacklistUserCommand());
|
||||
addCommand(new RestoreOutfitCommand());
|
||||
|
||||
// General Commands
|
||||
addCommand(new PingCommand());
|
||||
|
Loading…
Reference in New Issue
Block a user