@@ -28,25 +28,35 @@ public static async Task<bool> OnMessageCreated(DiscordClient client, MessageCre
2828 Config . Log . Debug ( $ "Removed checkpoint spam message from user { author . Username } ({ author . Id } ) in #{ msg . Channel ? . Name } ") ;
2929 return false ;
3030 }
31-
32- if ( msg . Content is not { Length : > 0 } )
33- return true ;
31+
3432
3533 if ( MessageCache . TryGetValue ( author . Id , out var item )
36- && item is ( DiscordMessage { Content . Length : > 0 } lastMessage , bool isWarned )
37- && lastMessage . Content == msg . Content
34+ && item is ( DiscordMessage lastMessage , bool isWarned )
35+ && SameContent ( lastMessage , msg )
3836 && lastMessage . ChannelId != msg . ChannelId )
3937 {
4038 var removedSpam = false ;
4139 try
4240 {
4341 await msg . DeleteAsync ( "spam" ) . ConfigureAwait ( false ) ;
42+ removedSpam = true ;
43+
44+ var newMsgContent = "<???>" ;
45+ if ( msg . Content is { Length : > 0 } )
46+ {
47+ newMsgContent = msg . Content ;
48+ }
49+ else if ( msg is { Attachments . Count : > 0 } )
50+ {
51+ foreach ( var att in msg . Attachments )
52+ newMsgContent += $ "📎 { att . FileName } \n ";
53+ newMsgContent = newMsgContent . TrimEnd ( ) ;
54+ }
4455 Config . Log . Debug ( $ """
4556 Removed spam message from user { author . Username } ({ author . Id } ) in #{ msg . Channel ? . Name } :
46- { msg . Content . Trim ( ) }
57+ { newMsgContent . Trim ( ) }
4758 """
4859 ) ;
49- removedSpam = true ;
5060 }
5161 catch ( Exception e )
5262 {
@@ -71,4 +81,19 @@ public static async Task<bool> OnMessageCreated(DiscordClient client, MessageCre
7181 MessageCache . Set ( author . Id , ( msg , false ) , DefaultExpiration ) ;
7282 return true ;
7383 }
84+
85+ private static bool SameContent ( DiscordMessage msg1 , DiscordMessage msg2 )
86+ {
87+ if ( msg1 is { Content . Length : > 0 }
88+ && msg2 is { Content . Length : > 0 }
89+ && msg1 . Content == msg2 . Content )
90+ return true ;
91+
92+ if ( msg1 is { Attachments . Count : > 0 }
93+ && msg2 is { Attachments . Count : > 0 }
94+ && msg1 . Attachments . SequenceEqual ( msg2 . Attachments , DiscordAttachmentComparer . Instance ) )
95+ return true ;
96+
97+ return false ;
98+ }
7499}
0 commit comments