A Telegram group vote-based kick bot using Cloudflare Workers + D1 database with weighted voting and new member verification system.
votekick/
├── src/
│ ├── index.ts # Worker entry point (Webhook + Cron)
│ ├── telegram.ts # Telegram API wrapper
│ ├── types.ts # TypeScript type definitions
│ ├── renderService.ts # UI rendering
│ ├── db/
│ │ ├── usersRepo.ts # User database operations
│ │ ├── votesRepo.ts # Vote database operations
│ │ ├── voteRecordsRepo.ts # Vote records database operations
│ │ ├── verificationsRepo.ts # Verification records database operations
│ │ ├── pendingDeletionsRepo.ts # Pending deletions database operations
│ │ └── botMessagesRepo.ts # Bot messages database operations
│ └── services/
│ ├── voteService.ts # Core voting logic
│ ├── verificationService.ts # New member verification logic
│ ├── weightService.ts # Weight calculation service
│ └── botMessageService.ts # Bot message service
├── migrations/
│ ├── 0001_init.sql # Initial database schema
│ ├── 0002_add_verifications.sql # Verification feature extension
│ ├── 0003_add_bot_message_tracking.sql
│ └── create_pending_deletions.sql
├── scripts/
│ └── set-webhook.js # Telegram Webhook setup script
├── config/ # Configuration templates
├── docs/ # Documentation
├── wrangler.toml # Cloudflare Workers configuration
├── package.json
└── tsconfig.json
- Reply to a user's message and send
/kickto initiate a vote - Group members vote, user is kicked when approval weight reaches threshold
- Failed/expired votes are automatically cleaned up
- New members are recorded silently when joining
- Verification triggered on first message
- 1 minute verification timeout
- First failure kicks user, second failure permanently bans
- User reputation weights based on activity
- Vote power = √weight
- Dynamic kick threshold based on target's weight
- Cloudflare Account: https://cloudflare.com (Free)
- Node.js: https://nodejs.org (LTS recommended)
- Telegram Bot:
- Search
@BotFatheron Telegram - Send
/newbotand follow the instructions - Save your Bot Token
- Disable privacy mode for group usage:
/setprivacy→ Disabled
- Search
npm installnpx wrangler loginnpx wrangler d1 create votekick-dbCopy the database_id output and fill in wrangler.toml:
[[d1_databases]]
binding = "DB"
database_name = "votekick-db"
database_id = "YOUR_DATABASE_ID_HERE"# Run all migrations
npx wrangler d1 execute votekick-db --remote --file=migrations/0001_init.sql
npx wrangler d1 execute votekick-db --remote --file=migrations/0002_add_verifications.sql
npx wrangler d1 execute votekick-db --remote --file=migrations/0003_add_bot_message_tracking.sql
npx wrangler d1 execute votekick-db --remote --file=migrations/create_pending_deletions.sqlnpx wrangler secret put BOT_TOKEN
# Enter your Telegram Bot Tokennpx wrangler deployBOT_TOKEN=YOUR_BOT_TOKEN WORKER_URL=https://your-worker.workers.dev node scripts/set-webhook.js| Variable | Default | Description |
|---|---|---|
BASE_VOTE_THRESHOLD |
20 | Base kick threshold |
VOTE_DURATION_SECONDS |
300 | Vote duration (seconds) |
INITIATOR_COOLDOWN_SECONDS |
60 | Initiator cooldown (seconds) |
TARGET_COOLDOWN_SECONDS |
180 | Same target cooldown (seconds) |
MIN_WEIGHT_TO_INITIATE |
1.0 | Minimum weight to initiate vote |
ENABLE_VERIFICATION |
1 | Enable verification (1=yes, 0=no) |
Reputation Update Formula:
W_new = W_old × 0.90^Δd + log(1 + Δt * 0.002)
Δd= days since last update (time decay)Δt= seconds since last message (activity bonus)
Vote Power:
vote_power = W
Dynamic Threshold:
threshold = 20 × (1 + W / 7)
- Administrators/creators cannot be kicked
- Cannot kick bots
- Cannot kick yourself
- Cannot vote twice
- Initiator and target cooldown protection
Bot not responding?
- Ensure Bot has admin permissions
- Ensure Webhook is set correctly
- Check logs:
npx wrangler tail
Cannot kick users?
- Ensure Bot has "Ban Users" permission
- Group owners cannot be kicked (Telegram limitation)
How to disable verification?
- Set
ENABLE_VERIFICATION = "0"inwrangler.toml
/kick- Initiate vote to kick (reply to a message first)/start- Get usage guide (private chat)
This project is licensed under the GNU General Public License v2 (GPL-2.0). See LICENSE for full license text.
Key points:
- Free to use and modify
- Source code must be made available when distributing
- Derivative works must be distributed under the same license