Hey everyone! While building group game bots in Python, I kept running into two annoying reliability issues:

  1. Inline button & command spam — users rapidly tapping buttons, causing duplicate database writes or Telegram 429 Too Many Requests errors.
  2. Stale / overlapping round timers — background asyncio timers firing after a game round already restarted or ended.

I packaged my solution into a lightweight, zero-dependency Python library called TelePulse (built purely on time.monotonic, collections.deque, and asyncio). It works with aiogram, pyTelegramBotAPI, python-telegram-bot, or custom webhook handlers.

Install

pip install telepulse 

Quick Example

from aiogram import Router, types from telepulse import LimitResult, ScopedTimerManager, throttle router = Router() timers = ScopedTimerManager() async def on_spam(message: types.Message, result: LimitResult) -> None: await message.answer(f"Too fast! Try again in {result.retry_after}s.") # 1. Anti-flood decorator with optional penalty block @router.message() @throttle(rate=3, per=5.0, block_for=10.0, on_limited=on_spam) async def handle_action(message: types.Message) -> None: await message.answer("Action accepted!") # 2. Generation-guarded timers: scheduling the same scope cancels & invalidates the old timer async def finish_round(chat_id: int, round_id: int) -> None: print(f"Chat {chat_id}: Round {round_id} ended!") timers.schedule("chat:-100123:round", 30.0, finish_round, -100123, 1) timers.schedule("chat:-100123:round", 30.0, finish_round, -100123, 2) # Round 1 is safely cancelled 

It is MIT-licensed and currently at v0.1.0. I would love feedback from other bot developers — especially on whether adding native aiogram BaseMiddleware support would be useful for v0.2.0!