From bb5f9160ef28dc9aba0364d795cac560863540bc Mon Sep 17 00:00:00 2001 From: William M Date: Wed, 5 Jun 2024 22:39:44 +0800 Subject: [PATCH] Catch ExecutionExceptions for level up alerts --- pom.xml | 2 +- .../cominatyou/util/versioning/Version.java | 4 ++-- src/main/java/com/cominatyou/xp/XPSystem.java | 20 +++++++++++++------ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index b917c25..f93d959 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.cominatyou hildabot - 2.5.4 + 2.6.0 hildabot http://www.example.com diff --git a/src/main/java/com/cominatyou/util/versioning/Version.java b/src/main/java/com/cominatyou/util/versioning/Version.java index 6e38adf..8af4cbc 100644 --- a/src/main/java/com/cominatyou/util/versioning/Version.java +++ b/src/main/java/com/cominatyou/util/versioning/Version.java @@ -1,7 +1,7 @@ package com.cominatyou.util.versioning; public class Version { - public static final String VERSION = "2.5.4"; - public static final String BUILD_NUMBER = "11F045"; + public static final String VERSION = "2.6.0"; + public static final String BUILD_NUMBER = "11G046"; public static final String VERSION_STRING = String.format("%s (%s)", VERSION, BUILD_NUMBER); } diff --git a/src/main/java/com/cominatyou/xp/XPSystem.java b/src/main/java/com/cominatyou/xp/XPSystem.java index 702f67b..fd30185 100644 --- a/src/main/java/com/cominatyou/xp/XPSystem.java +++ b/src/main/java/com/cominatyou/xp/XPSystem.java @@ -4,6 +4,7 @@ import java.io.StringWriter; import java.util.Arrays; import java.util.List; +import java.util.concurrent.ExecutionException; import java.util.concurrent.ThreadLocalRandom; import com.cominatyou.db.RedisInstance; @@ -69,21 +70,28 @@ public static void checkForLevelUp(int beforeActionLevel, User user, Server serv .setTitle(embedTitle) .setDescription("To disable this message going forward, run `h!levelalert` in this DM or <#495034452422950915>."); try { - user.openPrivateChannel().join().sendMessage(embed); + user.openPrivateChannel().get().sendMessage(embed).get(); Log.eventf("LevelAlert", "Sent level up message to %s", user.getName()); } - catch (Exception e) { - if (e.getMessage().contains("Cannot send messages to this user")) { // Target user has DMs off for the server + catch (ExecutionException e) { + if (e.getCause().getMessage().contains("Cannot send messages to this user")) { // Target user has DMs off for the server Log.eventf("LevelAlert", "No message was sent to %s as their privacy settings prevent it.", user.getName()); } else { - e.printStackTrace(); + e.getCause().printStackTrace(); final StringWriter sw = new StringWriter(); - e.printStackTrace(new PrintWriter(sw)); + e.getCause().printStackTrace(new PrintWriter(sw)); - Log.error("LevelAlert", String.format("Failed to send level up message to %s.", user.getName()), sw.toString()); + Log.error("LevelAlert", String.format("Failed to send level up message to %s.\n```%s```", user.getName()), sw.toString()); } } + catch (Exception e) { + e.printStackTrace(); + final StringWriter sw = new StringWriter(); + e.printStackTrace(new PrintWriter(sw)); + + Log.error("LevelAlert", String.format("Failed to send level up message to %s.\n```%s```", user.getName()), sw.toString()); + } } else { Log.eventf("LevelAlert", "Not sending a message to %s as they have level alerts off.", user.getName());