-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d522e8f
commit 8774f02
Showing
5 changed files
with
51 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package uk.co.jkinc.Vaultier; | ||
|
||
import java.util.Date; | ||
|
||
public class RateLimiter { | ||
private static final int maxReqs = 60; // 1 every 30 seconds | ||
public static boolean ProcessRequest(String ApiKey) { | ||
Integer requestsThisPeriod = Vaultier.database.db.RateLimits.get(ApiKey); | ||
if (requestsThisPeriod == null) { | ||
requestsThisPeriod = 0; | ||
} | ||
|
||
long currentPeriod = new Date().getTime() / (1000 * 60 * 30); | ||
|
||
if (Vaultier.database.db.currentTimePeriod != currentPeriod) { | ||
Vaultier.database.db.RateLimits.clear(); | ||
return true; | ||
} | ||
|
||
if (requestsThisPeriod > maxReqs) { | ||
return false; | ||
} else { | ||
requestsThisPeriod+=1; | ||
Vaultier.database.db.RateLimits.put(ApiKey, requestsThisPeriod); | ||
return true; | ||
} | ||
} | ||
|
||
|
||
} |