Skip to content

Kernel Python Telegram Bot. A modular Telegram bot powered by python-telegram-bot. This bot is designed for scalability, maintainability, and follows clean architecture principles.

License

Notifications You must be signed in to change notification settings

LoboGuardian/kernel-python-telegram-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ› οΈ Kernel Python Telegram Bot

A modular Telegram bot powered by python-telegram-bot.
This bot is designed for scalability, maintainability, and follows clean architecture principles.

Features

  • Uses python-telegram-bot for handling Telegram interactions.
  • Structured with SOLID principles for modularity.
  • Poetry-based dependency management (previously Pipenv).
  • Built-in error handling and logging.
  • Uses environment variables (.env) to store sensitive data.

Upcoming Enhancements & Next Steps

We are actively improving the kernel to be more reusable, scalable, and efficient. The following enhancements are planned:

  • Short-Term Goals

    • Support for Webhooks: Implement run_webhook() to allow event-driven execution.
    • Testing with SQLite: Create unit tests using pytest for config_loader.py, database.py, and handlers.
    • Verify PostgreSQL Integration: Ensure database compatibility with PostgreSQL.
  • Mid-Term Goals

    • Plugin System for Dynamic Modules: Load new commands automatically from src/plugins/.
    • Multi-language Support (i18n): Implement a translation system with JSON-based locales.
    • Message Middleware: Filter messages before they reach command handlers.
  • Long-Term Goals

    • Redis Caching for Performance Optimization: Store user sessions in memory for faster responses.
    • External API Integration: Create api_client.py for connecting with third-party services.
    • WebSockets for Real-Time Events: Enable instant notifications and live event handling.
    • Admin Dashboard with FastAPI: Develop an API to manage and monitor the bot remotely.

Installation & Setup

Check SETUP.md

β–Ά Running the Bot

You can start the bot in two ways:

1. Using Poetry

poetry run python src/main.py

2. Using the run.sh Script

Make sure run.sh is executable:

chmod +x run.sh
./run.sh

3. Using Webhooks (Coming Soon)

poetry run python src/main.py --webhook

** Project Structure**

kernel-telegram-bot/
β”œβ”€β”€ src/                          # Core application logic
β”‚   β”œβ”€β”€ __init__.py               # Marks the src directory as a package
β”‚   β”œβ”€β”€ main.py                   # Bot entry point and event loop starter
β”‚   β”‚
β”‚   β”œβ”€β”€ handlers/                 # Telegram command handlers (organized by category)
β”‚   β”‚   β”œβ”€β”€ __init__.py           # Initializes the handlers package
β”‚   β”‚   β”œβ”€β”€ common/                   # General-purpose commands
β”‚   β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”‚   β”œβ”€β”€ start.py              # Handles the /start command
β”‚   β”‚   β”‚   β”œβ”€β”€ help.py               # Provides a list of available commands (/help)
β”‚   β”‚   β”‚   β”œβ”€β”€ ping.py               # Health check (/ping)
β”‚   β”‚   β”‚   └── about.py              # Shows bot info (/about)
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ fun/                      # Fun and entertainment-related commands
β”‚   β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”‚   β”œβ”€β”€ joke.py               # Returns a random joke (/joke)
β”‚   β”‚   β”‚   β”œβ”€β”€ roll.py               # Rolls a dice emoji (/roll)
β”‚   β”‚   β”‚   └── quote.py              # (Optional) Sends a random quote (/quote)
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ utility/                  # Utility commands (tools, lookups, etc.)
β”‚   β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”‚   β”œβ”€β”€ weather.py            # Fetches weather info for a city (/weather <city>)
β”‚   β”‚   β”‚   β”œβ”€β”€ currency.py           # Converts currency values (/currency USD EUR 100)
β”‚   β”‚   β”‚   β”œβ”€β”€ echo.py               # Repeats the user's input (/echo <text>)
β”‚   β”‚   β”‚   └── time.py               # Shows current server time (/time)
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ admin/
β”‚   β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”‚   β”œβ”€β”€ status.py             # /status - Check bot or system status
β”‚   β”‚   β”‚   β”œβ”€β”€ ban.py                # /ban <user_id> - Ban a user
β”‚   β”‚   β”‚   β”œβ”€β”€ unban.py              # /unban <user_id> - Unban a user
β”‚   β”‚   β”‚   β”œβ”€β”€ list_groups.py        # /listgroups - List groups where the bot is active
β”‚   β”‚   β”‚   β”œβ”€β”€ leave_group.py        # /leavegroup <group_id> - Force the bot to leave a group
β”‚   β”‚   β”‚   β”œβ”€β”€ broadcast.py          # /broadcast <message> - Send message to all groups/channels
β”‚   β”‚   β”‚   β”œβ”€β”€ admins.py             # /admins - List group/channel admins
β”‚   β”‚   β”‚   β”œβ”€β”€ promote.py            # /promote <user_id>
β”‚   β”‚   β”‚   β”œβ”€β”€ demote.py             # /demote <user_id>
β”‚   β”‚   β”‚   β”œβ”€β”€ mute.py               # /mute <user_id> [duration]
β”‚   β”‚   β”‚   β”œβ”€β”€ unmute.py             # /unmute <user_id>
β”‚   β”‚   β”‚   β”œβ”€β”€ warn.py               # /warn <user_id> - Issue warning
β”‚   β”‚   β”‚   β”œβ”€β”€ kick.py               # /kick <user_id> - Kick user
β”‚   β”‚   β”‚   β”œβ”€β”€ purge.py              # /purge - Clean messages
β”‚   β”‚   β”‚   β”œβ”€β”€ set_rules.py          # /setrules <text> - Define rules
β”‚   β”‚   β”‚   β”œβ”€β”€ rules.py              # /rules - Show current rules
β”‚   β”‚   β”‚   └── pin_message.py        # /pin - Pin the replied message (admin only)
β”‚   β”‚   β”‚
β”‚   β”‚   └── fallback/                 # Fallbacks and error handlers
β”‚   β”‚       β”œβ”€β”€ __init__.py
β”‚   β”‚       β”œβ”€β”€ unknown.py            # Handles unknown or invalid commands
β”‚   β”‚       └── errors.py             # Global error and exception handling
β”‚   β”‚
β”‚   β”œβ”€β”€ services/                 # Business logic and backend integrations
β”‚   β”‚   β”œβ”€β”€ __init__.py           # Initializes the services package
β”‚   β”‚   β”œβ”€β”€ auth.py               # User authentication and permission checks
β”‚   β”‚   β”œβ”€β”€ database.py           # Data persistence (supports SQLite & PostgreSQL)
β”‚   β”‚   β”œβ”€β”€ cache.py              # (Planned) Redis-based caching for performance
β”‚   β”‚   β”œβ”€β”€ api_client.py         # (Planned) Integration with third-party APIs
β”‚   β”‚
β”‚   β”œβ”€β”€ utils/                    # Utility modules for shared logic
β”‚   β”‚   β”œβ”€β”€ __init__.py           # Initializes the utils package
β”‚   β”‚   β”œβ”€β”€ config_loader.py      # Loads environment variables and settings
β”‚   β”‚   β”œβ”€β”€ logger.py             # Sets up structured logging for the app
β”‚   β”‚   β”œβ”€β”€ middleware.py         # (Planned) Preprocessing for messages (e.g., spam filtering)
β”‚   β”‚
β”‚   β”œβ”€β”€ plugins/                  # (Planned) Dynamic plugin loader for modular extensions
β”‚   β”œβ”€β”€ locales/                  # (Planned) Internationalization and language packs
β”‚   β”œβ”€β”€ dashboard/                # (Planned) FastAPI-powered admin panel for bot management
β”‚   β”œβ”€β”€ config.py                 # Centralized bot configuration and constants
β”‚
β”œβ”€β”€ tests/                        # Automated unit and integration tests
β”‚   β”œβ”€β”€ test_config.py            # Tests for configuration loading
β”‚   β”œβ”€β”€ test_database.py          # Tests for data persistence logic
β”‚   β”œβ”€β”€ test_handlers.py          # Tests for Telegram command responses
β”‚
β”œβ”€β”€ docs/                         # Documentation and guides
β”‚   β”œβ”€β”€ SETUP.md                  # How to install and configure the bot
β”‚   β”œβ”€β”€ TESTING.md                # How to write and run tests
β”‚   β”œβ”€β”€ DEPLOYMENT.md             # Deployment guide and best practices
β”‚
β”œβ”€β”€ .gitignore                    # Specifies intentionally untracked files to ignore in Git
β”œβ”€β”€ .env                          # Environment-specific variables (e.g., API keys, tokens)
β”œβ”€β”€ LICENSE                       # License file for open source usage terms
β”œβ”€β”€ README.md                     # Main project overview and usage documentation
β”œβ”€β”€ CODE_OF_CONDUCT.md            # Guidelines for respectful community behavior
β”œβ”€β”€ AUTHORS.md                    # List of project authors and contributors
β”œβ”€β”€ CONTRIBUTING.md               # Instructions for contributing to the project
β”œβ”€β”€ pyproject.toml                # Project configuration for Poetry (dependencies, metadata)
β”œβ”€β”€ poetry.lock                   # Locked dependency versions for reproducible builds
└── run.sh                        # Shell script to launch the bot with one command

**Running Tests

To run unit tests:

poetry run pytest

**Development & Contribution

Fork this repository.

Clone your fork:

git clone https://github.com/LoboGuardian/kernel-telegram-bot.git

Install dependencies:

poetry install

Create a feature branch:

git checkout -b feature/new-feature

Make changes and commit:

git commit -m "Added a new feature"
Push and create a pull request.

License

This project is licensed under the GPL-3.0 License. See the LICENSE file for details.

Credits & Contact


Contribution & Future Development

We welcome contributions! Our current focus areas include:

  • Expanding testing coverage.

  • Optimizing database performance.

  • Enhancing real-time event handling with WebSockets.

  • If you want to contribute, fork the repo and submit a PR.

Feel free to discuss improvements via GitHub Issues.

About

Kernel Python Telegram Bot. A modular Telegram bot powered by python-telegram-bot. This bot is designed for scalability, maintainability, and follows clean architecture principles.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages