Merge remote-tracking branch 'origin/master'
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m44s

This commit is contained in:
Lee 2024-07-07 01:19:31 +01:00
commit 8a01359f6e
6 changed files with 11 additions and 100 deletions

33
pom.xml

@ -11,7 +11,7 @@
<groupId>cc.fascinated</groupId> <groupId>cc.fascinated</groupId>
<artifactId>Bat</artifactId> <artifactId>Bat</artifactId>
<version>0.1</version> <version>0.0.1-SNAPSHOT</version>
<name>Bat</name> <name>Bat</name>
<description>Bat Bot for Discord</description> <description>Bat Bot for Discord</description>
@ -67,37 +67,6 @@
</archive> </archive>
</configuration> </configuration>
</plugin> </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> </plugins>
</build> </build>

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

@ -1,52 +0,0 @@
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,6 +1,5 @@
package cc.fascinated.bat.common; package cc.fascinated.bat.common;
import cc.fascinated.bat.BatApplication;
import cc.fascinated.bat.config.Config; import cc.fascinated.bat.config.Config;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.EmbedBuilder;
@ -21,7 +20,6 @@ public class EmbedUtils {
public static EmbedBuilder genericEmbed() { public static EmbedBuilder genericEmbed() {
return new EmbedBuilder() return new EmbedBuilder()
.setTimestamp(LocalDateTime.now()) .setTimestamp(LocalDateTime.now())
.setFooter(BatApplication.BUILD_DATA.getVersion())
.setColor(Colors.DEFAULT); .setColor(Colors.DEFAULT);
} }
@ -33,7 +31,6 @@ public class EmbedUtils {
public static EmbedBuilder errorEmbed() { public static EmbedBuilder errorEmbed() {
return new EmbedBuilder() return new EmbedBuilder()
.setTimestamp(LocalDateTime.now()) .setTimestamp(LocalDateTime.now())
.setFooter(BatApplication.BUILD_DATA.getVersion())
.setColor(Colors.ERROR); .setColor(Colors.ERROR);
} }
@ -45,7 +42,6 @@ public class EmbedUtils {
public static EmbedBuilder successEmbed() { public static EmbedBuilder successEmbed() {
return new EmbedBuilder() return new EmbedBuilder()
.setTimestamp(LocalDateTime.now()) .setTimestamp(LocalDateTime.now())
.setFooter(BatApplication.BUILD_DATA.getVersion())
.setColor(Colors.SUCCESS); .setColor(Colors.SUCCESS);
} }

@ -26,7 +26,7 @@ import org.springframework.stereotype.Component;
public class BaseFeature extends Feature { public class BaseFeature extends Feature {
@Autowired @Autowired
public BaseFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) { public BaseFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
super("Base", FeatureProfile.FeatureState.DISABLED, false); super("Base", FeatureProfile.FeatureState.ENABLED, false);
super.registerCommand(commandService, context.getBean(PremiumCommand.class)); super.registerCommand(commandService, context.getBean(PremiumCommand.class));
super.registerCommand(commandService, context.getBean(BotAdminCommand.class)); super.registerCommand(commandService, context.getBean(BotAdminCommand.class));

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