Metadata-Version: 2.4
Name: rubkey
Version: 2.0.2
Summary: Rubika Bot API library - Simple and powerful bot framework for Rubika messenger
Home-page: https://github.com/codetansarian
Author: taha ansarianpour
Author-email: codetansarian@gmail.com
License: MIT
Keywords: rubika bot rubkey messenger api group channel plugin inline webhook ban filter markdown async calendar
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.20.0
Requires-Dist: aiosqlite>=0.17.0
Requires-Dist: aiohttp>=3.8.0
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: keywords
Dynamic: license
Dynamic: license-file
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# Rubkey - Rubika Bot API Library

> **Official Rubika Channel:** [@library_rubkey](https://rubika.ir/library_rubkey)

Rubika Bot API library - Simple and powerful bot framework for Rubika messenger

## Source Code

For source code of the Rubkey library, visit the GitHub page:

[https://github.com/codetansarian/Source-code-of-the-Rubkey-library](https://github.com/codetansarian/Source-code-of-the-Rubkey-library)

## Features

- Send text messages with Chat Keypad and Inline Keypad
- Send polls
- Send files (image, video, file, voice, music, gif)
- Chat Keypad with button types: Simple, AskMyPhoneNumber, Textbox, File, GalleryImage, GalleryVideo, CameraImage, CameraVideo, Audio, RecordAudio, Barcode
- Inline Keypad with auto-updating data (counter, stats, etc.)
- Inline Keypad with advanced buttons: Selection, NumberPicker, StringPicker, Link, Barcode, Textbox, Calendar
- Calendar button with Persian and Gregorian support
- Textbox button with SingleLine/MultiLine and String/Number keypad
- Markdown parse mode: Bold, Italic, Underline, Strike, Spoiler, Quote, Link, Mono, Pre
- Metadata system for text formatting (Bold, Italic, Underline, Strike, Spoiler, Mono, Pre, Link, Mention, Quote)
- Admin system with ADMIN_ID and ADMIN_PASSWORD
- Admin-specific commands, buttons, and keypads
- Ban system with ban/unban users
- Group ban/unban with reply (message_map)
- Edit and delete messages
- Edit message with Inline Keypad update
- Edit and remove Chat Keypad
- Forward messages and files
- Message handlers for commands, buttons, and all messages
- Command and message filters with regex
- Rate limiting to prevent spam
- Cache system for faster responses
- Error handling with automatic retry (exponential backoff)
- Analytics for tracking user behavior
- Auto-delete messages with rules and filter words
- Filter words with add/remove
- Session management with auto offset saving
- SQLite offset storage (automatic rebuild)
- Smart skip old messages
- User session storage (JSON)
- SQLite database for messages and users
- Full async bot support with asyncio + aiohttp
- AsyncBot: all sync features in async
- AsyncGroupBot: all group features in async
- AsyncChannelBot: all channel features in async
- AsyncSendFile: file upload/download in async
- AsyncWebhookServer: webhook in async
- Webhook support (aiohttp async server)
- Webhook auto-start with set_webhook
- Webhook with middleware and router
- Contact and file receiving from users
- Built-in user counter (total_users, user_ids)
- Group support with GroupBot and GroupHandlers
- Group admin system (set/remove/is/get admins)
- Admin only ban mode
- Group auto-delete with admin bypass
- Group-specific commands, messages, and buttons
- Group data storage
- Get group info (title, chat_id, type)
- Channel support with ChannelBot and ChannelHandlers
- Channel commands, messages, and data storage
- Get channel info (title, chat_id, type, username)
- Plugin system with auto-loading and reloading
- QR/Barcode scanning

## Sync Methods

- `send_message(chat_id, text, keypad=None, inline_keypad=None, reply_to=None, metadata=None, parse_mode=None)` — Send text message
- `edit_message(chat_id, message_id, text, inline_keypad=None, metadata=None, parse_mode=None)` — Edit message
- `delete_message(chat_id, message_id)` — Delete message
- `send_poll(chat_id, question, options)` — Send poll
- `send_file(chat_id, file_id, text="", keypad=None, inline_keypad=None, reply_to=None)` — Send file
- `forward_message(from_chat_id, to_chat_id, message_id)` — Forward message
- `get_chat(chat_id)` — Get chat information
- `get_me()` — Get bot information
- `remove_keypad(chat_id)` — Remove Chat Keypad
- `edit_chat_keypad(chat_id, keypad)` — Edit Chat Keypad
- `set_commands(commands)` — Set bot commands
- `delete_commands()` — Delete all commands
- `ban_chat_member(chat_id, user_id)` — Ban member in group
- `unban_chat_member(chat_id, user_id)` — Unban member in group
- `set_webhook(url, host="0.0.0.0", port=5000)` — Set webhook and auto-start server
- `delete_webhook()` — Delete webhook and stop server
- `get_webhook_info()` — Get webhook status
- `get_updates(limit=10)` — Get updates
- `poll_updates(limit=10, sleep=1)` — Continuous updates generator
- `run()` — Start bot polling

## Async Methods

### AsyncBot
- `await bot.send_message(chat_id, text, ...)` — Send message
- `await bot.edit_message(chat_id, message_id, text, ...)` — Edit message
- `await bot.delete_message(chat_id, message_id)` — Delete message
- `await bot.send_poll(chat_id, question, options)` — Send poll
- `await bot.send_file(chat_id, file_id, text, ...)` — Send file
- `await bot.forward_message(from_chat_id, to_chat_id, message_id)` — Forward message
- `await bot.get_chat(chat_id)` — Get chat info
- `await bot.get_me()` — Get bot info
- `await bot.remove_keypad(chat_id)` — Remove keypad
- `await bot.edit_chat_keypad(chat_id, keypad)` — Edit keypad
- `await bot.set_commands(commands)` — Set commands
- `await bot.delete_commands()` — Delete commands
- `await bot.ban_chat_member(chat_id, user_id)` — Ban member
- `await bot.unban_chat_member(chat_id, user_id)` — Unban member

### AsyncGroupBot
- `await bot.get_group_info(chat_id)` — Get group info
- `bot.set_group_admin(group_id, user_id)` — Set admin
- `bot.is_group_admin(group_id, user_id)` — Check admin
- `bot.get_group_admins(group_id)` — List admins
- All GroupBot features in async

### AsyncChannelBot
- `await bot.get_channel_info(chat_id)` — Get channel info
- `await bot.send_to_channel(channel_id, text)` — Send to channel
- `await bot.edit_in_channel(channel_id, message_id, text)` — Edit in channel
- `await bot.delete_in_channel(channel_id, message_id)` — Delete in channel
- `await bot.forward_to_channel(from_chat_id, channel_id, message_id)` — Forward to channel
- `await bot.send_poll_to_channel(channel_id, question, options)` — Poll in channel
- All ChannelBot features in async

### AsyncSendFile
- `await sendfile.request_send_file(file_type)` — Request upload URL
- `await sendfile.upload_file(upload_url, file_path)` — Upload file
- `await sendfile.send_file(chat_id, file_id, text)` — Send file

### AsyncWebhookServer
- `server.run()` — Start server
- `server.run_in_thread()` — Start in background
- `server.stop()` — Stop server

## Markdown Parse Mode

- `**text**` — Bold
- `*text*` — Italic
- `__text__` — Underline
- `~~text~~` — Strike
- `||text||` — Spoiler
- `` `text` `` — Mono
- ```` ```text``` ```` — Pre
- `> text` — Quote
- `[text](url)` — Link

Usage: `bot.send_message(chat_id, "**Bold** *Italic*", parse_mode="Markdown")`

## Metadata System

- `Metadata()` — Create metadata object
- `metadata.add_part(MetadataPart(type, from_index, length, **kwargs))` — Add metadata part
- Types: Bold, Italic, Underline, Strike, Spoiler, Mono, Pre, Link, Mention, Quote

## Auto-Delete System

- `set_auto_delete(rules)` — Set auto-delete rules
- `add_filter_word(word)` — Add filter word
- `remove_filter_word(word)` — Remove filter word
- `admins_can_bypass_delete` — Admins bypass auto-delete

## Ban System

- `ban_user(user_id)` — Ban a user
- `unban_user(user_id)` — Unban a user
- `admin_ban(msg, user_id)` — Ban by admin only
- `ban_chat_member(chat_id, user_id)` — Ban in group
- `unban_chat_member(chat_id, user_id)` — Unban in group
- `banned_users` — Set of banned users

## Webhook

- `set_webhook(url, host="0.0.0.0", port=5000)` — Set webhook and auto-start server
- `delete_webhook()` — Delete webhook and stop server
- `get_webhook_info()` — Get webhook status
- `WebhookServer(bot, host, port)` — Sync webhook server
- `AsyncWebhookServer(bot, host, port)` — Async webhook server
- `server.run()` / `server.run_in_thread()` / `server.stop()`

## Analytics

- `get_analytics(user_id=None)` — Get analytics
- `set_rate_limit(max_per_second=5, window=1)` — Rate limit
- `set_cache_ttl(ttl)` — Cache TTL

## File Methods (SendFile / AsyncSendFile)

- `SendFile(bot)` — Sync file sender
- `AsyncSendFile(bot)` — Async file sender
- `sendfile.request_send_file(file_type="Image")` — Request upload URL
- `sendfile.upload_file(upload_url, file_path)` — Upload file
- `sendfile.send_file(chat_id, file_id, text)` — Send file

## Handlers

- `@bot.command("name", pattern=None)` — Handle command with optional regex
- `@bot.on_message(pattern=None)` — Handle messages with optional regex
- `@bot.on_button("button_id")` — Handle button clicks

## Filters

- `Filters.command("name")` — Filter by command
- `Filters.text("text")` — Filter by text
- `Filters.regex(pattern)` — Regex filter
- `Filters.chat_type("private/group/channel")` — Chat type filter
- `Filters.has_file()` / `Filters.has_contact()` / `Filters.has_button("id")` — Content filters
- `Filters.is_admin()` — Admin filter
- `Filters.and/or/not_filter(...)` — Combine filters

## Middleware & Router

- `bot.add_middleware(func)` — Add middleware
- `Router()` — Create router
- `router.command("name", filters=...)` — Router command
- `router.on_message(filters=...)` — Router message
- `router.on_button("id", filters=...)` — Router button
- `bot.include_router(router)` — Include router

## Admin System

- `bot.ADMIN_ID` / `bot.ADMIN_PASSWORD` — Admin settings
- `@bot.admin_command("name")` — Admin command
- `@bot.admin_on_message()` — Admin messages
- `@bot.admin_on_button("button_id")` — Admin buttons

## Group System

- `GroupBot(token)` / `AsyncGroupBot(token)` — Group bot
- `bot.set_group_handlers(handlers)` — Set handlers
- `bot.get_group_info(chat_id)` — Group info (title, chat_id, type)
- `bot.set_group_admin(id, user_id)` — Set admin
- `bot.remove_group_admin(id, user_id)` — Remove admin
- `bot.is_group_admin(id, user_id)` — Check admin
- `bot.get_group_admins(id)` — List admins
- `bot.first_admin_on_start` / `bot.first_n_admins` / `bot.no_admin_mode` / `bot.admin_only_ban`
- `GroupHandlers()` — Group handlers
- `handlers.command("name", group_only=True)` — Group command
- `handlers.on_message(group_only=True)` — Group message
- `handlers.on_button("id", group_only=True)` — Group button
- `handlers.set_data/get_data` — Group data storage

## Channel System

- `ChannelBot(token)` / `AsyncChannelBot(token)` — Channel bot
- `bot.set_channel_handlers(handlers)` — Set handlers
- `bot.get_channel_info(chat_id)` — Channel info (title, chat_id, type, username)
- `bot.send_to_channel/edit_in_channel/delete_in_channel` — Channel management
- `bot.forward_to_channel/send_poll_to_channel` — Channel actions
- `ChannelHandlers()` — Channel handlers
- `handlers.command("name")` / `handlers.on_message()` / `handlers.set_data/get_data`

## Session & Database

- `Session(session_file="session.json")` — JSON session
- `session.set/get/delete/clear` — Session methods
- `Database(db_path="rubkey.db")` — SQLite database
- `database.init/save_message/save_user/get_messages/get_user`

## Plugin System

- `PluginLoader(bot, plugin_dir="plugins")` — Plugin loader
- `loader.load_all()` / `loader.reload_all()`
- `Plugin(info)` — Plugin object
- `PluginInfo(name, version, author, description)` — Plugin info
- `@plugin.command/on_message/on_button/admin_command/admin_on_message/admin_on_button`

## Keypad Classes

- `Keypad(resize=True, one_time=False)` — Chat Keypad
- `KeyButton(button_id, text, button_type="Simple")` — Chat button
- `TextboxButton(...)` — Textbox button
- `FileButton(...)` — File picker button
- `BarcodeButton(...)` — Barcode scanner (Chat Keypad)
- `InlineKeypad()` — Inline Keypad
- `InlineButton(button_id, text, button_type="Simple")` — Inline button

## Advanced Inline Buttons

- `SelectionButton(...)` — Selection list
- `NumberPickerButton(...)` — Number picker
- `StringPickerButton(...)` — String picker
- `LinkButton(...)` — Link button
- `BarcodeInlineButton(...)` — Barcode scanner
- `TextboxInlineButton(...)` — Textbox
- `CalendarButton(...)` — Calendar (Persian/Gregorian)

## Message Object

- `msg.text` — Message text
- `msg.chat_id` — Chat ID
- `msg.message_id` — Message ID
- `msg.sender_id` — Sender ID
- `msg.time` — Message time
- `msg.is_edited` — Edit status
- `msg.button_id` — Clicked button ID
- `msg.contact` — Contact info
- `msg.file` — File info (file_id, file_name, size)
- `msg.poll` — Poll info
- `msg.aux_data` — Auxiliary data
- `msg.reply_to_message_id` — Reply ID
- `msg.reply(text, ...)` — Reply
- `msg.edit(text, ...)` — Edit
- `msg.delete()` — Deletet
- All GroupBot features async

### AsyncChannelBot
- `AsyncChannelBot(token)` — Create async channel bot
- All ChannelBot features async

### AsyncSendFile
- `AsyncSendFile(bot)` — Create async file sender
- `await sendfile.request_send_file(file_type)` — Request upload URL async
- `await sendfile.upload_file(upload_url, file_path)` — Upload file async
- `await sendfile.send_file(chat_id, file_id, text)` — Send file async

### AsyncWebhookServer
- `AsyncWebhookServer(bot, host, port)` — Create async webhook server
- `server.run()` — Start server
- `server.run_in_thread()` — Start in background
- `server.stop()` — Stop server

## Keypad Classes

- `Keypad(resize=True, one_time=False)` — Create Chat Keypad
- `keypad.add_row(*buttons)` — Add button row
- `KeyButton(button_id, text, button_type="Simple")` — Create Chat Keypad button
- `TextboxButton(button_id, text, type_line="SingleLine", type_keypad="String", place_holder="", title="")` — Create Textbox button
- `FileButton(button_id, text, file_type="File")` — Create file picker button
- `BarcodeButton(button_id, text)` — Create barcode scanner button
- `InlineKeypad()` — Create Inline Keypad
- `inline_keypad.add_row(*buttons)` — Add button row
- `InlineButton(button_id, text, button_type="Simple")` — Create Inline Keypad button

## Advanced Inline Buttons

- `SelectionButton(button_id, text, selection_id, items, is_multi_selection=False, columns_count="1", title="")` — Selection list
- `NumberPickerButton(button_id, text, min_value, max_value, default_value=None, title="")` — Number picker
- `StringPickerButton(button_id, text, items, default_value=None, title="")` — String picker
- `LinkButton(button_id, text, link_url)` — Link button
- `BarcodeInlineButton(button_id, text)` — Barcode scanner (inline)
- `TextboxInlineButton(button_id, text, type_line="SingleLine", type_keypad="String", place_holder="", title="")` — Textbox (inline)

## Message Object

- `msg.text` — Message text
- `msg.chat_id` — Chat ID
- `msg.message_id` — Message ID
- `msg.sender_id` — Sender ID
- `msg.time` — Message time
- `msg.is_edited` — Edit status
- `msg.button_id` — Clicked button ID
- `msg.contact` — Contact information
- `msg.file` — File information (file_id, file_name, size)
- `msg.poll` — Poll information
- `msg.aux_data` — Auxiliary data
- `msg.reply_to_message_id` — Reply message ID
- `msg.reply(text, keypad=None, inline_keypad=None, metadata=None, parse_mode=None)` — Reply to message
- `msg.edit(text, inline_keypad=None, metadata=None, parse_mode=None)` — Edit message
- `msg.delete()` — Delete message
