A sophisticated, extensible Telegram bot framework that enables anonymous message forwarding with a powerful plugin system. AnonkaReforged allows users to send anonymous messages to a designated channel while maintaining complete privacy and offering extensive customization through plugins.
- Features
- Requirements
- Installation
- Configuration
- Usage
- Project Structure
- Architecture Overview
- Core Components
- Plugin System
- Localization
- Environment Variables
- Error Handling
- Best Practices
- Contributing
- License
- Anonymous Message Forwarding: Users send messages privately, which are then forwarded to a public channel anonymously
- Bot Ignition System: Automatically filters out messages from other bots to prevent spam
- Multi-language Support: Built-in localization system supporting English, Ukrainian, Russian, Polish, Spanish, German, and French
- Asynchronous Architecture: Uses
aiogram(async Telegram bot API wrapper) for high-performance concurrent request handling
- Plugin System: Comprehensive plugin architecture for extending bot functionality without modifying core code
- Configuration Management: Environment-based configuration with fallback defaults
- Graceful Cleanup: Proper resource management with async cleanup handlers
- Comprehensive Logging: Detailed logging system for debugging and monitoring
- Python: 3.9 or higher
- Dependencies:
aiogram>= 3.0 (Telegram Bot API wrapper)python-dotenv(Environment variable management)
pip install aiogram python-dotenvpip install -r requirements.txtgit clone https://github.com/cmpdchtr/AnonkaReforged.git
cd AnonkaReforged# On Windows
python -m venv venv
venv\Scripts\activate
# On macOS/Linux
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txtCreate a .env file in the project root:
BOT_TOKEN=your_telegram_bot_token_here
CHANNEL_ID=your_target_channel_id_here
LANGUAGE=enpython main.py| Variable | Required | Description | Example |
|---|---|---|---|
BOT_TOKEN |
โ Yes | Telegram Bot API token from BotFather | 123456789:ABCDefGHIjklmnoPQRstuvWXyz |
CHANNEL_ID |
โ Yes | Telegram channel ID where messages are forwarded | -1001234567890 |
LANGUAGE |
โ No | Bot interface language (default: en) |
en, uk, ru, pl, es, de, fr |
-
BOT_TOKEN:
- Chat with @BotFather on Telegram
- Use
/newbotcommand to create a new bot - Copy the token provided
-
CHANNEL_ID:
- Create a channel in Telegram
- Add the bot as an administrator
- Send a test message and use telegram bot API to get the channel ID
- Or find it in the channel info (usually starts with
-100)
- Start the Bot: Send
/startcommand to the bot - Send Anonymous Message: Simply type any message and send it
- Confirmation: Receive a confirmation that your message was sent to the channel
- Monitor Messages: View all anonymous messages in the configured channel
- Manage Plugins: Place plugin folders in the
plugins/directory - Customize Language: Set
LANGUAGEenvironment variable - View Logs: Check console output for operational details
AnonkaReforged/
โโโ main.py # Bot entry point and core logic
โโโ plugin_system.py # Plugin framework and manager
โโโ locales.json # Multi-language translation strings
โโโ PLUGINS.md # Plugin development documentation
โโโ README.md # This file
โโโ LICENSE # MIT License
โโโ .env # Environment variables (create manually)
โโโ .env.example # Example environment file
โโโ requirements.txt # Python dependencies
โโโ plugins/ # Plugin directory
โ โโโ __init__.py # Makes plugins a Python package
โ โโโ ban_plugin/ # Example: Ban management plugin
โ โ โโโ plugin.py # Plugin implementation
โ โ โโโ config.json # Plugin configuration
โ โ โโโ README.md # Plugin documentation
โ โ โโโ banned_users.json # Plugin data persistence
โ โโโ your_plugin/ # Template for new plugins
โ โโโ plugin.py
โโโ __pycache__/ # Python cache (auto-generated)
โโโ venv/ # Virtual environment (recommended)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Telegram Bot โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโดโโโโโโโโโโโโ
โ โ
โโโโโโโโโผโโโโโโโโโโโ โโโโโโโโโโผโโโโโโโโโโโ
โ /start Command โ โ Regular Messages โ
โโโโโโโโโฌโโโโโโโโโโโ โโโโโโโโโฌโโโโโโโโโโโโ
โ โ
โโโโโโโโโผโโโโโโโโโโโ โโโโโโโโโโผโโโโโโโโโโโโโโโ
โ Send Welcome โ โ Plugin Handlers โ
โ Message โ โ (if applicable) โ
โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโฌโโโโโโโโโโโโโโโ
โ
โโโโโโโโโผโโโโโโโโโโโโโโโ
โ Forward to โ
โ Channel (Copy) โ
โโโโโโโโโฌโโโโโโโโโโโโโโโ
โ
โโโโโโโโโผโโโโโโโโโโโโโโโ
โ Send Confirmation โ
โ to User โ
โโโโโโโโโโโโโโโโโโโโโโโโ
- Plugin Discovery: On startup, all plugins in
plugins/are discovered - Plugin Loading: Each plugin's
plugin.pyis loaded and instantiated - Plugin Setup: Each plugin's
setup()method registers handlers - Message Processing: Incoming messages are processed by plugin handlers first, then core handlers
- Plugin Cleanup: On shutdown, all plugins'
cleanup()methods are called
Responsibilities:
- Initializes the Telegram bot using aiogram
- Loads configuration from environment variables
- Manages localization system
- Registers message handlers
- Orchestrates plugin loading
- Handles message forwarding logic
Key Functions:
load_locales(): Loads translation strings fromlocales.jsont(key, **kwargs): Translation function with variable substitutioncmd_start(): Handles/startcommandforward_to_channel(): Forwards user messages to the channelmain(): Async entry point that starts the bot
Key Features:
# Configuration loading with validation
token = os.getenv("BOT_TOKEN") # Required
channel_id = os.getenv("CHANNEL_ID") # Required
language = os.getenv("LANGUAGE", "en") # Optional, defaults to English
# Handler priority: Plugins first, then catch-all forward
# This prevents plugin commands from being forwarded as messagesComponents:
- Purpose: Base class for all plugins
- Required Implementation:
setup()method - Optional Implementation:
cleanup()method - Properties:
bot: Bot instancedp: Dispatcher instanceplugin_dir: Path to plugin directoryname: Plugin class namelogger: Logger instance
class Plugin(ABC):
async def setup(self) -> bool:
"""Initialize plugin - register handlers, load config, etc."""
pass
async def cleanup(self):
"""Clean up resources when plugin is unloaded."""
pass- Purpose: Discover, load, and manage all plugins
- Responsibilities:
- Scan
plugins/directory for plugin folders - Load plugin modules dynamically using
importlib - Instantiate plugin classes
- Call setup/cleanup methods
- Maintain plugin registry
- Scan
Key Methods:
discover_plugins(): Find all valid plugin directoriesload_plugin(plugin_dir): Load a single pluginload_all_plugins(): Load all discovered plugins (async)unload_all_plugins(): Cleanup all plugins (async)get_plugin(name): Retrieve loaded plugin by namelist_plugins(): Get list of loaded plugin names
Plugin Loading Process:
# 1. Scan plugins/ directory for folders with plugin.py
# 2. Use importlib to load plugin.py module
# 3. Find class that inherits from Plugin
# 4. Instantiate the class
# 5. Call setup() method
# 6. If setup() returns True, add to registryStructure:
{
"language_code": {
"translation_key": "Translated text with {PLACEHOLDERS}"
}
}Supported Languages:
en- Englishuk- Ukrainianru- Russianpl- Polishes- Spanishde- Germanfr- French
Translation Keys:
start_message: Welcome message on/startmessage_sent: Confirmation after message forwardingerror_sending: Error message on forward failurebot_ignored: Message when bot tries to send
Variable Substitution:
The t() function supports template variables:
t("start_message", CHANNEL_ID="@mychannel")
# Replaces {CHANNEL_ID} with @mychannelFor detailed plugin development guide, see PLUGINS.md.
Quick Start:
# plugins/my_plugin/plugin.py
from aiogram import types
from aiogram.filters.command import Command
from plugin_system import Plugin
class MyPlugin(Plugin):
async def setup(self) -> bool:
"""Setup handlers and initialize plugin."""
try:
self.dp.message.register(self.cmd_ping, Command("ping"))
self.logger.info("MyPlugin initialized")
return True
except Exception as e:
self.logger.error(f"Setup failed: {e}")
return False
async def cmd_ping(self, message: types.Message):
"""Example command handler."""
await message.answer("Pong! ๐")
async def cleanup(self):
"""Called when plugin is unloaded."""
self.logger.info("MyPlugin cleanup")- Dynamic Loading: Plugins loaded at runtime without bot restart (requires code restart currently)
- Isolated Logging: Each plugin has its own logger with
plugin.PluginNameprefix - Configuration Files: Access plugin config via
get_config_path() - Data Persistence: Store data in
self.plugin_dir - Full Bot Access: Access to bot instance and dispatcher for handler registration
- Error Isolation: Plugin errors don't crash the main bot
- Language Selection: Set via
LANGUAGEenvironment variable - Key-Based Translation: Use
t("key")function to get translated strings - Fallback System: Missing translations fall back to English
- Variable Substitution: Template variables like
{CHANNEL_ID}are replaced
Edit locales.json:
{
"pt": {
"start_message": "๐ <b>Bem-vindo!</b>\n\nEnvie-me qualquer mensagem...",
"message_sent": "Sua mensagem foi enviada! ๐",
"error_sending": "Desculpe, nรฃo consegui enviar sua mensagem.",
"bot_ignored": "Mensagens de bots nรฃo sรฃo aceitas."
}
}Then set LANGUAGE=pt in .env.
Create .env file in project root:
# .env
BOT_TOKEN=123456789:ABCDefGHIjklmnoPQRstuvWXyz
CHANNEL_ID=-1001234567890
LANGUAGE=enThe bot validates required variables on startup:
# Raises RuntimeError if missing
token = os.getenv("BOT_TOKEN")
channel_id = os.getenv("CHANNEL_ID")# In main.py
logging.basicConfig(level=logging.INFO) # Production
logging.basicConfig(level=logging.DEBUG) # Development| Scenario | Handling |
|---|---|
Missing BOT_TOKEN |
Raises RuntimeError at startup |
Missing CHANNEL_ID |
Raises RuntimeError at startup |
Missing locales.json |
Uses fallback English messages |
Invalid JSON in locales.json |
Raises JSONDecodeError |
| Forward to channel fails | User receives error message, exception logged |
| Plugin setup fails | Plugin not added to registry, error logged |
| Plugin cleanup fails | Error logged, but other plugins still cleaned up |
- Check logs regularly for warnings and errors
- Use try-except blocks in plugin
setup()methods - Return
Falsefromsetup()if initialization fails - Implement
cleanup()for proper resource management - Test plugins before deploying to production
-
Security:
- Never commit
.envfile to version control - Use strong, unique bot tokens
- Restrict channel access to trusted administrators
- Never commit
-
Maintenance:
- Regularly check bot logs
- Monitor message forwarding success rate
- Back up plugin configuration files
-
Performance:
- Use appropriate logging levels
- Test plugins in development before production
- Monitor bot response times
-
Code Quality:
- Inherit from
Pluginbase class - Implement proper error handling in
setup() - Use
self.loggerfor all logging
- Inherit from
-
Resource Management:
- Close file handles in
cleanup() - Stop background tasks properly
- Release database connections
- Close file handles in
-
Documentation:
- Add docstrings to all methods
- Create
README.mdin plugin folder - Document configuration options in
config.json
-
Compatibility:
- Target Python 3.9+
- Use aiogram v3.x
- Test with different bot configurations
We welcome contributions! Here's how to get started:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
To contribute a plugin:
- Create plugin following guidelines in
PLUGINS.md - Include comprehensive documentation
- Add test cases if applicable
- Submit PR with
[PLUGIN]prefix
This project is licensed under the MIT License. See the LICENSE file for details.
MIT License Summary:
- โ Commercial use allowed
- โ Modification allowed
- โ Distribution allowed
- โ Private use allowed
โ ๏ธ Liability limitedโ ๏ธ Warranty not provided
- Issues: Report bugs via GitHub Issues
- Documentation: See
PLUGINS.mdfor plugin development - Author: @cmpdchtr
Future enhancements planned:
- Hot plugin reload without bot restart
- Web dashboard for configuration
- Plugin marketplace
- Message scheduling
- Advanced statistics and analytics
- Rate limiting and abuse prevention
- Database integration for persistence
- Plugin dependency management
# Setup
git clone https://github.com/cmpdchtr/AnonkaReforged.git
cd AnonkaReforged
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
# Configure
cp .env.example .env
# Edit .env with your BOT_TOKEN and CHANNEL_ID
# Run
python main.py
# Create Plugin
mkdir plugins/my_plugin
# Create plugins/my_plugin/plugin.py following PLUGINS.md
# View Logs
# Check console output or configure logging to file- Lines of Code: ~500 (core bot logic)
- Supported Languages: 7
- Plugin System: Dynamic loading with error isolation
- Architecture: Fully asynchronous using aiogram 3.x
- Python Version: 3.9+
Last Updated: 1.11.2025
Version: V0.4
Status: Active Development
Made with โค๏ธ by @cmpdchtr