diff --git a/pom.xml b/pom.xml index 19bd24b..2a6c854 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ cc.fascinated Bat - 0.0.1-SNAPSHOT + 0.1 Bat Bat Bot for Discord @@ -67,6 +67,37 @@ + + + + pl.project13.maven + git-commit-id-plugin + 4.9.10 + + + + revision + + + + + git + $PROJECT.BASEDIR$/.git + true + true + src/main/resources/git.properties + full + $USER.TIMEZONE$ + MM-dd-yyyy@HH:mm:ss + + ^git.branch$ + ^git.build.(time|version)$ + ^git.commit.id.(abbrev|full)$ + ^git.build.user.name$ + + + + diff --git a/src/main/java/cc/fascinated/bat/BatApplication.java b/src/main/java/cc/fascinated/bat/BatApplication.java index da73e4c..17c1220 100644 --- a/src/main/java/cc/fascinated/bat/BatApplication.java +++ b/src/main/java/cc/fascinated/bat/BatApplication.java @@ -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) { diff --git a/src/main/java/cc/fascinated/bat/common/BuildData.java b/src/main/java/cc/fascinated/bat/common/BuildData.java new file mode 100644 index 0000000..4b2cbfc --- /dev/null +++ b/src/main/java/cc/fascinated/bat/common/BuildData.java @@ -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); + } +} diff --git a/src/main/java/cc/fascinated/bat/common/EmbedUtils.java b/src/main/java/cc/fascinated/bat/common/EmbedUtils.java index 09b5bfa..b611747 100644 --- a/src/main/java/cc/fascinated/bat/common/EmbedUtils.java +++ b/src/main/java/cc/fascinated/bat/common/EmbedUtils.java @@ -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); } diff --git a/src/main/java/cc/fascinated/bat/features/messagesnipe/MessageSnipeFeature.java b/src/main/java/cc/fascinated/bat/features/messagesnipe/MessageSnipeFeature.java index fbf2c76..7a80195 100644 --- a/src/main/java/cc/fascinated/bat/features/messagesnipe/MessageSnipeFeature.java +++ b/src/main/java/cc/fascinated/bat/features/messagesnipe/MessageSnipeFeature.java @@ -27,7 +27,7 @@ public class MessageSnipeFeature extends Feature implements EventListener { /** * The sniped messages for each guild */ - private static final Map> snipedMessages = new HashMap<>(); + private static final Map> 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 messages = snipedMessages.getOrDefault(guild, new ArrayList<>()).stream() + List 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 messages = snipedMessages.getOrDefault(guild, new ArrayList<>()); + List 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 messages = snipedMessages.getOrDefault(guild, new ArrayList<>()); + List 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 messages = snipedMessages.getOrDefault(guild, new ArrayList<>()); + List 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 messages = snipedMessages.getOrDefault(guild, new ArrayList<>()); + List messages = SNIPED_MESSAGES.getOrDefault(guild, new ArrayList<>()); if (messages.size() >= 10) { messages.remove(0); }