log errors to a channel
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 40s

This commit is contained in:
Lee 2024-07-04 06:55:56 +01:00
parent 09d850146a
commit 407ee6f1e9
13 changed files with 55 additions and 4 deletions

@ -1,12 +1,14 @@
package cc.fascinated.bat.common;
import cc.fascinated.bat.service.DiscordService;
import lombok.experimental.UtilityClass;
import lombok.extern.log4j.Log4j2;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
/**
* @author Fascinated (fascinated7)
*/
@UtilityClass
@Log4j2
public class ChannelUtils {
/**

@ -1,7 +1,9 @@
package cc.fascinated.bat.common;
import cc.fascinated.bat.config.Config;
import lombok.experimental.UtilityClass;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import java.time.LocalDateTime;
@ -50,8 +52,21 @@ public class EmbedUtils {
* @return the embed builder
*/
public static EmbedBuilder genericInteractionError(Exception ex) {
TextChannel channel = ChannelUtils.getTextChannel(Config.INSTANCE.getLogsChannel());
if (channel != null) {
channel.sendMessageEmbeds(EmbedUtils.errorEmbed()
.setDescription("""
An error has occurred while processing an interaction. Please check the logs for more information.
```java
%s
```""".formatted(ex.getLocalizedMessage()))
.build()).queue();
}
return EmbedUtils.errorEmbed()
.setDescription("An error occurred while processing your interaction. Please try again later.\n" +
"**Error:** ```java\n%s\n```" + ex.getLocalizedMessage());
.setDescription("""
An error has occurred while processing your interaction. Please check the logs for more information.
```java
%s
```""".formatted(ex.getLocalizedMessage()));
}
}

@ -1,8 +1,11 @@
package cc.fascinated.bat.common;
import lombok.experimental.UtilityClass;
/**
* @author Fascinated (fascinated7)
*/
@UtilityClass
public class EnumUtils {
/**
* Gets the name of the enum

@ -1,10 +1,13 @@
package cc.fascinated.bat.common;
import lombok.experimental.UtilityClass;
import java.awt.*;
/**
* @author Fascinated (fascinated7)
*/
@UtilityClass
public class HexColorUtils {
/**
* Checks if the given string is a hex color

@ -2,6 +2,7 @@ package cc.fascinated.bat.common;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser;
import lombok.experimental.UtilityClass;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Role;
@ -10,6 +11,7 @@ import java.util.Comparator;
/**
* @author Fascinated (fascinated7)
*/
@UtilityClass
public class MemberUtils {
/**
* Checks if a user has permission to edit another user

@ -1,11 +1,14 @@
package cc.fascinated.bat.common;
import lombok.experimental.UtilityClass;
import java.text.DecimalFormat;
import java.util.Locale;
/**
* @author Fascinated (fascinated7)
*/
@UtilityClass
public class NumberFormatter {
/**
* The suffixes for the numbers

@ -3,6 +3,7 @@ package cc.fascinated.bat.common;
import cc.fascinated.bat.BatApplication;
import cc.fascinated.bat.model.token.paste.PasteUploadToken;
import lombok.SneakyThrows;
import lombok.experimental.UtilityClass;
import lombok.extern.log4j.Log4j2;
import java.net.URI;
@ -13,6 +14,7 @@ import java.net.http.HttpResponse;
/**
* @author Fascinated (fascinated7)
*/
@UtilityClass
@Log4j2
public class PasteUtils {
private static final String PASTE_URL = "https://paste.fascinated.cc/";

@ -1,12 +1,14 @@
package cc.fascinated.bat.common;
import cc.fascinated.bat.model.BatGuild;
import lombok.experimental.UtilityClass;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Role;
/**
* @author Fascinated (fascinated7)
*/
@UtilityClass
public class RoleUtils {
/**
* Checks if a member has permission to give the role to another member

@ -3,6 +3,7 @@ package cc.fascinated.bat.common;
import cc.fascinated.bat.model.BatUser;
import cc.fascinated.bat.service.SpotifyService;
import lombok.NonNull;
import lombok.experimental.UtilityClass;
import lombok.extern.log4j.Log4j2;
import se.michaelthelin.spotify.model_objects.miscellaneous.CurrentlyPlaying;
import se.michaelthelin.spotify.model_objects.specification.Track;
@ -10,6 +11,7 @@ import se.michaelthelin.spotify.model_objects.specification.Track;
/**
* @author Fascinated (fascinated7)
*/
@UtilityClass
@Log4j2
public class SpotifyUtils {
/**

@ -1,8 +1,11 @@
package cc.fascinated.bat.common;
import lombok.experimental.UtilityClass;
/**
* @author Fascinated (fascinated7)
*/
@UtilityClass
public class StringUtils {
/**
* Generates a random string

@ -1,12 +1,14 @@
package cc.fascinated.bat.common;
import cc.fascinated.bat.service.DiscordService;
import lombok.experimental.UtilityClass;
import lombok.extern.log4j.Log4j2;
import net.dv8tion.jda.api.entities.User;
/**
* @author Fascinated (fascinated7)
*/
@UtilityClass
@Log4j2
public class UserUtils {
/**

@ -23,6 +23,11 @@ public class Config {
*/
private final String adminGuild;
/**
* The ID of the logs channel
*/
private final String logsChannel;
static {
// Are we running on production?
String appEnv = System.getenv("APP_ENV");
@ -30,8 +35,12 @@ public class Config {
}
@Autowired
public Config(@Value("${bat.admin-guild}") String adminGuild) {
public Config(
@Value("${bat.admin-guild}") String adminGuild,
@Value("${bat.logs-channel}") String logsChannel
) {
INSTANCE = this;
this.adminGuild = adminGuild;
this.logsChannel = logsChannel;
}
}

@ -6,7 +6,10 @@ discord:
bat:
# This is where commands will be registered (whilst in development mode)
# also where bot owner only commands will be registered
admin-guild: 1203163422498361404
admin-guild: set me
# This is the guild where the bot will log errors and other information
logs-channel: set me
# Sentry Configuration
sentry: