From 1a7b6c6ada9cd75802fb4d6a9b0475f1c431aae2 Mon Sep 17 00:00:00 2001 From: Salmonllama Date: Sat, 4 Jul 2020 18:46:53 -0400 Subject: [PATCH] Update OutfitInfo Command for database changes --- .../commands/staff/OutfitInfoCommand.java | 37 +++++++++++-------- .../dev/salmonllama/fsbot/guthix/Guthix.java | 2 +- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/main/java/dev/salmonllama/fsbot/commands/staff/OutfitInfoCommand.java b/src/main/java/dev/salmonllama/fsbot/commands/staff/OutfitInfoCommand.java index 5b9bd96..769a6ff 100644 --- a/src/main/java/dev/salmonllama/fsbot/commands/staff/OutfitInfoCommand.java +++ b/src/main/java/dev/salmonllama/fsbot/commands/staff/OutfitInfoCommand.java @@ -6,6 +6,7 @@ package dev.salmonllama.fsbot.commands.staff; import dev.salmonllama.fsbot.config.BotConfig; +import dev.salmonllama.fsbot.database.controllers.OutfitController; import dev.salmonllama.fsbot.guthix.Command; import dev.salmonllama.fsbot.guthix.CommandContext; import dev.salmonllama.fsbot.guthix.CommandPermission; @@ -15,6 +16,7 @@ import dev.salmonllama.fsbot.utilities.database.DatabaseUtilities; import dev.salmonllama.fsbot.utilities.exceptions.DiscordError; import dev.salmonllama.fsbot.utilities.exceptions.OutfitNotFoundException; import org.javacord.api.entity.channel.TextChannel; +import org.javacord.api.entity.message.embed.EmbedBuilder; import java.util.ArrayList; import java.util.Arrays; @@ -28,28 +30,33 @@ public class OutfitInfoCommand extends Command { @Override public CommandPermission permission() { return new CommandPermission(PermissionType.ROLE, BotConfig.STAFF_ROLE); } @Override public Collection aliases() { return new ArrayList<>(Arrays.asList("outfitinfo", "oinfo")); } - private final DatabaseUtilities db; - - public OutfitInfoCommand(DatabaseUtilities db) { - this.db = db; - } - @Override public void onCommand(CommandContext ctx) { String[] args = ctx.getArgs(); - DiscordApi api = ctx.getApi(); - TextChannel channel = ctx.getChannel(); if (args.length != 1) { - channel.sendMessage(String.format("you did that wrong. bother %s to make these more specific.", api.getOwner().join().getDiscriminatedName())); + ctx.reply("You must supply an outfit ID."); return; } - try { - channel.sendMessage(db.getOutfitFromId(args[0]).generateInfo()); - } - catch (OutfitNotFoundException e) { - channel.sendMessage(new DiscordError(e.getMessage()).get()); - } + String id = args[0]; + OutfitController.findById(id).thenAcceptAsync(possibleOutfit -> { + possibleOutfit.ifPresentOrElse(outfit -> { + EmbedBuilder embed = new EmbedBuilder() + .setTitle("Outfit Info") + .setThumbnail(outfit.getLink()) + .setAuthor(ctx.getApi().getYourself()) + .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); + ctx.reply(embed); + }, () -> { + ctx.reply("Outfit not found"); + }); + }); } } diff --git a/src/main/java/dev/salmonllama/fsbot/guthix/Guthix.java b/src/main/java/dev/salmonllama/fsbot/guthix/Guthix.java index f6c6a9f..bf76765 100644 --- a/src/main/java/dev/salmonllama/fsbot/guthix/Guthix.java +++ b/src/main/java/dev/salmonllama/fsbot/guthix/Guthix.java @@ -58,7 +58,7 @@ public class Guthix implements MessageCreateListener { addCommand(new GetOutfitCommand()); addCommand(new RetagCommand(db)); addCommand(new RemoveOutfitCommand(db)); - addCommand(new OutfitInfoCommand(db)); + addCommand(new OutfitInfoCommand()); addCommand(new SetStatusCommand()); addCommand(new WelcomeMessageCommand()); addCommand(new ShowGalleriesCommand());