Skip to content
2 changes: 2 additions & 0 deletions application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ dependencies {
implementation 'org.apache.logging.log4j:log4j-core:2.19.0'
runtimeOnly 'org.apache.logging.log4j:log4j-slf4j18-impl:2.18.0'

implementation 'club.minnced:discord-webhooks:0.8.2'

implementation 'org.jooq:jooq:3.17.2'

implementation 'io.mikael:urlbuilder:2.0.9'
Expand Down
4 changes: 3 additions & 1 deletion application/config.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,7 @@
"wsc",
"wsf",
"wsh"
]
],
"logInfoChannelWebhook": "<put_your_webhook_here>",
"logErrorChannelWebhook": "<put_your_webhook_here>"
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.togetherjava.tjbot.commands.system.BotCore;
import org.togetherjava.tjbot.config.Config;
import org.togetherjava.tjbot.db.Database;
import org.togetherjava.tjbot.logging.LogMarkers;
import org.togetherjava.tjbot.logging.discord.DiscordLogging;

import java.io.IOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -57,6 +59,7 @@ public static void main(final String[] args) {

Thread.setDefaultUncaughtExceptionHandler(Application::onUncaughtException);
Runtime.getRuntime().addShutdownHook(new Thread(Application::onShutdown));
DiscordLogging.startDiscordLogging(config);

runBot(config);
}
Expand Down Expand Up @@ -92,7 +95,7 @@ public static void runBot(Config config) {

logger.info("Bot is ready");
} catch (InvalidTokenException e) {
logger.error("Failed to login", e);
logger.error(LogMarkers.SENSITIVE, "Failed to login", e);
} catch (InterruptedException e) {
logger.error("Interrupted while waiting for setup to complete", e);
Thread.currentThread().interrupt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.togetherjava.tjbot.db.Database;
import org.togetherjava.tjbot.db.generated.tables.ComponentIds;
import org.togetherjava.tjbot.db.generated.tables.records.ComponentIdsRecord;
import org.togetherjava.tjbot.logging.LogMarkers;

import java.time.Instant;
import java.time.temporal.ChronoUnit;
Expand Down Expand Up @@ -323,8 +324,8 @@ private void logDebugSizeStatistics() {
ComponentIds.COMPONENT_IDS.LIFESPAN.eq(lifespan.name())))));
int recordsCount = lifespanToCount.values().stream().mapToInt(Integer::intValue).sum();

logger.debug("The component id store consists of {} records ({})", recordsCount,
lifespanToCount);
logger.debug(LogMarkers.SENSITIVE, "The component id store consists of {} records ({})",
recordsCount, lifespanToCount);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.slf4j.LoggerFactory;
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.logging.LogMarkers;

import javax.annotation.Nullable;
import java.time.Instant;
Expand Down Expand Up @@ -128,7 +129,8 @@ private static Optional<RestAction<InteractionHook>> handleNotAlreadyBannedRespo
.setEphemeral(true));
}
}
logger.warn("Something unexpected went wrong while trying to ban the user '{}'.",
logger.warn(LogMarkers.SENSITIVE,
"Something unexpected went wrong while trying to ban the user '{}'.",
target.getAsTag(), alreadyBannedFailure);
return Optional.of(event.reply("Failed to ban the user due to an unexpected problem.")
.setEphemeral(true));
Expand All @@ -149,7 +151,7 @@ private AuditableRestAction<Void> banUser(User target, Member author,
int deleteHistoryDays, Guild guild) {
String durationMessage =
temporaryData == null ? "permanently" : "for " + temporaryData.duration();
logger.info(
logger.info(LogMarkers.SENSITIVE,
"'{}' ({}) banned the user '{}' ({}) {} from guild '{}' and deleted their message history of the last {} days, for reason '{}'.",
author.getUser().getAsTag(), author.getId(), target.getAsTag(), target.getId(),
durationMessage, guild.getName(), deleteHistoryDays, reason);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.slf4j.LoggerFactory;
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.logging.LogMarkers;

import javax.annotation.Nullable;
import java.util.Objects;
Expand Down Expand Up @@ -82,7 +83,8 @@ private static RestAction<Boolean> sendDm(ISnowflake target, String reason, Guil

private AuditableRestAction<Void> kickUser(Member target, Member author, String reason,
Guild guild) {
logger.info("'{}' ({}) kicked the user '{}' ({}) from guild '{}' for reason '{}'.",
logger.info(LogMarkers.SENSITIVE,
"'{}' ({}) kicked the user '{}' ({}) from guild '{}' for reason '{}'.",
author.getUser().getAsTag(), author.getId(), target.getUser().getAsTag(),
target.getId(), guild.getName(), reason);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.config.Config;
import org.togetherjava.tjbot.logging.LogMarkers;

import javax.annotation.Nullable;
import java.time.Instant;
Expand Down Expand Up @@ -103,7 +104,8 @@ private AuditableRestAction<Void> muteUser(Member target, Member author,
@Nullable ModerationUtils.TemporaryData temporaryData, String reason, Guild guild) {
String durationMessage =
temporaryData == null ? "permanently" : "for " + temporaryData.duration();
logger.info("'{}' ({}) muted the user '{}' ({}) {} in guild '{}' for reason '{}'.",
logger.info(LogMarkers.SENSITIVE,
"'{}' ({}) muted the user '{}' ({}) {} in guild '{}' for reason '{}'.",
author.getUser().getAsTag(), author.getId(), target.getUser().getAsTag(),
target.getId(), durationMessage, guild.getName(), reason);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.slf4j.LoggerFactory;
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.logging.LogMarkers;

import javax.annotation.Nullable;
import java.util.Objects;
Expand Down Expand Up @@ -77,7 +78,8 @@ private void sendNote(User target, Member author, String content, ISnowflake gui
}

private void storeNote(User target, Member author, String content, ISnowflake guild) {
logger.info("'{}' ({}) wrote a note about the user '{}' ({}) with content '{}'.",
logger.info(LogMarkers.SENSITIVE,
"'{}' ({}) wrote a note about the user '{}' ({}) with content '{}'.",
author.getUser().getAsTag(), author.getId(), target.getAsTag(), target.getId(),
content);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.config.Config;
import org.togetherjava.tjbot.logging.LogMarkers;

import javax.annotation.Nullable;
import java.util.Objects;
Expand Down Expand Up @@ -88,7 +89,8 @@ private static MessageEmbed sendFeedback(boolean hasSentDm, Member target, Membe

private AuditableRestAction<Void> quarantineUser(Member target, Member author, String reason,
Guild guild) {
logger.info("'{}' ({}) quarantined the user '{}' ({}) in guild '{}' for reason '{}'.",
logger.info(LogMarkers.SENSITIVE,
"'{}' ({}) quarantined the user '{}' ({}) in guild '{}' for reason '{}'.",
author.getUser().getAsTag(), author.getId(), target.getUser().getAsTag(),
target.getId(), guild.getName(), reason);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.slf4j.LoggerFactory;
import org.togetherjava.tjbot.commands.EventReceiver;
import org.togetherjava.tjbot.config.Config;
import org.togetherjava.tjbot.logging.LogMarkers;

import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -93,7 +94,8 @@ private boolean shouldApplyModerationRole(ModerationRole moderationRole,

private static void applyModerationRole(ModerationRole moderationRole, Member member) {
Guild guild = member.getGuild();
logger.info("Reapplied existing {} to user '{}' ({}) in guild '{}' after rejoining.",
logger.info(LogMarkers.SENSITIVE,
"Reapplied existing {} to user '{}' ({}) in guild '{}' after rejoining.",
moderationRole.actionName, member.getUser().getAsTag(), member.getId(),
guild.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.slf4j.LoggerFactory;
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.logging.LogMarkers;

import java.util.Objects;

Expand Down Expand Up @@ -49,7 +50,8 @@ private void unban(User target, Member author, String reason, Guild guild,
ModerationAction.UNBAN, target, null, reason);
event.replyEmbeds(message).queue();

logger.info("'{}' ({}) unbanned the user '{}' ({}) from guild '{}' for reason '{}'.",
logger.info(LogMarkers.SENSITIVE,
"'{}' ({}) unbanned the user '{}' ({}) from guild '{}' for reason '{}'.",
author.getUser().getAsTag(), author.getId(), target.getAsTag(), target.getId(),
guild.getName(), reason);

Expand All @@ -63,21 +65,23 @@ private static void handleFailure(Throwable unbanFailure, User target, IReplyCal
if (unbanFailure instanceof ErrorResponseException errorResponseException) {
if (errorResponseException.getErrorResponse() == ErrorResponse.UNKNOWN_USER) {
event.reply("The specified user does not exist.").setEphemeral(true).queue();
logger.debug("Unable to unban the user '{}' because they do not exist.", targetTag);
logger.debug(LogMarkers.SENSITIVE,
"Unable to unban the user '{}' because they do not exist.", targetTag);
return;
}

if (errorResponseException.getErrorResponse() == ErrorResponse.UNKNOWN_BAN) {
event.reply("The specified user is not banned.").setEphemeral(true).queue();
logger.debug("Unable to unban the user '{}' because they are not banned.",
targetTag);
logger.debug(LogMarkers.SENSITIVE,
"Unable to unban the user '{}' because they are not banned.", targetTag);
return;
}
}

event.reply("Sorry, but something went wrong.").setEphemeral(true).queue();
logger.warn("Something unexpected went wrong while trying to unban the user '{}'.",
targetTag, unbanFailure);
logger.warn(LogMarkers.SENSITIVE,
"Something unexpected went wrong while trying to unban the user '{}'.", targetTag,
unbanFailure);
}

private boolean handleChecks(IPermissionHolder bot, Member author, CharSequence reason,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.config.Config;
import org.togetherjava.tjbot.logging.LogMarkers;

import javax.annotation.Nullable;
import java.util.Objects;
Expand Down Expand Up @@ -81,7 +82,8 @@ private static MessageEmbed sendFeedback(boolean hasSentDm, Member target, Membe

private AuditableRestAction<Void> unmuteUser(Member target, Member author, String reason,
Guild guild) {
logger.info("'{}' ({}) unmuted the user '{}' ({}) in guild '{}' for reason '{}'.",
logger.info(LogMarkers.SENSITIVE,
"'{}' ({}) unmuted the user '{}' ({}) in guild '{}' for reason '{}'.",
author.getUser().getAsTag(), author.getId(), target.getUser().getAsTag(),
target.getId(), guild.getName(), reason);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.config.Config;
import org.togetherjava.tjbot.logging.LogMarkers;

import javax.annotation.Nullable;
import java.util.Objects;
Expand Down Expand Up @@ -86,7 +87,8 @@ private static MessageEmbed sendFeedback(boolean hasSentDm, Member target, Membe

private AuditableRestAction<Void> unquarantineUser(Member target, Member author, String reason,
Guild guild) {
logger.info("'{}' ({}) unquarantined the user '{}' ({}) in guild '{}' for reason '{}'.",
logger.info(LogMarkers.SENSITIVE,
"'{}' ({}) unquarantined the user '{}' ({}) in guild '{}' for reason '{}'.",
author.getUser().getAsTag(), author.getId(), target.getUser().getAsTag(),
target.getId(), guild.getName(), reason);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.slf4j.LoggerFactory;
import org.togetherjava.tjbot.commands.CommandVisibility;
import org.togetherjava.tjbot.commands.SlashCommandAdapter;
import org.togetherjava.tjbot.logging.LogMarkers;

import javax.annotation.Nullable;
import java.util.Objects;
Expand Down Expand Up @@ -69,7 +70,7 @@ private static RestAction<Boolean> dmUser(ISnowflake target, String reason, Guil
}

private void warnUser(User target, Member author, String reason, Guild guild) {
logger.info("'{}' ({}) warned the user '{}' ({}) for reason '{}'.",
logger.info(LogMarkers.SENSITIVE, "'{}' ({}) warned the user '{}' ({}) for reason '{}'.",
author.getUser().getAsTag(), author.getId(), target.getAsTag(), target.getId(),
reason);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.togetherjava.tjbot.commands.utils.MessageUtils;
import org.togetherjava.tjbot.config.Config;
import org.togetherjava.tjbot.config.ScamBlockerConfig;
import org.togetherjava.tjbot.logging.LogMarkers;

import java.awt.Color;
import java.util.*;
Expand Down Expand Up @@ -176,7 +177,8 @@ private void addScamToHistory(MessageReceivedEvent event) {
}

private void logScamMessage(MessageReceivedEvent event) {
logger.warn("Detected a scam message ('{}') from user '{}' in channel '{}' of guild '{}'.",
logger.warn(LogMarkers.SENSITIVE,
"Detected a scam message ('{}') from user '{}' in channel '{}' of guild '{}'.",
event.getMessageId(), event.getAuthor().getId(), event.getChannel().getId(),
event.getGuild().getId());
}
Expand Down Expand Up @@ -281,7 +283,7 @@ public void onButtonClick(ButtonInteractionEvent event, List<String> argsRaw) {
MessageUtils.disableButtons(event.getMessage());
event.deferEdit().queue();
if (event.getButton().getStyle() == ButtonStyle.DANGER) {
logger.info(
logger.info(LogMarkers.SENSITIVE,
"Identified a false-positive scam (id '{}', hash '{}') in guild '{}' sent by author '{}'",
args.messageId, args.contentHash, args.guildId, args.authorId);
return;
Expand All @@ -307,7 +309,7 @@ public void onButtonClick(ButtonInteractionEvent event, List<String> argsRaw) {
TextChannel channel = guild.getTextChannelById(scamMessage.channelId());
if (channel == null) {
logger.debug(
"Attempted to delete scam messages, bot the channel '{}' does not exist anymore, skipping deleting messages for this channel.",
"Attempted to delete scam messages, but the channel '{}' does not exist anymore, skipping deleting messages for this channel.",
scamMessage.channelId());
return;
}
Expand All @@ -318,10 +320,10 @@ public void onButtonClick(ButtonInteractionEvent event, List<String> argsRaw) {

Consumer<Throwable> onRetrieveAuthorFailure = new ErrorHandler()
.handle(ErrorResponse.UNKNOWN_USER,
failure -> logger.debug(
failure -> logger.debug(LogMarkers.SENSITIVE,
"Attempted to handle scam, but user '{}' does not exist anymore.",
args.authorId))
.handle(ErrorResponse.UNKNOWN_MEMBER, failure -> logger.debug(
.handle(ErrorResponse.UNKNOWN_MEMBER, failure -> logger.debug(LogMarkers.SENSITIVE,
"Attempted to handle scam, but user '{}' is not a member of the guild anymore.",
args.authorId));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.dv8tion.jda.api.exceptions.ErrorResponseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.togetherjava.tjbot.logging.LogMarkers;

/**
* Role based moderation actions that can be revoked, for example a {@link TemporaryMuteAction} or a
Expand All @@ -28,10 +29,10 @@ public FailureIdentification handleRevokeFailure(Throwable failure, long targetI

if (failure instanceof ErrorResponseException errorResponseException) {
switch (errorResponseException.getErrorResponse()) {
case UNKNOWN_USER -> logger.debug(
case UNKNOWN_USER -> logger.debug(LogMarkers.SENSITIVE,
"Attempted to revoke a temporary {} but user '{}' does not exist anymore.",
actionName, targetId);
case UNKNOWN_MEMBER -> logger.debug(
case UNKNOWN_MEMBER -> logger.debug(LogMarkers.SENSITIVE,
"Attempted to revoke a temporary {} but user '{}' is not a member of the guild anymore.",
actionName, targetId);
case UNKNOWN_ROLE -> logger.warn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.togetherjava.tjbot.commands.moderation.ModerationAction;
import org.togetherjava.tjbot.logging.LogMarkers;

/**
* Action to revoke temporary bans, as applied by
Expand Down Expand Up @@ -36,14 +37,14 @@ public RestAction<Void> revokeAction(Guild guild, User target, String reason) {
public FailureIdentification handleRevokeFailure(Throwable failure, long targetId) {
if (failure instanceof ErrorResponseException errorResponseException) {
if (errorResponseException.getErrorResponse() == ErrorResponse.UNKNOWN_USER) {
logger.debug(
logger.debug(LogMarkers.SENSITIVE,
"Attempted to revoke a temporary ban but user '{}' does not exist anymore.",
targetId);
return FailureIdentification.KNOWN;
}

if (errorResponseException.getErrorResponse() == ErrorResponse.UNKNOWN_BAN) {
logger.debug(
logger.debug(LogMarkers.SENSITIVE,
"Attempted to revoke a temporary ban but the user '{}' is not banned anymore.",
targetId);
return FailureIdentification.KNOWN;
Expand Down
Loading