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

73 lines
2.2 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
*
* @param ex the exception
* @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());
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()
2024-07-04 06:55:56 +01:00
.setDescription("""
An error has occurred while processing your interaction. Please check the logs for more information.
```java
%s
```""".formatted(ex.getLocalizedMessage()));
}
2024-06-24 13:56:01 +01:00
}