Skip to content

Commit

Permalink
Catch ExecutionExceptions for level up alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
CominAtYou committed Jun 5, 2024
1 parent 9648003 commit bb5f916
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.cominatyou</groupId>
<artifactId>hildabot</artifactId>
<version>2.5.4</version>
<version>2.6.0</version>

<name>hildabot</name>
<url>http://www.example.com</url>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/cominatyou/util/versioning/Version.java
Original file line number Diff line number Diff line change
@@ -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);
}
20 changes: 14 additions & 6 deletions src/main/java/com/cominatyou/xp/XPSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit bb5f916

Please sign in to comment.