Some checks failed
Deploy to Dokku / docker (ubuntu-latest) (push) Failing after 1m4s
78 lines
2.3 KiB
Java
78 lines
2.3 KiB
Java
package cc.fascinated.bat.common;
|
|
|
|
import cc.fascinated.bat.BatApplication;
|
|
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;
|
|
|
|
/**
|
|
* @author Fascinated (fascinated7)
|
|
*/
|
|
@UtilityClass
|
|
public class EmbedUtils {
|
|
/**
|
|
* Builds a generic embed
|
|
*
|
|
* @return the embed builder
|
|
*/
|
|
public static EmbedBuilder genericEmbed() {
|
|
return new EmbedBuilder()
|
|
.setTimestamp(LocalDateTime.now())
|
|
.setFooter(BatApplication.BUILD_DATA.getVersion())
|
|
.setColor(Colors.DEFAULT);
|
|
}
|
|
|
|
/**
|
|
* Builds an error embed
|
|
*
|
|
* @return the embed builder
|
|
*/
|
|
public static EmbedBuilder errorEmbed() {
|
|
return new EmbedBuilder()
|
|
.setTimestamp(LocalDateTime.now())
|
|
.setFooter(BatApplication.BUILD_DATA.getVersion())
|
|
.setColor(Colors.ERROR);
|
|
}
|
|
|
|
/**
|
|
* Builds a success embed
|
|
*
|
|
* @return the embed builder
|
|
*/
|
|
public static EmbedBuilder successEmbed() {
|
|
return new EmbedBuilder()
|
|
.setTimestamp(LocalDateTime.now())
|
|
.setFooter(BatApplication.BUILD_DATA.getVersion())
|
|
.setColor(Colors.SUCCESS);
|
|
}
|
|
|
|
/**
|
|
* Builds a generic interaction error embed
|
|
*
|
|
* @param ex the exceptionk
|
|
* @return the embed builder
|
|
*/
|
|
public static EmbedBuilder genericInteractionError(Exception ex) {
|
|
TextChannel channel = ChannelUtils.getTextChannel(Config.INSTANCE.getLogsChannel());
|
|
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()
|
|
));
|
|
|
|
if (channel != null) {
|
|
channel.sendMessageEmbeds(embed.build()).queue();
|
|
}
|
|
return embed;
|
|
}
|
|
}
|