@@ -116,6 +116,7 @@ public static async Task MessageHandlerAsync(DiscordClient client, DiscordMessag
116
116
}
117
117
public static async Task MessageHandlerAsync ( DiscordClient client , MockDiscordMessage message , DiscordChannel channel , bool isAnEdit = false , bool limitFilters = false , bool wasAutoModBlock = false )
118
118
{
119
+ #region combine all message text
119
120
// Get forwarded msg & embeds, if any, and combine with content to evaluate
120
121
// Combined as a single long string
121
122
@@ -160,9 +161,11 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe
160
161
msgContentWithEmbedData += $ " { field . Name } { field . Value } ";
161
162
}
162
163
}
164
+ #endregion
163
165
164
166
try
165
167
{
168
+ #region return early checks
166
169
if ( message . Timestamp is not null && message . Timestamp . Value . Year < ( DateTime . Now . Year - 2 ) )
167
170
return ;
168
171
@@ -171,7 +174,9 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe
171
174
172
175
if ( message . Author is null || message . Author . Id == client . CurrentUser . Id )
173
176
return ;
177
+ #endregion
174
178
179
+ #region debug logging
175
180
if ( wasAutoModBlock )
176
181
{
177
182
Program . discord . Logger . LogDebug ( "Processing AutoMod-blocked message in {channelId} by user {userId}" , channel . Id , message . Author . Id ) ;
@@ -182,9 +187,11 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe
182
187
{
183
188
Program . discord . Logger . LogDebug ( "Processing message {messageId} in {channelId} by user {userId}" , message . Id , channel . Id , message . Author . Id ) ;
184
189
}
190
+ #endregion
185
191
186
192
if ( ! limitFilters )
187
193
{
194
+ #region tracked user relaying
188
195
if ( Program . db . SetContains ( "trackedUsers" , message . Author . Id ) )
189
196
{
190
197
// Check current channel against tracking channels
@@ -206,13 +213,17 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe
206
213
await RelayTrackedMessageAsync ( client , message ) ;
207
214
}
208
215
}
216
+ #endregion
209
217
218
+ #region DM relaying
210
219
if ( ! isAnEdit && channel . IsPrivate && Program . cfgjson . LogChannels . ContainsKey ( "dms" ) )
211
220
{
212
221
DirectMessageEvent . DirectMessageEventHandler ( message . BaseMessage ) ;
213
222
return ;
214
223
}
224
+ #endregion
215
225
226
+ #region modmail thread handling
216
227
if ( ! isAnEdit && message . Author . Id == Program . cfgjson . ModmailUserId && message . Content == "@here" && message . Embeds [ 0 ] . Footer . Text . Contains ( "User ID:" ) )
217
228
{
218
229
Program . discord . Logger . LogDebug ( Program . CliptokEventID , "Processing modmail message {message} in {channel}" , message . Id , channel ) ;
@@ -274,7 +285,9 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe
274
285
await LogChannelHelper . LogMessageAsync ( "mod" , $ "{ Program . cfgjson . Emoji . Deleted } Note `{ note . Value . NoteId } ` was automatically deleted after modmail thread creation (belonging to { modmailMember . Mention } )", embed ) ;
275
286
}
276
287
}
288
+ #endregion
277
289
290
+ #region giveaways handling
278
291
// handle #giveaways
279
292
if ( ! isAnEdit && message . Author . Id == Program . cfgjson . GiveawayBot && channel . Id == Program . cfgjson . GiveawaysChannel && message . Content == Program . cfgjson . GiveawayTriggerMessage )
280
293
{
@@ -287,9 +300,10 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe
287
300
288
301
await message . BaseMessage . CreateThreadAsync ( giveawayTitle , DiscordAutoArchiveDuration . ThreeDays , "Automatically creating giveaway thread." ) ;
289
302
}
303
+ #endregion
290
304
}
291
305
292
- // automatic listupdate for private lists
306
+ #region automatic listupdate for private lists
293
307
if (
294
308
Program . cfgjson . GitListDirectory is not null
295
309
&& Program . cfgjson . GitListDirectory != ""
@@ -316,18 +330,23 @@ Program.cfgjson.GitListDirectory is not null
316
330
await msg . ModifyAsync ( $ "{ Program . cfgjson . Emoji . Success } Successfully updated and reloaded private lists!\n ```\n { result } \n ```") ;
317
331
}
318
332
}
333
+ #endregion
319
334
320
- // Skip DMs, external guilds, and messages from bots, beyond this point.
335
+ #region Skip DMs, external guilds, and messages from bots, beyond this point.
321
336
if ( channel . IsPrivate || channel . Guild . Id != Program . cfgjson . ServerID || message . Author . IsBot )
322
337
return ;
338
+ #endregion
323
339
340
+ #region mention relaying
324
341
if ( ! limitFilters && ! Program . cfgjson . MentionTrackExcludedChannels . Contains ( channel . Id ) && ( channel . ParentId is null || ! Program . cfgjson . MentionTrackExcludedChannels . Contains ( ( ulong ) channel . ParentId ) ) )
325
342
{
326
343
// track mentions
327
344
if ( message . MentionedUsers . Any ( x => x . Id == Program . discord . CurrentUser . Id ) )
328
345
await LogChannelHelper . LogMessageAsync ( "mentions" , await DiscordHelpers . GenerateMessageRelay ( message . BaseMessage , true , true , false ) ) ;
329
346
}
347
+ #endregion
330
348
349
+ #region retrieve member object
331
350
DiscordMember member ;
332
351
try
333
352
{
@@ -340,10 +359,12 @@ Program.cfgjson.GitListDirectory is not null
340
359
341
360
if ( member == default )
342
361
return ;
362
+ #endregion
343
363
344
- // Skip messages from moderators beyond this point.
364
+ #region content filters
345
365
if ( ( await GetPermLevelAsync ( member ) ) < ServerPermLevel . TrialModerator )
346
366
{
367
+ #region block messages in forum intro thread
347
368
if ( ! limitFilters )
348
369
{
349
370
if ( ( channel . Id == Program . cfgjson . SupportForumIntroThreadId ||
@@ -357,7 +378,9 @@ Program.cfgjson.GitListDirectory is not null
357
378
return ;
358
379
}
359
380
}
381
+ #endregion
360
382
383
+ #region mass mentions ban filter
361
384
if ( ( message . MentionedUsers is not null && message . MentionedUsers . Count > Program . cfgjson . MassMentionBanThreshold ) || ( message . MentionedUsersCount > Program . cfgjson . MassMentionBanThreshold ) )
362
385
{
363
386
if ( wasAutoModBlock )
@@ -378,7 +401,10 @@ Program.cfgjson.GitListDirectory is not null
378
401
_ = InvestigationsHelpers . SendInfringingMessaageAsync ( "mod" , message , "Mass mentions (Ban threshold)" , DiscordHelpers . MessageLink ( chatMsg ) , content : content , messageContentOverride : msgContentWithEmbedData , wasAutoModBlock : wasAutoModBlock ) ;
379
402
return ;
380
403
}
404
+ #endregion
381
405
406
+
407
+ #region restricted word list filters
382
408
bool match = false ;
383
409
384
410
// Matching word list
@@ -431,7 +457,9 @@ Program.cfgjson.GitListDirectory is not null
431
457
if ( match )
432
458
return ;
433
459
434
- // Unapproved invites
460
+ #endregion
461
+
462
+ #region invite filter
435
463
string checkedMessage = msgContentWithEmbedData . Replace ( '\\ ' , '/' ) ;
436
464
437
465
if ( ( await GetPermLevelAsync ( member ) ) < ( ServerPermLevel ) Program . cfgjson . InviteTierRequirement && checkedMessage . Contains ( "dsc.gg/" ) ||
@@ -571,7 +599,9 @@ Program.cfgjson.GitListDirectory is not null
571
599
if ( match )
572
600
return ;
573
601
574
- // Mass emoji
602
+ #endregion
603
+
604
+ #region mass emoji filter
575
605
if ( ! Program . cfgjson . UnrestrictedEmojiChannels . Contains ( channel . Id ) && msgContentWithEmbedData . Length >= Program . cfgjson . MassEmojiThreshold )
576
606
{
577
607
char [ ] tempArray = msgContentWithEmbedData . Replace ( "🏻" , "" ) . Replace ( "🏼" , "" ) . Replace ( "🏽" , "" ) . Replace ( "🏾" , "" ) . Replace ( "🏿" , "" ) . ToCharArray ( ) ;
@@ -635,7 +665,9 @@ Program.cfgjson.GitListDirectory is not null
635
665
await InvestigationsHelpers . SendInfringingMessaageAsync ( "investigations" , message , reason , warning . ContextLink , messageContentOverride : msgContentWithEmbedData , wasAutoModBlock : wasAutoModBlock ) ;
636
666
return ;
637
667
}
668
+ #endregion
638
669
670
+ #region tech support relaying
639
671
if ( ! limitFilters )
640
672
{
641
673
if ( channel . Id == Program . cfgjson . TechSupportChannel &&
@@ -683,9 +715,10 @@ Program.cfgjson.GitListDirectory is not null
683
715
_ = logOut . CreateReactionAsync ( DiscordEmoji . FromName ( client , ":CliptokAcknowledge:" , true ) ) ;
684
716
}
685
717
}
718
+ #endregion
686
719
}
687
720
688
- // phishing API
721
+ #region phishing API
689
722
var urlMatches = url_rx . Matches ( msgContentWithEmbedData ) ;
690
723
if ( urlMatches . Count > 0 && Environment . GetEnvironmentVariable ( "CLIPTOK_ANTIPHISHING_ENDPOINT" ) is not null && Environment . GetEnvironmentVariable ( "CLIPTOK_ANTIPHISHING_ENDPOINT" ) != "useyourimagination" )
691
724
{
@@ -716,8 +749,9 @@ Program.cfgjson.GitListDirectory is not null
716
749
}
717
750
}
718
751
}
752
+ #endregion
719
753
720
- // attempted to ping @ everyone/@ here
754
+ #region everyone/here ping filter
721
755
var msgContent = msgContentWithEmbedData ;
722
756
foreach ( var letter in Checks . ListChecks . lookalikeAlphabetMap )
723
757
msgContent = msgContent . Replace ( letter . Key , letter . Value ) ;
@@ -738,8 +772,9 @@ Program.cfgjson.GitListDirectory is not null
738
772
await InvestigationsHelpers . SendInfringingMessaageAsync ( "investigations" , message , reason , warning . ContextLink , messageContentOverride : msgContentWithEmbedData , wasAutoModBlock : wasAutoModBlock ) ;
739
773
return ;
740
774
}
775
+ #endregion
741
776
742
- // Mass mentions
777
+ #region mass mentions warn filter
743
778
if ( ( ( message . MentionedUsers is not null && message . MentionedUsers . Count >= Program . cfgjson . MassMentionThreshold ) || ( message . MentionedUsersCount >= Program . cfgjson . MassMentionThreshold ) ) && ( await GetPermLevelAsync ( member ) ) < ServerPermLevel . Tier3 )
744
779
{
745
780
if ( wasAutoModBlock )
@@ -766,8 +801,9 @@ Program.cfgjson.GitListDirectory is not null
766
801
await InvestigationsHelpers . SendInfringingMessaageAsync ( "investigations" , message , reason , warning . ContextLink , messageContentOverride : msgContentWithEmbedData , wasAutoModBlock : wasAutoModBlock ) ;
767
802
return ;
768
803
}
804
+ #endregion
769
805
770
- // line limit
806
+ #region line limit filter
771
807
var lineCount = CountNewlines ( msgContentWithEmbedData ) ;
772
808
773
809
if ( ! Program . cfgjson . LineLimitExcludedChannels . Contains ( channel . Id )
@@ -838,11 +874,13 @@ Program.cfgjson.GitListDirectory is not null
838
874
}
839
875
840
876
}
877
+ #endregion
841
878
}
879
+ #endregion
842
880
843
881
if ( ! limitFilters )
844
882
{
845
- // feedback hub forum
883
+ #region feedback hub forum validation
846
884
if ( ( await GetPermLevelAsync ( member ) ) < ServerPermLevel . TrialModerator && ! isAnEdit && channel . IsThread && channel . ParentId == Program . cfgjson . FeedbackHubForum && ! Program . db . SetContains ( "processedFeedbackHubThreads" , channel . Id ) )
847
885
{
848
886
var thread = ( DiscordThreadChannel ) channel ;
@@ -884,7 +922,9 @@ await LogChannelHelper.LogMessageAsync("messages",
884
922
}
885
923
}
886
924
}
925
+ #endregion
887
926
927
+ #region passive list matching
888
928
// Check the passive lists AFTER all other checks.
889
929
if ( ( await GetPermLevelAsync ( member ) ) >= ServerPermLevel . TrialModerator )
890
930
return ;
@@ -924,6 +964,7 @@ await InvestigationsHelpers.SendInfringingMessaageAsync(
924
964
}
925
965
}
926
966
}
967
+ #endregion
927
968
}
928
969
}
929
970
catch ( Exception e )
0 commit comments