@@ -10,6 +10,26 @@ export const antiSpamMap = new Collection<string, AntiSpamUserOpts>();
1010const WINDOW_SIZE = 5000 ;
1111const MAX_STORE = 3 ;
1212
13+ /**
14+ * Sets spam timers for a given user.
15+ * @param userId - The ID of the user to set spam timers for.
16+ * @returns void
17+ */
18+ export const setSpamTimers = ( user : User ) => {
19+ const five_min = 60 * 5000 ;
20+ const userInCol = antiSpamMap . get ( user . id ) ;
21+ const scheduler = user . client . getScheduler ( ) ;
22+ const lastMsgTimestamp = userInCol ?. timestamps [ userInCol . timestamps . length - 1 ] ;
23+
24+ if ( lastMsgTimestamp && Date . now ( ) - five_min <= lastMsgTimestamp ) {
25+ scheduler . stopTask ( `removeFromCol_${ user . id } ` ) ;
26+ }
27+
28+ scheduler . addRecurringTask ( `removeFromCol_${ user . id } ` , new Date ( Date . now ( ) + five_min ) , ( ) => {
29+ antiSpamMap . delete ( user . id ) ;
30+ } ) ;
31+ } ;
32+
1333/**
1434 * Runs the anti-spam mechanism for a given user.
1535 * @param author - The user to run the anti-spam mechanism for.
@@ -56,23 +76,3 @@ export const runAntiSpam = (author: User, maxInfractions = MAX_STORE) => {
5676 } ) ;
5777 }
5878} ;
59-
60- /**
61- * Sets spam timers for a given user.
62- * @param userId - The ID of the user to set spam timers for.
63- * @returns void
64- */
65- export const setSpamTimers = ( user : User ) => {
66- const five_min = 60 * 5000 ;
67- const userInCol = antiSpamMap . get ( user . id ) ;
68- const scheduler = user . client . getScheduler ( ) ;
69- const lastMsgTimestamp = userInCol ?. timestamps [ userInCol . timestamps . length - 1 ] ;
70-
71- if ( lastMsgTimestamp && Date . now ( ) - five_min <= lastMsgTimestamp ) {
72- scheduler . stopTask ( `removeFromCol_${ user . id } ` ) ;
73- }
74-
75- scheduler . addRecurringTask ( `removeFromCol_${ user . id } ` , new Date ( Date . now ( ) + five_min ) , ( ) => {
76- antiSpamMap . delete ( user . id ) ;
77- } ) ;
78- } ;
0 commit comments