Skip to content

Commit 32397b4

Browse files
committed
Rewrite: cleaned up the entire project + added compatibility for grammY v2.0.
1 parent d27e937 commit 32397b4

70 files changed

Lines changed: 14859 additions & 1009 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test.yml

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,54 @@ name: Test and Build
22

33
on:
44
push:
5-
branches: [main]
5+
branches:
6+
- main
7+
- 'rc/**'
68
pull_request:
7-
branches: [main]
9+
branches:
10+
- main
811

912
jobs:
1013
test:
11-
strategy:
12-
matrix:
13-
node-version: [22.x, 24.x]
14-
1514
runs-on: ubuntu-latest
1615

16+
services:
17+
redis:
18+
image: redis:8-alpine
19+
ports:
20+
- 6379:6379
21+
options: >-
22+
--health-cmd "redis-cli ping"
23+
--health-interval 10s
24+
--health-timeout 5s
25+
--health-retries 5
26+
1727
steps:
1828
- name: Checkout repository
19-
uses: actions/checkout@v4
29+
uses: actions/checkout@v6
2030

2131
- name: Setup Deno
2232
uses: denoland/setup-deno@v2
2333
with:
24-
deno-version: v2.x
34+
deno-version: 2.9.5
35+
cache: true
2536

2637
- name: Setup Node.js
27-
uses: actions/setup-node@v4
38+
uses: actions/setup-node@v6
2839
with:
29-
node-version: ${{ matrix.node-version }}
40+
node-version: 22
41+
package-manager-cache: false
42+
43+
- name: Configure JSR npm bridge
44+
run: echo '@jsr:registry=https://npm.jsr.io' >> "$HOME/.npmrc"
3045

3146
- name: Install dependencies
32-
run: deno ci
47+
run: deno install --frozen
48+
49+
- name: Run release checks
50+
run: npm run release:check
3351

34-
- name: Validate
35-
run: npm test
52+
- name: Run real Redis integration tests
53+
env:
54+
RATELIMITER_REDIS_URL: redis://127.0.0.1:6379
55+
run: deno task test:redis

README.md

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
1-
[![Test and Build](https://github.com/Amir-Zouerami/ratelimiter/actions/workflows/test.yml/badge.svg)](https://github.com/Amir-Zouerami/ratelimiter/actions/workflows/test.yml)
2-
31
# Rate Limit Users (`ratelimiter`)
42

5-
`ratelimiter` is an advanced and flexible middleware for the grammY framework, designed to protect
6-
Telegram bots from spam and resource abuse.
3+
`ratelimiter` is a flexible rate-limiting middleware for grammY with Deno and Node.js support.
74

8-
<p align="center">
9-
<a href="https://github.com/grammyjs/ratelimiter">
10-
<img src="./grammy-ratelimiter-cover.jpg" alt="grammY rate limiter cover">
11-
</a>
12-
</p>
5+
## Usage
136

14-
At its core, `ratelimiter` acts as a configurable gatekeeper for incoming updates. It allows
15-
developers to define precise rules for how many messages a user or chat (or any arbitrary entity)
16-
can send in a given period, ensuring the bot remains responsive and server resources are protected
17-
from overload.
7+
See the [official grammY rate limiter documentation](https://grammy.dev/plugins/ratelimiter) for
8+
installation and usage.
189

19-
The plugin inspects each incoming message, identifies its source, and decides if it should be
20-
processed or dismissed based on the rules you set.
10+
## Development
2111

22-
> **For more information and how-to instructions, please visit**
23-
> [**the official grammY ratelimiter documentation.**](https://grammy.dev/plugins/ratelimiter)
12+
Deno is the source runtime; the npm package is generated for Node.js with `deno2node`. Keep public
13+
APIs strongly typed, documented with JSDoc, and covered in both runtimes.
2414

25-
## License
15+
```sh
16+
deno task ok
17+
npm run typecheck
18+
npm run lint
19+
npm run test:node
20+
```
2621

27-
Distributed under the MIT License. See `LICENSE` for more information.
22+
Run `deno task test:redis` separately against a disposable Redis instance when changing Redis-backed
23+
behavior.

deno.jsonc

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
{
22
"name": "@grammyjs/ratelimiter",
33
"version": "2.0.0",
4-
"exports": "./mod.ts",
4+
"exports": {
5+
".": "./mod.ts",
6+
"./storages": "./storages.ts"
7+
},
8+
"publish": {
9+
"include": [
10+
"LICENSE",
11+
"README.md",
12+
"deno.jsonc",
13+
"grammy-ratelimiter-cover.jpg",
14+
"mod.ts",
15+
"storages.ts",
16+
"src/"
17+
]
18+
},
519
"lock": {
620
"frozen": true
721
},
@@ -13,11 +27,15 @@
1327
]
1428
},
1529
"tasks": {
16-
"check": "deno check mod.ts storages.ts ./src/ tests/core.test.ts",
17-
"test": "deno test tests/core.test.ts",
30+
"check": "deno check mod.ts storages.ts ./src/ tests/runtime/ tests/contracts/ tests/support/ tests/integration/",
31+
"test:runtime": "deno test tests/runtime/",
32+
"test:types": "deno check tests/types/public_api.test.ts",
33+
"test": "deno task test:runtime && deno task test:types",
34+
"test:redis": "deno test --allow-env=RATELIMITER_REDIS_URL --allow-net tests/integration/redis.integration.test.ts",
1835
"ok": "deno fmt --check && deno lint && deno task test && deno task check",
1936
"fix": "deno fmt && deno lint --fix",
20-
"dev": "deno run --watch --allow-all examples/basic.ts"
37+
"dev": "deno run --watch --allow-env=BOT_TOKEN --allow-net=api.telegram.org examples/local-deno-bot.ts",
38+
"doc:lint": "deno doc --lint mod.ts storages.ts"
2139
},
2240
"fmt": {
2341
"useTabs": true,
@@ -27,10 +45,13 @@
2745
},
2846
"compilerOptions": {
2947
"strict": true,
30-
"lib": ["deno.ns", "deno.window"]
48+
"lib": [
49+
"deno.ns",
50+
"deno.window"
51+
]
3152
},
3253
"imports": {
33-
"@grammyjs/grammy": "jsr:@grammyjs/grammy@2.0.0-beta.6",
54+
"@grammyjs/grammy": "jsr:@grammyjs/grammy@2.0.0-beta.8",
3455
"@std/assert": "jsr:@std/assert@^1.0.19"
3556
}
3657
}

0 commit comments

Comments
 (0)