Skip to main content

The Complete Bot Builder Kit for Pyrogram Bots: Build, Enhance, and Scale with Ease

Project description

pyrokit

Usecase

API_ID = 123456           # Replace with your API_ID
API_HASH = "your_api_hash"  # Replace with your API_HASH
TOKEN = "my_bot_session"

app = Client(TOKEN, API_ID, API_HASH)

kit = PyroKit()

@app.on_message(filters.command("clean"))
@kit.ensure_admin(permissions=["can_delete_messages"])
@auto_flood
@rate_limit(5, 60)
async def clean_command(client: Client, message: Message):
    """Delete multiple messages with progress"""
    progress_msg = await message.reply("🧹 Cleaning...")
    
    async def progress(current, total):
        bar, perc = await kit.create_progress_bar(current, total)
        await kit.edit_or_resend(progress_msg, f"Cleaning: {bar} {perc}%")
    
    await client.delete_messages(
        chat_id=message.chat.id,
        message_ids=range(message.message_id-10, message.message_id),
        progress=progress
    )
    await kit.safe_delete(progress_msg)

@app.on_callback_query(filters.regex(r"^page_\d+"))
@kit.async_retry(max_retries=3)
async def handle_pagination(client: Client, query: CallbackQuery):
    """Handle inline keyboard pagination"""
    page = int(query.data.split("_")[1])
    content = f"Page {page} content"
    buttons = kit.inline_keyboard([
        [("Previous", f"page_{page-1}"), ("Next", f"page_{page+1}")]
    ])
    await kit.answer_query(query, f"Switched to page {page}")
    await kit.edit_or_resend(query.message, content, reply_markup=buttons)

# ==================== MAIN EXECUTION ====================
if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    app.run()

PyroKit Documentation

A comprehensive utility toolkit for Pyrogram bot development

1. Core Features:
-----------------
- Automated flood control
- Rate limiting with multiple strategies
- Admin permission verification
- Async error retry mechanism
- Smart message management

2. Advanced Features:
---------------------
- Database integration with connection pooling
- Multi-language localization support
- Error reporting to webhooks
- File validation and temp file management
- Inline query pagination
- Middleware processing pipeline
- Stateful conversation handlers

3. Usage Examples:
------------------
3.1 Database Integration:
@app.on_message(filters.command("stats"))
@kit.with_db
async def show_stats(client, message, db):
    count = await db.fetchval("SELECT COUNT(*) FROM users")
    await message.reply(f"Total users: {count}")

3.2 Localization:
@app.on_message(filters.command("help"))
@kit.localized(fallback_lang='en')
async def help_command(client, message, lang):
    await message.reply(lang['help_text'])

3.3 Error Reporting:
@app.on_message(filters.command("danger"))
@kit.error_webhook("https://errors.example.com")
async def risky_command(client, message):
    # Potentially error-prone code
    ...

4. Configuration:
-----------------
Initialize with custom config:
config = {
    'temp_dir': 'my_temp_files',
    'max_file_size': 5_000_000_000,
    'db_dsn': 'postgres://user:pass@localhost/db'
}
kit = PyroKit(config)

5. Best Practices:
------------------
- Use @safe_delete for message cleanup
- Always validate downloaded files
- Use middleware for analytics tracking
- Implement rate limiting on public endpoints
- Store user-specific data in conversation states

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyrokit-0.0.1.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyrokit-0.0.1-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file pyrokit-0.0.1.tar.gz.

File metadata

  • Download URL: pyrokit-0.0.1.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for pyrokit-0.0.1.tar.gz
Algorithm Hash digest
SHA256 d12a4ff22d7cc03263ec99fbfe885d6ef2ace76fac80fea0d76e797d87c5d0c2
MD5 9c29d1bfae0d87f23dc13a6e2ce16ba0
BLAKE2b-256 3aee15aa7a02069547afd449e3dd3da065c62cb658774faeead042edfc55f20c

See more details on using hashes here.

File details

Details for the file pyrokit-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: pyrokit-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for pyrokit-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 38aa973a0c240b25dd55354921640e441e555742b8c5092eb24c3e5e0640b3d3
MD5 3899caad849bef02a89a5f1d95c655c1
BLAKE2b-256 701181ffbf7a0a742df8eb9ea968b1219a7adde0a0a217e650be210b28211884

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page