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:
parent
19e0760aa2
commit
40ded90edf
|
|
@ -29,6 +29,10 @@ allprojects {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.test {
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// Minimessage
|
// Minimessage
|
||||||
// implementation("net.kyori:adventure-text-minimessage:4.1.0-SNAPSHOT")
|
// implementation("net.kyori:adventure-text-minimessage:4.1.0-SNAPSHOT")
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||||
import net.luckperms.api.model.user.User;
|
import net.luckperms.api.model.user.User;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
@ -65,6 +66,7 @@ public class LiteBansBanListener {
|
||||||
.setColor(entry.isPermanent() ? Color.RED : Color.ORANGE)
|
.setColor(entry.isPermanent() ? Color.RED : Color.ORANGE)
|
||||||
.setAuthor(username, null, "https://crafatar.com/avatars/" + stringUuid + "?overlay")
|
.setAuthor(username, null, "https://crafatar.com/avatars/" + stringUuid + "?overlay")
|
||||||
.addField("Banned by", entry.getExecutorName() == null ? "unknown" : entry.getExecutorName(), true)
|
.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)
|
.addField("Reason", entry.getReason() == null ? "unknown" : entry.getReason(), true)
|
||||||
.setTitle("Auto Discord ban");
|
.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) {
|
private Optional<MessageEmbed.Field> banDiscordUserIfExists(Entry entry, UUID uuid) {
|
||||||
if (!entry.isPermanent())
|
if (!entry.isPermanent())
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
|
||||||
|
|
@ -20,14 +20,17 @@ public class Evidence {
|
||||||
Config.NEXT_CLOUD.USERNAME,
|
Config.NEXT_CLOUD.USERNAME,
|
||||||
Config.NEXT_CLOUD.PASSWORD
|
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)) {
|
if (!nextcloudConnector.folderExists(evidenceFilePath)) {
|
||||||
nextcloudConnector.createFolder(evidenceFilePath);
|
nextcloudConnector.createFolder(evidenceFilePath);
|
||||||
}
|
}
|
||||||
nextcloudConnector.createFolder(evidenceFilePath + "/" + getCurrentDate());
|
String newEvidenceFolderPath = evidenceFilePath + "/" + getCurrentDate();
|
||||||
|
if (!nextcloudConnector.folderExists(newEvidenceFolderPath)) {
|
||||||
|
nextcloudConnector.createFolder(newEvidenceFolderPath);
|
||||||
|
}
|
||||||
String id;
|
String id;
|
||||||
try {
|
try {
|
||||||
id = nextcloudConnector.getProperties(evidenceFilePath + "/" + getCurrentDate(), true).getId();
|
id = nextcloudConnector.getProperties(newEvidenceFolderPath, true).getId();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
ALogger.error("Failed to get share link for Next Cloud folder", e);
|
ALogger.error("Failed to get share link for Next Cloud folder", e);
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package com.alttd.proxydiscordlink.util;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class EvidenceTest {
|
public class EvidenceTest {
|
||||||
|
|
@ -9,11 +11,9 @@ public class EvidenceTest {
|
||||||
@Test
|
@Test
|
||||||
void shouldReturnEvidenceUrl() {
|
void shouldReturnEvidenceUrl() {
|
||||||
Evidence evidence = new Evidence();
|
Evidence evidence = new Evidence();
|
||||||
|
Optional<String> evidenceUrl = evidence.getNewEvidenceFolder("akastijn").join();
|
||||||
evidence.getNewEvidenceFolder("akastijn").thenAccept(evidenceUrl -> {
|
assertTrue(evidenceUrl.isPresent());
|
||||||
assertTrue(evidenceUrl.isPresent());
|
System.out.println(evidenceUrl.get());
|
||||||
System.out.println(evidenceUrl.get());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user