Start of CompletableFuture refactor

This commit is contained in:
Aleksei 2020-02-24 23:20:18 -05:00
parent 9cdf7e866c
commit 23d3c3c904
2 changed files with 9 additions and 19 deletions

View File

@ -17,6 +17,7 @@ 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.message.embed.EmbedBuilder; import org.javacord.api.entity.message.embed.EmbedBuilder;
import org.javacord.api.entity.server.Server; import org.javacord.api.entity.server.Server;
import org.javacord.api.util.logging.ExceptionLogger;
import java.awt.*; import java.awt.*;
import java.sql.SQLException; import java.sql.SQLException;
@ -51,15 +52,10 @@ public class CreateGalleryCommand extends Command { // TODO: This command needs
// Store the gallery channel in the database. // Store the gallery channel in the database.
String channelId = ctx.getChannel().getIdAsString(); String channelId = ctx.getChannel().getIdAsString();
try { if (GalleryController.galleryExists(channelId).join()) { // This is a value that is needed immediately.
if (GalleryController.galleryExists(channelId)) {
ctx.reply("A gallery already exists in this channel, can not create a new one."); ctx.reply("A gallery already exists in this channel, can not create a new one.");
return; return;
} }
} catch (SQLException e) {
ctx.reply(String.format("Error: %s", e.getMessage())); // TODO: error logging.
return;
}
String tag = ctx.getArgs()[0]; String tag = ctx.getArgs()[0];
@ -74,12 +70,7 @@ public class CreateGalleryCommand extends Command { // TODO: This command needs
ctx.getChannel().asServerTextChannel().ifPresent(channel -> gallery.channelName = channel.getName()); ctx.getChannel().asServerTextChannel().ifPresent(channel -> gallery.channelName = channel.getName());
try { GalleryController.insert(gallery).exceptionally(ExceptionLogger.get()); // Make a discord exception logger for the thingos
GalleryController.insert(gallery);
} catch(SQLException e) {
ctx.reply(String.format("Error: %s", e.getMessage())); // TODO: error logging.
return;
}
EmbedBuilder embed = new EmbedBuilder() EmbedBuilder embed = new EmbedBuilder()
.setColor(Color.GREEN) .setColor(Color.GREEN)

View File

@ -23,6 +23,7 @@ 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.util.logging.ExceptionLogger;
public class ShowGalleriesCommand extends Command { public class ShowGalleriesCommand extends Command {
@Override public String name() { return "Show Galleries"; } @Override public String name() { return "Show Galleries"; }
@ -39,13 +40,11 @@ public class ShowGalleriesCommand extends Command {
} }
ctx.getServer().ifPresent(server -> { ctx.getServer().ifPresent(server -> {
try { GalleryController.getGalleriesByServer(server.getIdAsString())
Collection<GalleryChannel> galleries = GalleryController.getGalleriesByServer(server.getIdAsString()); .exceptionally(ExceptionLogger.get())
.thenAccept(galleries -> {
ctx.reply(galleryEmbed(galleries, server)); ctx.reply(galleryEmbed(galleries, server));
} catch (SQLException e) { });
ctx.reply("An exception has occurred: " + e.getMessage());
}
}); });
} }