Updated outfit retag command
This commit is contained in:
parent
74d4c3c4ce
commit
cf698be97e
@ -7,18 +7,17 @@ package dev.salmonllama.fsbot.commands.staff;
|
|||||||
|
|
||||||
import com.vdurmont.emoji.EmojiParser;
|
import com.vdurmont.emoji.EmojiParser;
|
||||||
import dev.salmonllama.fsbot.config.BotConfig;
|
import dev.salmonllama.fsbot.config.BotConfig;
|
||||||
|
import dev.salmonllama.fsbot.database.controllers.OutfitController;
|
||||||
|
import dev.salmonllama.fsbot.database.models.Outfit;
|
||||||
import dev.salmonllama.fsbot.guthix.Command;
|
import dev.salmonllama.fsbot.guthix.Command;
|
||||||
import dev.salmonllama.fsbot.guthix.CommandContext;
|
import dev.salmonllama.fsbot.guthix.CommandContext;
|
||||||
import dev.salmonllama.fsbot.guthix.CommandPermission;
|
import dev.salmonllama.fsbot.guthix.CommandPermission;
|
||||||
import dev.salmonllama.fsbot.guthix.PermissionType;
|
import dev.salmonllama.fsbot.guthix.PermissionType;
|
||||||
import org.javacord.api.entity.channel.TextChannel;
|
import org.javacord.api.entity.channel.TextChannel;
|
||||||
import org.javacord.api.entity.user.User;
|
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||||
import dev.salmonllama.fsbot.listeners.ReactionRetagConfirmationListener;
|
|
||||||
import dev.salmonllama.fsbot.utilities.Outfit;
|
|
||||||
import dev.salmonllama.fsbot.utilities.database.DatabaseUtilities;
|
|
||||||
import dev.salmonllama.fsbot.utilities.exceptions.DiscordError;
|
|
||||||
import dev.salmonllama.fsbot.utilities.exceptions.OutfitNotFoundException;
|
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -31,34 +30,90 @@ public class RetagCommand extends Command {
|
|||||||
@Override public CommandPermission permission() { return new CommandPermission(PermissionType.ROLE, BotConfig.STAFF_ROLE); }
|
@Override public CommandPermission permission() { return new CommandPermission(PermissionType.ROLE, BotConfig.STAFF_ROLE); }
|
||||||
@Override public Collection<String> aliases() { return new ArrayList<>(Collections.singletonList("retag")); }
|
@Override public Collection<String> aliases() { return new ArrayList<>(Collections.singletonList("retag")); }
|
||||||
|
|
||||||
private final DatabaseUtilities db;
|
|
||||||
|
|
||||||
public RetagCommand(DatabaseUtilities db) {
|
|
||||||
this.db = db;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(CommandContext ctx) {
|
public void onCommand(CommandContext ctx) {
|
||||||
String[] args = ctx.getArgs();
|
String[] args = ctx.getArgs();
|
||||||
TextChannel channel = ctx.getChannel();
|
TextChannel channel = ctx.getChannel();
|
||||||
User author = ctx.getUser();
|
long authorId = ctx.getUser().getId();
|
||||||
|
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
channel.sendMessage("You did that wrong mate. check the help command.");
|
channel.sendMessage("Improper usage");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// Get the outfit, confirm update through reaction
|
||||||
Outfit outfit = this.db.getOutfitFromId(args[0]);
|
String outfitId = args[0];
|
||||||
|
String newTag = args[1];
|
||||||
|
|
||||||
channel.sendMessage(outfit.generateInfo().setTitle(String.format("Update tag to %s?", args[1]))).thenAcceptAsync(message -> {
|
OutfitController.findById(outfitId).thenAcceptAsync(possibleOutfit -> {
|
||||||
message.addReaction(EmojiParser.parseToUnicode(":white_check_mark:"));
|
possibleOutfit.ifPresentOrElse(outfit -> {
|
||||||
message.addReaction(EmojiParser.parseToUnicode(":octagonal_sign:"));
|
// Send info, confirmation, and add reaction listener
|
||||||
message.addReactionAddListener(new ReactionRetagConfirmationListener(author, message, outfit, db, outfit.getTag(), args[1]));
|
EmbedBuilder response = new EmbedBuilder()
|
||||||
|
.setTitle("Confirm Tag Edit")
|
||||||
|
.setThumbnail(outfit.getLink())
|
||||||
|
.setAuthor(ctx.getApi().getUserById(outfit.getSubmitter()).join())
|
||||||
|
.setUrl(outfit.getLink())
|
||||||
|
.addField("Current Tag:", outfit.getTag())
|
||||||
|
.addField("New Tag:", newTag);
|
||||||
|
|
||||||
|
ctx.reply(response).thenAcceptAsync(msg -> {
|
||||||
|
msg.addReaction(EmojiParser.parseToUnicode(":white_check_mark:"));
|
||||||
|
msg.addReaction(EmojiParser.parseToUnicode(":octagonal_sign:"));
|
||||||
|
|
||||||
|
msg.addReactionAddListener(event -> {
|
||||||
|
if (event.getUser().getId() != authorId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.getEmoji().equalsEmoji(EmojiParser.parseToUnicode(":white_check_mark:"))) {
|
||||||
|
// Update the outfit
|
||||||
|
Outfit newOutfit = new Outfit.OutfitBuilder(outfit)
|
||||||
|
.setTag(newTag)
|
||||||
|
.setUpdated(new Timestamp(System.currentTimeMillis()))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
OutfitController.update(newOutfit).thenAcceptAsync((Void) -> {
|
||||||
|
EmbedBuilder embed = new EmbedBuilder()
|
||||||
|
.setTitle("Outfit retagged successfully!")
|
||||||
|
.setDescription(String.format("Outfit %s will now display as %s", newOutfit.getId(), newOutfit.getTag()));
|
||||||
|
|
||||||
|
msg.delete();
|
||||||
|
ctx.reply(embed);
|
||||||
|
// TODO: Log the action in FSBot-log
|
||||||
|
});
|
||||||
|
} else if (event.getEmoji().equalsEmoji(EmojiParser.parseToUnicode(":octagonal_sign:"))) {
|
||||||
|
// Do nothing
|
||||||
|
msg.delete();
|
||||||
|
EmbedBuilder embed = new EmbedBuilder()
|
||||||
|
.setTitle("Update Cancelled")
|
||||||
|
.setDescription("No modifications were made");
|
||||||
|
|
||||||
|
ctx.reply(embed);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}, () -> {
|
||||||
|
// Err, outfit not found
|
||||||
|
EmbedBuilder response = new EmbedBuilder()
|
||||||
|
.setTitle("Error occurred")
|
||||||
|
.setDescription("That ID was not found in the database")
|
||||||
|
.setColor(Color.RED);
|
||||||
|
|
||||||
|
ctx.reply(response);
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
catch (OutfitNotFoundException e) {
|
|
||||||
channel.sendMessage(new DiscordError(e.getMessage()).get());
|
// try {
|
||||||
}
|
// Outfit outfit = this.db.getOutfitFromId(args[0]);
|
||||||
|
//
|
||||||
|
// channel.sendMessage(outfit.generateInfo().setTitle(String.format("Update tag to %s?", args[1]))).thenAcceptAsync(message -> {
|
||||||
|
// message.addReaction(EmojiParser.parseToUnicode(":white_check_mark:"));
|
||||||
|
// message.addReaction(EmojiParser.parseToUnicode(":octagonal_sign:"));
|
||||||
|
// message.addReactionAddListener(new ReactionRetagConfirmationListener(author, message, outfit, db, outfit.getTag(), args[1]));
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// catch (OutfitNotFoundException e) {
|
||||||
|
// channel.sendMessage(new DiscordError(e.getMessage()).get());
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user