Refactor folder handling and enhance ban duration reporting

Improved Nextcloud folder handling by checking for folder existence before creation, ensuring efficient operations. Updated LiteBansBanListener to include ban durations in Discord messages, adding clarity for temporary bans. Enhanced unit test structure for Evidence with simplified assertions.
This commit is contained in:
Teriuihi 2025-01-03 23:49:14 +01:00
parent 19e0760aa2
commit 40ded90edf
4 changed files with 24 additions and 8 deletions

View File

@ -29,6 +29,10 @@ allprojects {
}
}
tasks.test {
useJUnitPlatform()
}
dependencies {
// Minimessage
// implementation("net.kyori:adventure-text-minimessage:4.1.0-SNAPSHOT")

View File

@ -13,6 +13,7 @@ import net.dv8tion.jda.api.entities.MessageEmbed;
import net.luckperms.api.model.user.User;
import java.awt.*;
import java.time.Instant;
import java.util.Optional;
import java.util.UUID;
@ -65,6 +66,7 @@ public class LiteBansBanListener {
.setColor(entry.isPermanent() ? Color.RED : Color.ORANGE)
.setAuthor(username, null, "https://crafatar.com/avatars/" + stringUuid + "?overlay")
.addField("Banned by", entry.getExecutorName() == null ? "unknown" : entry.getExecutorName(), true)
.addField("Ban duration", getBanDuration(entry), true)
.addField("Reason", entry.getReason() == null ? "unknown" : entry.getReason(), true)
.setTitle("Auto Discord ban");
@ -80,6 +82,13 @@ public class LiteBansBanListener {
});
}
private String getBanDuration(Entry entry) {
if (entry.isPermanent())
return "Permanent ban";
Instant instant = Instant.ofEpochMilli(entry.getDateEnd());
return String.format("<t:%d:F>", instant.getEpochSecond());
}
private Optional<MessageEmbed.Field> banDiscordUserIfExists(Entry entry, UUID uuid) {
if (!entry.isPermanent())
return Optional.empty();

View File

@ -20,14 +20,17 @@ public class Evidence {
Config.NEXT_CLOUD.USERNAME,
Config.NEXT_CLOUD.PASSWORD
);
String evidenceFilePath = String.format("/Altitude/Altitude Moderation Tools/Evidence/%s", username);
String evidenceFilePath = String.format("/Evidence/%s", username);
if (!nextcloudConnector.folderExists(evidenceFilePath)) {
nextcloudConnector.createFolder(evidenceFilePath);
}
nextcloudConnector.createFolder(evidenceFilePath + "/" + getCurrentDate());
String newEvidenceFolderPath = evidenceFilePath + "/" + getCurrentDate();
if (!nextcloudConnector.folderExists(newEvidenceFolderPath)) {
nextcloudConnector.createFolder(newEvidenceFolderPath);
}
String id;
try {
id = nextcloudConnector.getProperties(evidenceFilePath + "/" + getCurrentDate(), true).getId();
id = nextcloudConnector.getProperties(newEvidenceFolderPath, true).getId();
} catch (IOException e) {
ALogger.error("Failed to get share link for Next Cloud folder", e);
return Optional.empty();

View File

@ -2,6 +2,8 @@ package com.alttd.proxydiscordlink.util;
import org.junit.jupiter.api.Test;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class EvidenceTest {
@ -9,11 +11,9 @@ public class EvidenceTest {
@Test
void shouldReturnEvidenceUrl() {
Evidence evidence = new Evidence();
evidence.getNewEvidenceFolder("akastijn").thenAccept(evidenceUrl -> {
assertTrue(evidenceUrl.isPresent());
System.out.println(evidenceUrl.get());
});
Optional<String> evidenceUrl = evidence.getNewEvidenceFolder("akastijn").join();
assertTrue(evidenceUrl.isPresent());
System.out.println(evidenceUrl.get());
}