88import net .dv8tion .jda .api .Permission ;
99import net .dv8tion .jda .api .entities .Member ;
1010import net .dv8tion .jda .api .entities .Message ;
11+ import net .dv8tion .jda .api .entities .MessageReference ;
1112import net .dv8tion .jda .api .entities .channel .unions .MessageChannelUnion ;
13+ import net .dv8tion .jda .api .entities .messages .MessageSnapshot ;
1214import net .dv8tion .jda .api .events .message .MessageReceivedEvent ;
1315import net .dv8tion .jda .api .events .message .MessageUpdateEvent ;
1416import net .dv8tion .jda .api .hooks .ListenerAdapter ;
@@ -132,7 +134,7 @@ private void checkContentAutomod(@Nonnull Message message) {
132134 }
133135
134136 private void doAutomodActions (Message message , String reason ) {
135- notificationService .withGuild (message .getGuild ()).sendToModerationLog (c -> c .sendMessageFormat ("Message by %s: `%s`" , message .getAuthor ().getAsMention (), message . getContentRaw ( )));
137+ notificationService .withGuild (message .getGuild ()).sendToModerationLog (c -> c .sendMessageFormat ("Message by %s: `%s`" , message .getAuthor ().getAsMention (), getMessageContent ( message )));
136138 moderationService
137139 .warn (
138140 message .getAuthor (),
@@ -188,7 +190,7 @@ private void handleSpam(@Nonnull Message msg, Member member) {
188190 * @return True if a link is found and False if not.
189191 */
190192 public boolean hasSuspiciousLink (@ NotNull Message message ) {
191- final String messageRaw = message . getContentRaw ( );
193+ final String messageRaw = getMessageContent ( message );
192194 Matcher urlMatcher = URL_PATTERN .matcher (messageRaw );
193195 if (messageRaw .contains ("http://" ) || messageRaw .contains ("https://" )) {
194196 // only do it for a links, so it won't iterate for each message
@@ -217,7 +219,7 @@ public boolean hasSuspiciousLink(@NotNull Message message) {
217219 */
218220 public boolean hasAdvertisingLink (@ NotNull Message message ) {
219221 // Advertising
220- Matcher matcher = INVITE_URL .matcher (cleanString (message . getContentRaw ( )));
222+ Matcher matcher = INVITE_URL .matcher (cleanString (getMessageContent ( message )));
221223 int start = 0 ;
222224 while (matcher .find (start )) {
223225 if (botConfig .get (message .getGuild ()).getModerationConfig ().getAutomodInviteExcludes ().stream ().noneMatch (matcher .group ()::contains )) {
@@ -232,4 +234,16 @@ private boolean isSuggestionsChannel(@NotNull MessageChannelUnion channel) {
232234 return channel .getType ().isGuild () &&
233235 channel .getIdLong () == botConfig .get (channel .asGuildMessageChannel ().getGuild ()).getModerationConfig ().getSuggestionChannel ().getIdLong ();
234236 }
237+
238+ private String getMessageContent (Message msg ) {
239+ //see https://github.com/discord-jda/JDA/releases/tag/v5.1.2
240+ MessageReference messageReference = msg .getMessageReference ();
241+ if (messageReference != null && messageReference .getType () == MessageReference .MessageReferenceType .FORWARD ) {
242+ MessageSnapshot snapshot = msg .getMessageSnapshots ().get (0 );
243+ if (snapshot != null ) {
244+ return snapshot .getContentRaw ();
245+ }
246+ }
247+ return msg .getContentRaw ();
248+ }
235249}
0 commit comments