Merge pull request #48 from Fashionscape/dev
Outfit restoration and report attachments
This commit is contained in:
commit
d84959a25e
@ -17,9 +17,6 @@ import org.slf4j.LoggerFactory;
|
|||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
// TODO: auto-switching status messages.
|
|
||||||
// TODO: Add an official Logger --> logging to Discord, not console
|
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
@ -28,7 +25,6 @@ public class Main {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
String configLocation = Constants.BOT_FOLDER.concat(Constants.CONFIG_NAME);
|
String configLocation = Constants.BOT_FOLDER.concat(Constants.CONFIG_NAME);
|
||||||
BotConfig.initConfig(configLocation, false);
|
BotConfig.initConfig(configLocation, false);
|
||||||
// TODO: Use args to dictate newFiling. Also use args to dictate database setup.
|
|
||||||
|
|
||||||
FSDB.init();
|
FSDB.init();
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ import java.awt.*;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CreateGalleryCommand extends Command { // TODO: This command needs help.
|
public class CreateGalleryCommand extends Command {
|
||||||
@Override public String name() { return "Create Gallery"; }
|
@Override public String name() { return "Create Gallery"; }
|
||||||
@Override public String description() { return "Creates a channel gallery, tracking any posted images"; }
|
@Override public String description() { return "Creates a channel gallery, tracking any posted images"; }
|
||||||
@Override public String usage() { return "creategallery <String tag>"; }
|
@Override public String usage() { return "creategallery <String tag>"; }
|
||||||
@ -27,7 +27,7 @@ public class CreateGalleryCommand extends Command { // TODO: This command needs
|
|||||||
@Override
|
@Override
|
||||||
public void onCommand(CommandContext ctx) {
|
public void onCommand(CommandContext ctx) {
|
||||||
if (ctx.isPrivateMessage()) {
|
if (ctx.isPrivateMessage()) {
|
||||||
ctx.reply("This command can only be used in a server!"); // TODO: Stop this. Turn this into a preset no-no embed.
|
ctx.reply("This command can only be used in a server!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ctx.getArgs().length < 1) {
|
if (ctx.getArgs().length < 1) {
|
||||||
|
@ -49,7 +49,7 @@ public class OutfitCommand extends Command {
|
|||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 0:
|
case 0:
|
||||||
// Send one single random outfit of the given tag
|
// Send one single random outfit of the given tag
|
||||||
OutfitController.findRandomByTag(command).thenAccept(possibleOutfit -> { // TODO: Add an orElse case
|
OutfitController.findRandomByTag(command).thenAccept(possibleOutfit -> {
|
||||||
possibleOutfit.ifPresent(outfit -> {
|
possibleOutfit.ifPresent(outfit -> {
|
||||||
ctx.getApi().getUserById(outfit.getSubmitter()).thenAcceptAsync(user -> {
|
ctx.getApi().getUserById(outfit.getSubmitter()).thenAcceptAsync(user -> {
|
||||||
EmbedBuilder response = new EmbedBuilder()
|
EmbedBuilder response = new EmbedBuilder()
|
||||||
@ -91,7 +91,7 @@ public class OutfitCommand extends Command {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
ctx.reply("Improper command usage"); // TODO: Logging update reminder
|
ctx.reply("Improper command usage");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ public class StatsCommand extends Command {
|
|||||||
int userCount = ctx.getApi().getCachedUsers().size(); // Will these be accurate with sharding?
|
int userCount = ctx.getApi().getCachedUsers().size(); // Will these be accurate with sharding?
|
||||||
int serverCount = ctx.getApi().getServers().size();
|
int serverCount = ctx.getApi().getServers().size();
|
||||||
|
|
||||||
EmbedBuilder embed = new EmbedBuilder(); // TODO: Standard embeds yeah?
|
EmbedBuilder embed = new EmbedBuilder();
|
||||||
embed.setTitle("Stats");
|
embed.setTitle("Stats");
|
||||||
embed.addField("Users:", String.valueOf(userCount));
|
embed.addField("Users:", String.valueOf(userCount));
|
||||||
embed.addField("Servers:", String.valueOf(serverCount));
|
embed.addField("Servers:", String.valueOf(serverCount));
|
||||||
|
@ -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) {
|
public static CompletableFuture<Void> forceRemove(String id) {
|
||||||
return CompletableFuture.runAsync(() -> {
|
return CompletableFuture.runAsync(() -> {
|
||||||
try {
|
try {
|
||||||
@ -363,6 +375,7 @@ public class OutfitController {
|
|||||||
"meta = ?," +
|
"meta = ?," +
|
||||||
"updated = ?," +
|
"updated = ?," +
|
||||||
"featured = ?," +
|
"featured = ?," +
|
||||||
|
"deleted = ?," +
|
||||||
"display_count = ?" +
|
"display_count = ?" +
|
||||||
"WHERE id = ?",
|
"WHERE id = ?",
|
||||||
outfit.getLink(),
|
outfit.getLink(),
|
||||||
@ -371,6 +384,7 @@ public class OutfitController {
|
|||||||
outfit.getMeta(),
|
outfit.getMeta(),
|
||||||
outfit.getUpdated(),
|
outfit.getUpdated(),
|
||||||
outfit.isFeatured(),
|
outfit.isFeatured(),
|
||||||
|
outfit.isDeleted(),
|
||||||
outfit.getDisplayCount(),
|
outfit.getDisplayCount(),
|
||||||
outfit.getId());
|
outfit.getId());
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ public class ImgurAPIConnection {
|
|||||||
try (Response response = client.newCall(request).execute()) {
|
try (Response response = client.newCall(request).execute()) {
|
||||||
json = new JSONObject(response.body().string()).getJSONObject("data");
|
json = new JSONObject(response.body().string()).getJSONObject("data");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace(); // TODO: Do tha logging thang.
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,6 +66,7 @@ public class Guthix implements MessageCreateListener {
|
|||||||
addCommand(new ShowGalleriesCommand());
|
addCommand(new ShowGalleriesCommand());
|
||||||
addCommand(new EditMetaCommand());
|
addCommand(new EditMetaCommand());
|
||||||
addCommand(new BlacklistUserCommand());
|
addCommand(new BlacklistUserCommand());
|
||||||
|
addCommand(new RestoreOutfitCommand());
|
||||||
|
|
||||||
// General Commands
|
// General Commands
|
||||||
addCommand(new PingCommand());
|
addCommand(new PingCommand());
|
||||||
|
@ -19,7 +19,7 @@ class Registry {
|
|||||||
commandsMap = new HashMap<>();
|
commandsMap = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
Predicate<String> valueMatch(String input) { // TODO: Move to a helper class
|
Predicate<String> valueMatch(String input) {
|
||||||
return str -> str.equals(input);
|
return str -> str.equals(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import org.javacord.api.DiscordApi;
|
|||||||
import org.javacord.api.entity.channel.TextChannel;
|
import org.javacord.api.entity.channel.TextChannel;
|
||||||
import org.javacord.api.entity.message.Message;
|
import org.javacord.api.entity.message.Message;
|
||||||
import org.javacord.api.entity.message.MessageAuthor;
|
import org.javacord.api.entity.message.MessageAuthor;
|
||||||
|
import org.javacord.api.entity.message.MessageBuilder;
|
||||||
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||||
import org.javacord.api.event.message.MessageCreateEvent;
|
import org.javacord.api.event.message.MessageCreateEvent;
|
||||||
import org.javacord.api.listener.message.MessageCreateListener;
|
import org.javacord.api.listener.message.MessageCreateListener;
|
||||||
@ -37,6 +38,12 @@ public class ReportListener implements MessageCreateListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String content = message.getContent();
|
String content = message.getContent();
|
||||||
|
message.getAttachments().forEach(
|
||||||
|
attachment -> attachment.downloadAsImage().thenAcceptAsync(
|
||||||
|
image -> new MessageBuilder()
|
||||||
|
.addAttachment(image, "evidence")
|
||||||
|
.setContent("Report Evidence:")
|
||||||
|
.send(channel)));
|
||||||
|
|
||||||
message.delete().join();
|
message.delete().join();
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import org.javacord.api.listener.server.ServerJoinListener;
|
|||||||
|
|
||||||
public class ServerJoined implements ServerJoinListener {
|
public class ServerJoined implements ServerJoinListener {
|
||||||
|
|
||||||
public void onServerJoin(ServerJoinEvent event) { // TODO: This needs fixing yo
|
public void onServerJoin(ServerJoinEvent event) {
|
||||||
// db.newServerProcess(event.getServer());
|
// db.newServerProcess(event.getServer());
|
||||||
|
|
||||||
// EmbedBuilder embed = new EmbedBuilder()
|
// EmbedBuilder embed = new EmbedBuilder()
|
||||||
|
Loading…
Reference in New Issue
Block a user