Skip to content

Commit

Permalink
Added Proper Error Messages to the KawaiiAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
beanbeanjuice committed Jun 21, 2024
1 parent a41202e commit 55db67e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 54 deletions.
60 changes: 7 additions & 53 deletions src/main/java/com/beanbeanjuice/cafebot/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.beanbeanjuice.cafebot.utility.section.twitch.TwitchHandler;
import com.beanbeanjuice.cafeapi.wrapper.CafeAPI;
import com.beanbeanjuice.cafeapi.wrapper.requests.RequestLocation;
import lombok.Getter;
import lombok.Setter;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.OnlineStatus;
Expand All @@ -44,20 +46,20 @@ public class Bot {
public static final String BOT_USER_AGENT = "java:com.beanbeanjuice.cafeBot:" + BOT_VERSION;
public static final String TWITCH_ACCESS_TOKEN = System.getenv("CAFEBOT_TWITCH_ACCESS_TOKEN");
private static final RequestLocation location = RequestLocation.valueOf(System.getenv("CAFEBOT_REQUEST_LOCATION"));
private static JDA bot;
@Getter private static JDA bot;

// API
private static CafeAPI cafeAPI;
@Getter @Setter private static CafeAPI cafeAPI;

// Internal Items
private static LogManager logger;
@Getter private static LogManager logger;
private static final String HOME_GUILD_ID = System.getenv("CAFEBOT_GUILD_ID");
private static final String HOME_GUILD_LOG_CHANNEL_ID = System.getenv("CAFEBOT_GUILD_LOG_CHANNEL_ID");
private static final String HOME_GUILD_WEBHOOK_URL = System.getenv("CAFEBOT_GUILD_WEBHOOK_URL");

// Handlers
private static CommandHandler commandHandler;
private static AIResponseListener aiResponseListener;
@Getter private static CommandHandler commandHandler;
@Getter private static AIResponseListener aiResponseListener;

// Additional Items
public static int commandsRun = 0;
Expand Down Expand Up @@ -133,52 +135,4 @@ public static void main(String[] args) throws LoginException, InterruptedExcepti
new Bot();
}

/**
* @return The current {@link JDA bot}.
*/
@NotNull
public static JDA getBot() {
return bot;
}

/**
* @return The current {@link LogManager}.
*/
@NotNull
public static LogManager getLogger() {
return logger;
}

/**
* @return The current {@link CafeAPI}.
*/
@NotNull
public static CafeAPI getCafeAPI() {
return cafeAPI;
}

/**
* Sets the current {@link CafeAPI}.
* @param newCafeAPI The new {@link CafeAPI}.
*/
public static void setCafeAPI(@NotNull CafeAPI newCafeAPI) {
cafeAPI = newCafeAPI;
}

/**
* @return The current {@link CommandHandler}.
*/
@NotNull
public static CommandHandler getCommandHandler() {
return commandHandler;
}

/**
* @return The current {@link AIResponseListener}.
*/
@NotNull
public static AIResponseListener getAIResponseListener() {
return aiResponseListener;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.io.InputStream;
import java.net.URISyntaxException;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* A {@link RequestBuilder} used to build {@link Request} objects.
Expand Down Expand Up @@ -70,7 +72,7 @@ public Optional<Request> build() {
return Optional.of(new Request(statusCode, new ObjectMapper().readTree(inputStream)));
}
} catch (URISyntaxException | IOException e) {
e.printStackTrace(); // TODO: Better logging.
Logger.getLogger(RequestBuilder.class.getName()).log(Level.WARNING, "Error building request: " + e.getMessage());
return Optional.empty();
}
}
Expand Down

0 comments on commit 55db67e

Please sign in to comment.