bot

command
v2.14.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 39 Imported by: 0

Documentation

Overview

This is the main executable package

This file implements a priority queue with per-user rate limiting for outgoing Telegram messages.

Producers call enqueueMessage which pushes packets into a buffered channel. A single sender goroutine owns a packetHeap, drains all pending packets from the channel into the heap each iteration, and sends the highest-priority ready packet.

The heap is a min-heap ordered by:

  1. readyAt time — earlier is better. Zero (default) means ready immediately. Rate-limited chats get a future readyAt and sink to the bottom.
  2. priority — lower value wins (db.PriorityHigh < db.PriorityLow)
  3. push sequence — global sequence counter

Per-user rate limiting: After each send, setReadyAt marks the chat as unavailable for 1 second. The heap re-sorts so other chats' packets flow while the rate-limited chat waits.

Cleanup: maxReadyAt entries are removed after they expire. A cleanup heap (min-heap by readyAt time) tracks per-chatID entries. Superseded entries (seq mismatch) are skipped. When an entry expires, its map entry is deleted and heap.Fix restores affected packets' heap positions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL