Files
Bat/src/main/java/cc/fascinated/bat/common/EmbedUtils.java

74 lines
2.1 KiB
Java
Raw Normal View History

2024-06-24 13:56:01 +01:00
package cc.fascinated.bat.common;
2024-07-04 06:55:56 +01:00
import cc.fascinated.bat.config.Config;
2024-06-25 11:14:12 +01:00
import lombok.experimental.UtilityClass;
2024-06-24 13:56:01 +01:00
import net.dv8tion.jda.api.EmbedBuilder;
2024-07-04 06:55:56 +01:00
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
2024-06-24 13:56:01 +01:00
import java.time.LocalDateTime;
/**
* @author Fascinated (fascinated7)
*/
2024-06-25 11:14:12 +01:00
@UtilityClass
2024-06-24 13:56:01 +01:00
public class EmbedUtils {
/**
* Builds a generic embed
*
* @return the embed builder
*/
2024-06-25 13:59:02 +01:00
public static EmbedBuilder genericEmbed() {
2024-06-24 13:56:01 +01:00
return new EmbedBuilder()
.setTimestamp(LocalDateTime.now())
.setColor(Colors.DEFAULT);
2024-06-24 13:56:01 +01:00
}
/**
* Builds an error embed
*
* @return the embed builder
*/
2024-06-25 13:59:02 +01:00
public static EmbedBuilder errorEmbed() {
2024-06-24 13:56:01 +01:00
return new EmbedBuilder()
.setTimestamp(LocalDateTime.now())
.setColor(Colors.ERROR);
2024-06-24 13:56:01 +01:00
}
/**
* Builds a success embed
*
* @return the embed builder
*/
2024-06-25 13:59:02 +01:00
public static EmbedBuilder successEmbed() {
2024-06-24 13:56:01 +01:00
return new EmbedBuilder()
.setTimestamp(LocalDateTime.now())
.setColor(Colors.SUCCESS);
2024-06-24 13:56:01 +01:00
}
/**
* Builds a generic interaction error embed
*
2024-07-05 23:35:41 +01:00
* @param ex the exceptionk
* @return the embed builder
*/
public static EmbedBuilder genericInteractionError(Exception ex) {
2024-07-04 06:55:56 +01:00
TextChannel channel = ChannelUtils.getTextChannel(Config.INSTANCE.getLogsChannel());
2024-07-05 23:35:41 +01:00
EmbedBuilder embed = errorEmbed()
.setDescription("""
An error has occurred while processing %s interaction. If this issue persists, please contact the developers.
Cause: `%s`
```java
%s
```""".formatted(
channel == null ? "an" : "your",
ex.getStackTrace()[0].getClassName(),
ex.getLocalizedMessage()
));
2024-07-04 06:55:56 +01:00
if (channel != null) {
2024-07-05 23:35:41 +01:00
channel.sendMessageEmbeds(embed.build()).queue();
2024-07-04 06:55:56 +01:00
}
2024-07-05 23:35:41 +01:00
return embed;
}
2024-06-24 13:56:01 +01:00
}