IpverseBot provides a comprehensive Telegram bot interface for retrieving IP range information for different countries. This document describes the internal API structure and key functions.
- Description: Main entry point for the bot
- Parameters: None
- Returns: None
- Functionality: Initializes bot, registers handlers, starts polling
- Description: Background task for cleaning old cache files
- Parameters: None
- Returns: None
- Schedule: Runs every 24 hours
BOT_TOKEN: Telegram bot token from BotFatherADMIN_ID: Telegram user ID of the administrator
SPAM_THRESHOLD: 2 seconds (minimum time between requests)RATE_LIMIT_REQUESTS: 10 (max requests per minute)RATE_LIMIT_PERIOD: 60 seconds (rate limit window)
- Description: Load user data from JSON database
- Returns: Dictionary of user data
- Structure:
{ "user_id": { "lang": "en|fa", "coins": 0, "daily_requests": {"date": "YYYY-MM-DD", "count": 0}, "referrer": "referrer_user_id", "referrals": 0, "last_message_id": null, "last_message_time": 0, "recent_requests": [], "processing": false, "referral_awarded": false } }
- Description: Save user data to JSON database
- Parameters: User data dictionary
- Description: Load bot settings
- Returns: Settings dictionary
- Structure:
{ "channels": ["@channel1", "@channel2"], "force_join": true }
- Description: Fetch ASN data from ipinfo.io
- Parameters:
session: aiohttp ClientSessioncountry: 2-letter country codepage: Page number for pagination
- Returns: JSON response or None
- Rate Limiting: 3 retry attempts with 5-second delays
- Description: Main IP processing function
- Parameters:
bot: Bot instancemessage: Telegram messagecountry: Country codeuser_id: User IDlang: User language
- Functionality:
- Fetches all ASN pages for country
- Generates comprehensive IP range report
- Caches results for reuse
- Sends file to user
- Description: Verify user membership in required channels
- Parameters: Bot instance, user ID
- Returns: True if member of all channels
- Description: Anti-spam protection
- Parameters: Bot instance, user ID, admin status
- Returns: True if request allowed
- Description: Rate limiting check
- Parameters: Bot instance, user ID, admin status
- Returns: True if within rate limits
- Description: Validate and clean country code
- Parameters: Raw country code input
- Returns: Sanitized 2-letter code or None
/start- Initialize bot, language selection, channel verification<country_code>- Request IP ranges (e.g., "US", "IR", "DE")
lang_en/lang_fa- Language selectioncheck_join- Verify channel membershipaccount- View account informationreferral- Get referral linkadmin_panel- Admin dashboard (admin only)
- Total users count
- IP files generated
- Cached files count
- Coins spent by users
- Add new required channels
- Remove channels
- Toggle force join requirement
- Verify bot admin status in channels
- Send messages to all users
- Progress tracking
- Delivery statistics
- User sends
/start - Check for referral parameter
- Create user record in database
- Language selection (if new user)
- Channel membership verification (if enabled)
- Award referral coins (if applicable)
- Display welcome message
- User sends country code
- Validate country code format
- Check user permissions (daily limit, coins)
- Check spam/rate limits
- Process request (fetch ASN data)
- Generate and cache IP range file
- Send file to user
- Update user statistics
- User gets referral link:
t.me/botname?start=user_id - New user clicks link and starts bot
- System records referrer in new user data
- When new user completes verification, referrer gets 1 coin
- Referrer receives notification
- Invalid country codes → User-friendly error message
- Rate limiting → Wait time notification
- Missing permissions → Channel join requirement
- API failures → Retry logic with exponential backoff
- All major operations logged with timestamps
- Error tracking for debugging
- User action monitoring
- Performance metrics
- Country codes sanitized and validated
- User inputs escaped and cleaned
- Admin verification for sensitive operations
- Per-user request limits
- Spam protection with time windows
- Admin bypass for all limits
- Sensitive configuration in environment variables
- User data stored locally (no external databases)
- Automatic cleanup of temporary files
- IP range files cached by country and date
- Automatic cleanup of files older than 1 day
- Reuse of cached files for multiple requests
- Non-blocking I/O for all network operations
- Concurrent processing of multiple user requests
- Background cleanup tasks
- Efficient JSON storage
- Minimal in-memory data structures
- Garbage collection of old cache entries
Matrix Team
- English Community: @MatrixORG
- Persian Community: @MatrixFa
- Chat Group: @DD0SChat