Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/geekuillaume/chatup-ratelimiter
https://github.com/geekuillaume/chatup-ratelimiter
Last synced: 7 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/geekuillaume/chatup-ratelimiter
- Owner: geekuillaume
- Created: 2015-12-09T21:50:00.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-12-10T17:59:25.000Z (about 9 years ago)
- Last Synced: 2024-11-29T18:45:34.512Z (24 days ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ChatUp Rate Limiter Plugin
A Chatup plugin to limit the number of messages a user can send and avoid spamming.
## How does it works
You declare rules in `X` messages per `Y` seconds. If the last `X` messages have been sent in less then `Y` seconds, the rule is exceeded and the banning level of the user is incremented.
The banning level are just increasing period of times. When a user is limited, he cannot send a message during the period of time `Z` specified by the level. After being unbanned, if he exceed a rule before `Z` seconds, his level is increased once again. If he doesn't break a rule after this time, his last level go back to -1.
You can specify as much rules and levels as you want.
## Example
Start by installing `chatup-ratelimiter` npm module with `npm install --save chatup-ratelimiter`, then in your ChatUp worker file, do something like this:
```js
var conf = {}; // Your configuration
var worker = new ChatUp.ChatWorker(conf);worker.registerMiddleware(require('chatup-ratelimiter')({
redisPrefix: 'chatup:ratelimiter',
levelIncreaseRules:[{
messages: 15,
time: 30
}, {
messages: 5,
time: 5
}],
levels: [30, 2 * 60, 10 * 60, 30 * 60]
}));worker.listen();
```