add version number to the embeds

This commit is contained in:
Lee 2024-07-07 00:28:58 +01:00
parent b5ac5d6a9b
commit 585d3e0793
5 changed files with 99 additions and 10 deletions

33
pom.xml

@ -11,7 +11,7 @@
<groupId>cc.fascinated</groupId>
<artifactId>Bat</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.1</version>
<name>Bat</name>
<description>Bat Bot for Discord</description>
@ -67,6 +67,37 @@
</archive>
</configuration>
</plugin>
<!-- Used for generating a git properties file during build -->
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>4.9.10</version>
<executions>
<execution>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<prefix>git</prefix>
<dotGitDirectory>$PROJECT.BASEDIR$/.git</dotGitDirectory>
<injectAllReactorProjects>true</injectAllReactorProjects>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>src/main/resources/git.properties</generateGitPropertiesFilename>
<commitIdGenerationMode>full</commitIdGenerationMode>
<dateFormatTimeZone>$USER.TIMEZONE$</dateFormatTimeZone>
<dateFormat>MM-dd-yyyy@HH:mm:ss</dateFormat>
<includeOnlyProperties>
<includeOnlyProperty>^git.branch$</includeOnlyProperty>
<includeOnlyProperty>^git.build.(time|version)$</includeOnlyProperty>
<includeOnlyProperty>^git.commit.id.(abbrev|full)$</includeOnlyProperty>
<includeOnlyProperty>^git.build.user.name$</includeOnlyProperty>
</includeOnlyProperties>
</configuration>
</plugin>
</plugins>
</build>

@ -1,5 +1,6 @@
package cc.fascinated.bat;
import cc.fascinated.bat.common.BuildData;
import cc.fascinated.bat.config.Config;
import cc.fascinated.bat.event.EventListener;
import cc.fascinated.bat.service.EventService;
@ -25,6 +26,7 @@ import java.util.Objects;
@Log4j2(topic = "Bat")
public class BatApplication {
public static Gson GSON = new GsonBuilder().create();
public static BuildData BUILD_DATA = new BuildData();
@SneakyThrows
public static void main(@NonNull String[] args) {

@ -0,0 +1,52 @@
package cc.fascinated.bat.common;
import lombok.Getter;
import lombok.extern.log4j.Log4j2;
import java.io.IOException;
import java.util.Properties;
/**
* @author Fascinated (fascinated7)
*/
@Getter
@Log4j2(topic = "Build Data")
public class BuildData {
/**
* The commit hash of the build
*/
private final String buildId;
/**
* The version of the build
*/
private final String buildVersion;
/**
* The date of the build
*/
private final String buildDate;
public BuildData() {
// get git.properties from resources
Properties properties = new Properties();
try {
properties.load(getClass().getClassLoader().getResourceAsStream("git.properties"));
} catch (IOException ex) {
log.error("Failed to load git.properties", ex);
}
this.buildId = properties.getProperty("git.commit.id.abbrev");
this.buildVersion = properties.getProperty("git.build.version");
this.buildDate = properties.getProperty("git.build.time");
}
/**
* Gets the version of the bot
*
* @return the version
*/
public String getVersion() {
return "Bat - v%s-%s".formatted(buildVersion, buildId);
}
}

@ -1,5 +1,6 @@
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;
@ -20,6 +21,7 @@ public class EmbedUtils {
public static EmbedBuilder genericEmbed() {
return new EmbedBuilder()
.setTimestamp(LocalDateTime.now())
.setFooter(BatApplication.BUILD_DATA.getVersion())
.setColor(Colors.DEFAULT);
}
@ -31,6 +33,7 @@ public class EmbedUtils {
public static EmbedBuilder errorEmbed() {
return new EmbedBuilder()
.setTimestamp(LocalDateTime.now())
.setFooter(BatApplication.BUILD_DATA.getVersion())
.setColor(Colors.ERROR);
}
@ -42,6 +45,7 @@ public class EmbedUtils {
public static EmbedBuilder successEmbed() {
return new EmbedBuilder()
.setTimestamp(LocalDateTime.now())
.setFooter(BatApplication.BUILD_DATA.getVersion())
.setColor(Colors.SUCCESS);
}

@ -27,7 +27,7 @@ public class MessageSnipeFeature extends Feature implements EventListener {
/**
* The sniped messages for each guild
*/
private static final Map<BatGuild, List<SnipedMessage>> snipedMessages = new HashMap<>();
private static final Map<BatGuild, List<SnipedMessage>> SNIPED_MESSAGES = new HashMap<>();
private static final long SNIPED_MESSAGE_EXPIRATION = TimeUnit.HOURS.toMillis(1);
@Autowired
@ -44,8 +44,8 @@ public class MessageSnipeFeature extends Feature implements EventListener {
* @return if the sniped messages were cleared
*/
public static boolean clearSnipedMessages(BatGuild guild) {
if (snipedMessages.containsKey(guild)) {
snipedMessages.remove(guild);
if (SNIPED_MESSAGES.containsKey(guild)) {
SNIPED_MESSAGES.remove(guild);
return true;
}
return false;
@ -58,7 +58,7 @@ public class MessageSnipeFeature extends Feature implements EventListener {
* @return the sniped messages for the given guild
*/
public static SnipedMessage getDeletedMessage(BatGuild guild, String channelId) {
List<SnipedMessage> messages = snipedMessages.getOrDefault(guild, new ArrayList<>()).stream()
List<SnipedMessage> messages = SNIPED_MESSAGES.getOrDefault(guild, new ArrayList<>()).stream()
.filter(message -> message.getDeletedDate() != null
&& message.getDeletedDate().getTime() + SNIPED_MESSAGE_EXPIRATION > System.currentTimeMillis())
.sorted(Comparator.comparing(SnipedMessage::getDeletedDate).reversed()).toList();
@ -79,7 +79,7 @@ public class MessageSnipeFeature extends Feature implements EventListener {
* @return the sniped message with the given id
*/
private SnipedMessage getSnipedMessage(BatGuild guild, String messageId) {
List<SnipedMessage> messages = snipedMessages.getOrDefault(guild, new ArrayList<>());
List<SnipedMessage> messages = SNIPED_MESSAGES.getOrDefault(guild, new ArrayList<>());
for (SnipedMessage message : messages) {
if (message.getMessage().getId().equals(messageId)) {
return message;
@ -94,12 +94,12 @@ public class MessageSnipeFeature extends Feature implements EventListener {
return;
}
List<SnipedMessage> messages = snipedMessages.getOrDefault(guild, new ArrayList<>());
List<SnipedMessage> messages = SNIPED_MESSAGES.getOrDefault(guild, new ArrayList<>());
if (messages.size() >= 10) { // Only store the last 10 messages
messages.remove(0);
}
messages.add(new SnipedMessage(event.getMessage(), null));
snipedMessages.put(guild, messages);
SNIPED_MESSAGES.put(guild, messages);
}
@Override
@ -107,7 +107,7 @@ public class MessageSnipeFeature extends Feature implements EventListener {
if (guild.getFeatureProfile().isFeatureDisabled(this)) {
return;
}
List<SnipedMessage> messages = snipedMessages.getOrDefault(guild, new ArrayList<>());
List<SnipedMessage> messages = SNIPED_MESSAGES.getOrDefault(guild, new ArrayList<>());
if (messages.size() >= 10) {
messages.remove(0);
}
@ -124,7 +124,7 @@ public class MessageSnipeFeature extends Feature implements EventListener {
if (guild.getFeatureProfile().isFeatureDisabled(this)) {
return;
}
List<SnipedMessage> messages = snipedMessages.getOrDefault(guild, new ArrayList<>());
List<SnipedMessage> messages = SNIPED_MESSAGES.getOrDefault(guild, new ArrayList<>());
if (messages.size() >= 10) {
messages.remove(0);
}