File tree Expand file tree Collapse file tree 2 files changed +7
-3
lines changed
integrations/src/integrations/discord/api Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change 1
1
import { IProcessStreamContext } from '../../../types'
2
2
3
- const DISCORD_RATE_LIMIT = 50
4
- const DISCORD_RATE_LIMIT_TIME = 1
3
+ const DISCORD_RATE_LIMIT = 100
4
+ const DISCORD_RATE_LIMIT_TIME = 1 // 1 second
5
5
const REDIS_KEY = 'discord-request-count'
6
6
7
7
export const getRateLimiter = ( ctx : IProcessStreamContext ) => {
Original file line number Diff line number Diff line change @@ -19,14 +19,18 @@ export class RateLimiter implements IRateLimiter {
19
19
const requestCount = value === null ? 0 : parseInt ( value )
20
20
const canMakeRequest = requestCount < this . maxRequests
21
21
22
+ if ( requestCount === 0 ) {
23
+ await this . cache . set ( this . counterKey , '0' , this . timeWindowSeconds )
24
+ }
25
+
22
26
if ( ! canMakeRequest ) {
23
27
const sleepTime = this . timeWindowSeconds + Math . floor ( Math . random ( ) * this . maxRequests )
24
28
throw new RateLimitError ( sleepTime , endpoint )
25
29
}
26
30
}
27
31
28
32
public async incrementRateLimit ( ) {
29
- await this . cache . increment ( this . counterKey , 1 , this . timeWindowSeconds )
33
+ await this . cache . increment ( this . counterKey , 1 )
30
34
}
31
35
}
32
36
You can’t perform that action at this time.
0 commit comments