diff --git a/common/src/main/java/com/discordsrv/common/bansync/enums/BanSyncResult.java b/common/src/main/java/com/discordsrv/common/bansync/enums/BanSyncResult.java index 4dee08f3..55d36b24 100644 --- a/common/src/main/java/com/discordsrv/common/bansync/enums/BanSyncResult.java +++ b/common/src/main/java/com/discordsrv/common/bansync/enums/BanSyncResult.java @@ -27,6 +27,7 @@ public enum BanSyncResult implements ISyncResult { NO_DISCORD_CONNECTION("No Discord connection"), GUILD_DOESNT_EXIST("Guild doesn't exist"), INVALID_CONFIG("Invalid config"), + ; private final String format; @@ -36,7 +37,12 @@ public enum BanSyncResult implements ISyncResult { } @Override - public boolean isSuccess() { + public boolean isError() { + return true; + } + + @Override + public boolean isUpdate() { return false; } diff --git a/common/src/main/java/com/discordsrv/common/groupsync/enums/GroupSyncResult.java b/common/src/main/java/com/discordsrv/common/groupsync/enums/GroupSyncResult.java index 1bcdfcda..54f9c646 100644 --- a/common/src/main/java/com/discordsrv/common/groupsync/enums/GroupSyncResult.java +++ b/common/src/main/java/com/discordsrv/common/groupsync/enums/GroupSyncResult.java @@ -22,21 +22,34 @@ import com.discordsrv.common.sync.result.ISyncResult; public enum GroupSyncResult implements ISyncResult { + // Fail + NOT_A_GUILD_MEMBER("User is not part of the server the role is in", true), + // Error ROLE_DOESNT_EXIST("Role doesn't exist"), ROLE_CANNOT_INTERACT("Bot doesn't have a role above the synced role (cannot interact)"), - NOT_A_GUILD_MEMBER("User is not part of the server the role is in"), PERMISSION_BACKEND_FAILED("Failed to interact with permission backend, error printed"), ; private final String format; + private final boolean success; GroupSyncResult(String format) { - this.format = format; + this(format, false); } - public boolean isSuccess() { + GroupSyncResult(String format, boolean success) { + this.format = format; + this.success = success; + } + + public boolean isError() { + return !success; + } + + @Override + public boolean isUpdate() { return false; } diff --git a/common/src/main/java/com/discordsrv/common/sync/AbstractSyncModule.java b/common/src/main/java/com/discordsrv/common/sync/AbstractSyncModule.java index 0e03937a..2ce8cd3e 100644 --- a/common/src/main/java/com/discordsrv/common/sync/AbstractSyncModule.java +++ b/common/src/main/java/com/discordsrv/common/sync/AbstractSyncModule.java @@ -435,7 +435,7 @@ public abstract class AbstractSyncModule< if (allFailReason != null) { String reason = allFailReason.format(gameTerm(), discordTerm()); String message = "Failed to " + syncName() + " " + summary.who() + " (sync cause: " + summary.cause() + "): " + reason; - if (!allFailReason.isSuccess()) { + if (allFailReason.isError()) { logger().error(message, throwableToLog); } else { logger().debug(message, throwableToLog); @@ -453,14 +453,18 @@ public abstract class AbstractSyncModule< List successResults = new ArrayList<>(); List failResults = new ArrayList<>(); + List auditResults = new ArrayList<>(); for (Map.Entry> entry : groupedResults.entrySet()) { ISyncResult result = entry.getKey(); String line = result.format(gameTerm(), discordTerm()) + ": [" + String.join(", ", entry.getValue()) + "]"; - if (result.isSuccess()) { - successResults.add(line); - } else { + if (result.isError()) { failResults.add(line); + } else { + successResults.add(line); + } + if (result.isUpdate()) { + auditResults.add(line); } } @@ -473,7 +477,9 @@ public abstract class AbstractSyncModule< if (anyFail) { logger().error(syncName() + partially + " failed for " + formatResults(summary, failResults)); } - discordSRV.logger().writeLogForCurrentDay(logFileName(), formatResults(summary, successResults)); + if (!auditResults.isEmpty()) { + discordSRV.logger().writeLogForCurrentDay(logFileName(), formatResults(summary, auditResults)); + } }); } diff --git a/common/src/main/java/com/discordsrv/common/sync/result/GenericSyncResults.java b/common/src/main/java/com/discordsrv/common/sync/result/GenericSyncResults.java index abef3c44..b67fbf3f 100644 --- a/common/src/main/java/com/discordsrv/common/sync/result/GenericSyncResults.java +++ b/common/src/main/java/com/discordsrv/common/sync/result/GenericSyncResults.java @@ -21,17 +21,17 @@ package com.discordsrv.common.sync.result; public enum GenericSyncResults implements ISyncResult { // Success, actioned - ADD_DISCORD("Add %d"), - REMOVE_DISCORD("Remove %d"), - ADD_GAME("Add %g"), - REMOVE_GAME("Remove %g"), + ADD_DISCORD("Add %d", true), + REMOVE_DISCORD("Remove %d", true), + ADD_GAME("Add %g", true), + REMOVE_GAME("Remove %g", true), // Success, Nothing done BOTH_TRUE("Both true"), BOTH_FALSE("Both false"), WRONG_DIRECTION("Wrong direction"), - // Error + // Fail NOT_LINKED("Accounts not linked"), ; @@ -41,20 +41,31 @@ public enum GenericSyncResults implements ISyncResult { } private final String message; + private final boolean update; private final boolean success; GenericSyncResults(String message) { - this(message, true); + this(message, false); } - GenericSyncResults(String message, boolean success) { + GenericSyncResults(String message, boolean update) { + this(message, update, true); + } + + GenericSyncResults(String message, boolean update, boolean success) { this.message = message; + this.update = update; this.success = success; } @Override - public boolean isSuccess() { - return success; + public boolean isError() { + return !success; + } + + @Override + public boolean isUpdate() { + return update; } @Override diff --git a/common/src/main/java/com/discordsrv/common/sync/result/ISyncResult.java b/common/src/main/java/com/discordsrv/common/sync/result/ISyncResult.java index 679b4662..51d6e8b3 100644 --- a/common/src/main/java/com/discordsrv/common/sync/result/ISyncResult.java +++ b/common/src/main/java/com/discordsrv/common/sync/result/ISyncResult.java @@ -22,7 +22,8 @@ import com.discordsrv.api.placeholder.util.Placeholders; public interface ISyncResult { - boolean isSuccess(); + boolean isError(); + boolean isUpdate(); String getFormat(); default String format(String gameTerm, String discordTerm) {