Merge pull request #41 from Fashionscape/dev
Code cleaning, proper logging, remove useless classes
This commit is contained in:
commit
a017bd4e00
@ -34,12 +34,13 @@ public class Main {
|
||||
|
||||
new DiscordApiBuilder().setToken(BotConfig.TOKEN).login().thenAccept(api -> {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
Guthix guthix = new Guthix(api);
|
||||
|
||||
// Register listeners
|
||||
api.addMessageCreateListener(new ImageListener());
|
||||
api.addServerMemberJoinListener(new NewMemberListener());
|
||||
api.addServerJoinListener(new ServerJoined(api));
|
||||
api.addServerJoinListener(new ServerJoined());
|
||||
api.addMessageCreateListener(new ThumbsListener());
|
||||
api.addMessageCreateListener(new AchievementListener());
|
||||
api.addMessageCreateListener(new ReportListener());
|
||||
|
@ -9,9 +9,7 @@ import dev.salmonllama.fsbot.guthix.*;
|
||||
import org.javacord.api.DiscordApi;
|
||||
import org.javacord.api.entity.channel.TextChannel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class InviteCommand extends Command {
|
||||
|
@ -6,9 +6,7 @@
|
||||
package dev.salmonllama.fsbot.commands.general;
|
||||
|
||||
import dev.salmonllama.fsbot.database.controllers.OutfitController;
|
||||
import dev.salmonllama.fsbot.database.models.Outfit;
|
||||
import dev.salmonllama.fsbot.guthix.*;
|
||||
import org.javacord.api.entity.message.Message;
|
||||
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||
import org.javacord.api.util.logging.ExceptionLogger;
|
||||
|
||||
@ -16,7 +14,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class OutfitCommand extends Command {
|
||||
private final int MAX_OUTFITS = 5;
|
||||
@ -211,9 +208,4 @@ public class OutfitCommand extends Command {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private CompletableFuture<Message> sendOutfit(Outfit outfit) {
|
||||
// TODO: Replace sending with this
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import dev.salmonllama.fsbot.guthix.*;
|
||||
import dev.salmonllama.fsbot.listeners.ForceDeleteAttachedListener;
|
||||
import org.javacord.api.entity.message.MessageBuilder;
|
||||
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||
import org.javacord.api.event.message.MessageCreateEvent;
|
||||
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -10,9 +10,7 @@ import dev.salmonllama.fsbot.guthix.*;
|
||||
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class SetStatusCommand extends Command {
|
||||
|
@ -6,7 +6,6 @@
|
||||
package dev.salmonllama.fsbot.database.controllers;
|
||||
|
||||
import dev.salmonllama.fsbot.database.FSDB;
|
||||
import dev.salmonllama.fsbot.database.models.ServerBlacklist;
|
||||
import dev.salmonllama.fsbot.database.models.UserBlacklist;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
|
@ -8,7 +8,6 @@ package dev.salmonllama.fsbot.database.models;
|
||||
import dev.salmonllama.fsbot.database.DatabaseModel;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
|
||||
public class StaticPermission extends DatabaseModel {
|
||||
private String userId;
|
||||
|
@ -17,6 +17,7 @@ public class UserBlacklist extends DatabaseModel {
|
||||
private UserBlacklist(Builder builder) {
|
||||
this.id = builder.id;
|
||||
this.reason = builder.reason;
|
||||
this.added = builder.added;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
|
@ -6,8 +6,6 @@
|
||||
package dev.salmonllama.fsbot.endpoints.scapefashion;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
@ -18,14 +16,13 @@ import java.net.http.HttpResponse;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class ScapeFashionConnection {
|
||||
// TODO: Refactor this for request-response based interactions
|
||||
private final String RS3_REQUEST_URL = "https://api.rune.scape.fashion";
|
||||
private final String RS3_LINK_URL = "https://rune.scape.fashion";
|
||||
|
||||
private final String OSRS_REQUEST_URL = "https://api.scape.fashion";
|
||||
private final String OSRS_LINK_URL = "https://scape.fashion";
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ScapeFashionConnection.class);
|
||||
|
||||
public ScapeFashionConnection() {}
|
||||
|
||||
// Uses the color endpoint to search for items
|
||||
|
@ -6,6 +6,7 @@
|
||||
package dev.salmonllama.fsbot.exceptions;
|
||||
|
||||
public class FailedUploadException extends Exception {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private String message;
|
||||
|
||||
public FailedUploadException(String imageLink) {
|
||||
|
@ -8,6 +8,7 @@ package dev.salmonllama.fsbot.exceptions;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class UnknownParameterException extends SQLException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private String message;
|
||||
|
||||
public UnknownParameterException(Object param) {
|
||||
|
@ -45,6 +45,8 @@ public class Guthix implements MessageCreateListener {
|
||||
}
|
||||
|
||||
public void initCommands() {
|
||||
logger.info("Initializing commands...");
|
||||
|
||||
// Developer Commands
|
||||
addCommand(new TestCommand());
|
||||
addCommand(new CreateGalleryCommand());
|
||||
@ -98,6 +100,8 @@ public class Guthix implements MessageCreateListener {
|
||||
addCommand(new Rs3MainhandCommand());
|
||||
addCommand(new Rs3OffhandCommand());
|
||||
addCommand(new Rs3TwohandedCommand());
|
||||
|
||||
logger.info("Command initialization complete!");
|
||||
}
|
||||
|
||||
public void addCommand(Command cmd) {
|
||||
@ -159,5 +163,6 @@ public class Guthix implements MessageCreateListener {
|
||||
}
|
||||
|
||||
cmd.invoke(ctx);
|
||||
logger.info(String.format("Processed command from %s.", author.getDiscriminatedName()));
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import org.javacord.api.listener.message.MessageCreateListener;
|
||||
|
||||
public class ForceDeleteAttachedListener implements MessageCreateListener {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private CommandContext ctx;
|
||||
|
||||
public ForceDeleteAttachedListener(CommandContext ctx) {
|
||||
|
@ -5,18 +5,11 @@
|
||||
|
||||
package dev.salmonllama.fsbot.listeners;
|
||||
|
||||
import org.javacord.api.DiscordApi;
|
||||
import org.javacord.api.event.server.ServerJoinEvent;
|
||||
import org.javacord.api.listener.server.ServerJoinListener;
|
||||
|
||||
public class ServerJoined implements ServerJoinListener {
|
||||
|
||||
private DiscordApi api;
|
||||
|
||||
public ServerJoined(DiscordApi api) {
|
||||
this.api = api;
|
||||
}
|
||||
|
||||
public void onServerJoin(ServerJoinEvent event) { // TODO: This needs fixing yo
|
||||
// db.newServerProcess(event.getServer());
|
||||
|
||||
|
@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020. Aleksei Gryczewski
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
package dev.salmonllama.fsbot.logging;
|
||||
|
||||
import dev.salmonllama.fsbot.config.BotConfig;
|
||||
import org.javacord.api.DiscordApi;
|
||||
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class Logger {
|
||||
|
||||
private final DiscordApi api;
|
||||
|
||||
private final String OUTFIT_LOG = BotConfig.OUTFIT_LOG;
|
||||
private final String REPORT_LOG = BotConfig.REPORT_LOG;
|
||||
private final String JOIN_LOG = BotConfig.JOIN_LOG;
|
||||
private final String ACTIVITY_LOG = BotConfig.ACTIVITY_LOG;
|
||||
private final String SALMONLLAMA = BotConfig.BOT_OWNER;
|
||||
|
||||
private EmbedBuilder reportEmbed;
|
||||
|
||||
private EmbedBuilder errorEmbed;
|
||||
|
||||
public Logger(DiscordApi api) {
|
||||
this.api = api;
|
||||
}
|
||||
|
||||
public void logOutfit() {
|
||||
api.getServerTextChannelById(OUTFIT_LOG).ifPresentOrElse(channel -> {
|
||||
// Log the thing
|
||||
channel.sendMessage("outfit");
|
||||
}, () -> {
|
||||
// DM me
|
||||
api.getUserById(SALMONLLAMA).thenAcceptAsync(user -> {
|
||||
user.sendMessage("Outfit log failed and was not found");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public void logReport() {
|
||||
api.getServerTextChannelById(REPORT_LOG).ifPresentOrElse(channel -> {
|
||||
// Log the thing
|
||||
channel.sendMessage("report");
|
||||
}, () -> {
|
||||
// DM me
|
||||
api.getUserById(SALMONLLAMA).thenAcceptAsync(user -> {
|
||||
user.sendMessage("Report log failed and was not found");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public void logError(String errorMsg) {
|
||||
api.getServerTextChannelById(ACTIVITY_LOG).ifPresentOrElse(channel -> {
|
||||
// Log the thing
|
||||
channel.sendMessage("error");
|
||||
}, () -> {
|
||||
// DM me
|
||||
api.getUserById(SALMONLLAMA).thenAcceptAsync(user -> {
|
||||
user.sendMessage("Error log failed and was not found");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public void logMovement() {
|
||||
api.getServerTextChannelById(JOIN_LOG).ifPresentOrElse(channel -> {
|
||||
// Log the thing
|
||||
channel.sendMessage("User joined/Left");
|
||||
}, () -> {
|
||||
// DM me
|
||||
api.getUserById(SALMONLLAMA).thenAcceptAsync(user -> {
|
||||
user.sendMessage("Movement log failed and was not found");
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020. Aleksei Gryczewski
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
package dev.salmonllama.fsbot.logging;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public enum ResponseType {
|
||||
ERROR (Color.RED, "Error"),
|
||||
WARN (Color.YELLOW, "Warning"),
|
||||
INFO (Color.BLUE, "Info"),
|
||||
LOG (Color.GRAY, "Log");
|
||||
|
||||
private Color color;
|
||||
private String title;
|
||||
ResponseType(Color color, String title) {
|
||||
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020. Aleksei Gryczewski
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
package dev.salmonllama.fsbot.logging;
|
||||
|
||||
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||
|
||||
public class StandardEmbed extends EmbedBuilder {
|
||||
public StandardEmbed() {
|
||||
super();
|
||||
}
|
||||
}
|
@ -10,7 +10,6 @@ import dev.salmonllama.fsbot.guthix.CommandContext;
|
||||
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class DiscordUtilities {
|
||||
public static void handleException(Exception e, CommandContext ctx) {
|
||||
|
@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020. Aleksei Gryczewski
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
package dev.salmonllama.fsbot.utilities.exceptions;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DiscordException {
|
||||
|
||||
private Color color;
|
||||
private String message;
|
||||
private String footer;
|
||||
private String title;
|
||||
|
||||
DiscordException(String title, String message, String footer, Color color) {
|
||||
this.title = title;
|
||||
this.message = message;
|
||||
this.footer = footer;
|
||||
this.color = color;
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
package dev.salmonllama.fsbot.utilities.exceptions;
|
||||
|
||||
public class OutfitNotFoundException extends Exception {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
|
@ -7,6 +7,8 @@ package dev.salmonllama.fsbot.utilities.exceptions;
|
||||
|
||||
public class TagNotFoundException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "That tag was not found, check your spelling and try again.";
|
||||
|
@ -20,7 +20,7 @@ public class Warning {
|
||||
|
||||
public EmbedBuilder sendWarning() {
|
||||
EmbedBuilder warning = new EmbedBuilder()
|
||||
.setColor(Color.YELLOW)
|
||||
.setColor(embedColor)
|
||||
.setFooter(embedFooter)
|
||||
.addField("WARNING", embedWarning);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user