Only log updates to file

This commit is contained in:
Vankka 2024-06-24 02:47:34 +03:00
parent 0e07eb26be
commit f125100b1b
No known key found for this signature in database
GPG Key ID: 62E48025ED4E7EBB
5 changed files with 56 additions and 19 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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<String> successResults = new ArrayList<>();
List<String> failResults = new ArrayList<>();
List<String> auditResults = new ArrayList<>();
for (Map.Entry<ISyncResult, List<String>> 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));
}
});
}

View File

@ -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

View File

@ -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) {