diff --git a/build.gradle b/build.gradle index a69e18a..ad4e63c 100644 --- a/build.gradle +++ b/build.gradle @@ -31,7 +31,7 @@ tasks.withType(JavaCompile) { options.encoding = "UTF-8" } -version = '2.6.0' +version = '2.6.1' sourceCompatibility = 1.8 mainClassName = 'de.nikos410.discordbot.DiscordBot' diff --git a/src/main/java/de/nikos410/discordbot/util/discord/DiscordIO.java b/src/main/java/de/nikos410/discordbot/util/discord/DiscordIO.java index 5823700..8c297d2 100644 --- a/src/main/java/de/nikos410/discordbot/util/discord/DiscordIO.java +++ b/src/main/java/de/nikos410/discordbot/util/discord/DiscordIO.java @@ -92,7 +92,7 @@ private static synchronized IMessage sendSingleMessage(final IChannel channel, f private static synchronized IMessage sendSingleMessage(final IChannel channel, final String message, final int tries){ try { - return channel.sendMessage(message); + return channel.sendMessage(sanitizeMessage(message)); } catch (RateLimitException rle) { if (tries > 0) { @@ -175,9 +175,9 @@ public static synchronized IMessage sendFile(final IChannel channel, final Strin return sendFile(channel, content, file, 20); } - private static IMessage sendFile(final IChannel channel, final String content, final File file, final int tries) { + private static IMessage sendFile(final IChannel channel, final String message, final File file, final int tries) { try { - return channel.sendFile(content, file); + return channel.sendFile(sanitizeMessage(message), file); } catch (RateLimitException rle) { if (tries > 0) { @@ -191,7 +191,7 @@ private static IMessage sendFile(final IChannel channel, final String content, f Thread.currentThread().interrupt(); } - return sendFile(channel, content, file, tries - 1); + return sendFile(channel, message, file, tries - 1); } else { LOG.warn("Bot was ratelimited while trying to send file.", rle); @@ -207,6 +207,16 @@ private static IMessage sendFile(final IChannel channel, final String content, f return null; } + /** + * Sanitize a message by replacing "@everyone" with "(at)everyone" + * + * @param message The message to be sanitized + * @return The sanitized message + */ + public static String sanitizeMessage(final String message) { + return message.replaceAll("@everyone", "(at)everyone"); + } + /** * Send a notification about an error to a channel. *