Skip to content

Friendlier handling of default webhook values on bot launch #1263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
public final class DiscordLogging {
private static final Logger logger = LoggerFactory.getLogger(DiscordLogging.class);
private static final String LOG_CHANNEL_WEBHOOK_DEFAULT_VALUE = "<put_your_webhook_here>";

private DiscordLogging() {
throw new UnsupportedOperationException("Utility class");
Expand All @@ -45,22 +46,29 @@ public static void startDiscordLogging(Config botConfig) {
}

private static void addAppenders(Configuration logConfig, Config botConfig) {
parseWebhookUri(botConfig.getLogInfoChannelWebhook())
parseWebhookUri(botConfig.getLogInfoChannelWebhook(), "info")
.ifPresent(webhookUri -> addDiscordLogAppender("DiscordInfo", createInfoRangeFilter(),
webhookUri, botConfig.getSourceCodeBaseUrl(), logConfig));

parseWebhookUri(botConfig.getLogErrorChannelWebhook())
parseWebhookUri(botConfig.getLogErrorChannelWebhook(), "error")
.ifPresent(webhookUri -> addDiscordLogAppender("DiscordError", createErrorRangeFilter(),
webhookUri, botConfig.getSourceCodeBaseUrl(), logConfig));
}

private static Optional<URI> parseWebhookUri(String webhookUri) {
private static Optional<URI> parseWebhookUri(String webhookUri, String webhookName) {
if (webhookUri.equalsIgnoreCase(LOG_CHANNEL_WEBHOOK_DEFAULT_VALUE)) {
logger.warn(
"The {} webhook URL was not setup yet, logs will not be forwarded to Discord. Enter a valid webhook URL in your `config.json` if you want log forwarding.",
webhookName);
return Optional.empty();
}

try {
return Optional.of(URI.create(webhookUri));
} catch (IllegalArgumentException e) {
logger.warn(LogMarkers.NO_DISCORD,
"The webhook URL ({}) in the config is invalid, logs will not be forwarded to Discord.",
webhookUri, e);
"The {} webhook URL ({}) in the config is invalid, logs will not be forwarded to Discord.",
webhookName, webhookUri, e);
return Optional.empty();
}
}
Expand Down
Loading