Update OutfitInfo Command for database changes

This commit is contained in:
Salmonllama 2020-07-04 18:46:53 -04:00
parent 5831720ca5
commit 1a7b6c6ada
2 changed files with 23 additions and 16 deletions

View File

@ -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<String> 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");
});
});
}
}

View File

@ -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());