This is a Python-based Telegram bot that tracks and reports the longest period of inactivity between messages in a group.
- Monitors Inactivity: Tracks the time between messages in any group it's a part of.
- Per-Group Records: Each group has its own separate inactivity record.
- New Record Announcements: Optionally announces when a new longest period of inactivity is achieved.
- Simple Commands: Easy-to-use commands to check the record or configure the bot.
The bot is built using clean architecture principles to ensure it is maintainable, scalable, and testable.
- SOLID Principles: The codebase is designed following SOLID principles.
- Dependency Injection: Components are decoupled using dependency injection.
- Pluggable Storage: The storage mechanism is abstracted, starting with a simple JSON file (
db.json) but easily replaceable with a database.
Follow these steps to set up and run the bot locally.
git clone <your-repository-url>
cd longest-inactivity-trackerIt is highly recommended to use a Python virtual environment to manage dependencies.
python3 -m venv venvActivate the virtual environment and install the required packages from requirements.txt.
On macOS and Linux:
source venv/bin/activate
pip install -r requirements.txtOn Windows:
.\venv\Scripts\activate
pip install -r requirements.txtYou need to provide a Telegram Bot Token for the bot to work.
- Make a copy of the
.env.examplefile and name it.env. - Open the new
.envfile and replaceyour_token_herewith your actual token from BotFather.
TELEGRAM_BOT_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
Once the dependencies are installed and the configuration is set, you can run the bot.
python src/main.pyThe bot will start polling for updates from Telegram. You can add it to your groups and start using its commands.
For the bot to read all messages in a group, you must disable its "Group Privacy" mode.
- Open a chat with
@BotFatheron Telegram. - Send the command
/mybotsand select your bot. - Go to Bot Settings -> Group Privacy.
- Click "Turn off".
Without this step, the bot will only recognize commands and will not be able to track inactivity.
/startor/help- Shows the help message with all available commands./record- Displays the current longest inactivity record for the group./toggle_announcements- Enables or disables the announcement of new records in the group. (Admin only)/seed <minutes>- Sets an initial inactivity record for the specified number of minutes. (Admin only)/leaderboard- Shows the top 5 users for the "Last Word" and "Silence Breaker" awards./history- Displays the last 5 inactivity records that were set in the group./clean- Deletes all stored data for the group, including records, leaderboards, and history. (Admin only)
This project includes a launch configuration for Visual Studio Code. To run or debug the bot within VS Code:
- Make sure you have selected the Python interpreter from the
venvdirectory. - Go to the Run and Debug view (Ctrl+Shift+D).
- Select the "Python: Run Bot" configuration from the dropdown and press F5.