Skip to content
Open
22 changes: 17 additions & 5 deletions src/main/java/oakbot/bot/Bot.java
Comment thread
sanifalimomin marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
public class Bot implements IBot {
private static final Logger logger = LoggerFactory.getLogger(Bot.class);
static final int BOTLER_ID = 13750349;

private static final int ROOM_JOIN_DELAY_MS = 2000;
Comment thread
sanifalimomin marked this conversation as resolved.
Outdated

private final BotConfiguration config;
private final SecurityConfiguration security;
Expand Down Expand Up @@ -152,7 +154,7 @@ private void joinRoomsOnStart(boolean quiet) {
* resolve an issue where the bot chooses to ignore all messages
* in certain rooms.
*/
Sleeper.sleep(2000);
Sleeper.sleep(ROOM_JOIN_DELAY_MS);
}

try {
Expand Down Expand Up @@ -593,6 +595,16 @@ public Chore() {

public abstract void complete();

/**
* Logs an error that occurred during chore execution.
* This method is pulled up from subclasses to provide common error logging functionality.
* @param message the error message
* @param cause the exception that caused the error
*/
protected void logError(String message, Exception cause) {
logger.atError().setCause(cause).log(() -> message);
Comment thread
sanifalimomin marked this conversation as resolved.
Outdated
}

@Override
public int compareTo(Chore that) {
/*
Expand Down Expand Up @@ -986,7 +998,7 @@ public void complete() {
room.deleteMessage(id);
}
} catch (Exception e) {
logger.atError().setCause(e).log(() -> "Problem editing chat message [room=" + roomId + ", id=" + postedMessage.getMessageIds().get(0) + "]");
logError("Problem editing chat message [room=" + roomId + ", id=" + postedMessage.getMessageIds().get(0) + "]", e);
}
}

Expand Down Expand Up @@ -1018,7 +1030,7 @@ public void complete() {
try {
task.run(Bot.this);
} catch (Exception e) {
logger.atError().setCause(e).log(() -> "Problem running scheduled task.");
logError("Problem running scheduled task.", e);
}
scheduleTask(task);
}
Expand Down Expand Up @@ -1052,7 +1064,7 @@ public void complete() {
try {
task.run(room, Bot.this);
} catch (Exception e) {
logger.atError().setCause(e).log(() -> "Problem running inactivity task in room " + room.getRoomId() + ".");
logError("Problem running inactivity task in room " + room.getRoomId() + ".", e);
}
}

Expand Down Expand Up @@ -1082,7 +1094,7 @@ public void complete() {
sendMessage(roomId, message);
}
} catch (Exception e) {
logger.atError().setCause(e).log(() -> "Problem posting delayed message [room=" + roomId + ", delay=" + message.delay() + "]: " + message.message());
logError("Problem posting delayed message [room=" + roomId + ", delay=" + message.delay() + "]: " + message.message(), e);
}
}
}
Expand Down