Skip to main content

No project description provided

Project description

# 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)

  • Send contacts from bot

  • Send locations from bot

  • 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

  • SelfBot: self-bot with phone number login

  • SelfBot commands (with slash / without slash)

  • SelfBot message edit and reply

  • SelfBot session save/load

  • 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

  • send_contact(chat_id, first_name, phone_number, last_name=””) — Send contact

  • send_location(chat_id, latitude, longitude) — Send location

  • 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.send_contact(chat_id, first_name, phone_number, last_name=””) — Send contact - await bot.send_location(chat_id, latitude, longitude) — Send location - 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

## SelfBot

  • SelfBot() — Create self-bot

  • bot.run() — Start self-bot (auto login)

  • bot.send_message(chat_id, text) — Send message

  • bot.edit_message(chat_id, message_id, text) — Edit message

  • @bot.on_command(“text”, slash=True) — Command with slash

  • @bot.on_command(“text”, slash=False) — Command without slash

  • @bot.on_message() — Message handler

  • msg.reply(text) — Reply to message

  • msg.edit(text) — Edit message

## Markdown Parse Mode

  • **text** — Bold

  • *text* — Italic

  • __text__ — Underline

  • ~~text~~ — Strike

  • ||text|| — Spoiler

  • `` text `` — Mono

  • `text` — Pre

  • > text — Quote

  • [text](url) — Link

## 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() — Delete

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

rubkey-2.0.4.tar.gz (22.3 kB view details)

Uploaded Source

Built Distributions

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

rubkey-2.0.4.0-py3-none-any.whl (33.2 kB view details)

Uploaded Python 3

rubkey-2.0.4-py3-none-any.whl (33.2 kB view details)

Uploaded Python 3

File details

Details for the file rubkey-2.0.4.tar.gz.

File metadata

  • Download URL: rubkey-2.0.4.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.34.2

File hashes

Hashes for rubkey-2.0.4.tar.gz
Algorithm Hash digest
SHA256 d4bd064eba3109864ecfff776a132961e81fae7cb4fdb75944c53d78b75eecf2
MD5 84bb8246e2b6fa67785f1211b7f37eb6
BLAKE2b-256 d55720c399e3c1a64602dd7488dde73f2c7d214505990af09c4d594b33e3a4da

See more details on using hashes here.

File details

Details for the file rubkey-2.0.4.0-py3-none-any.whl.

File metadata

  • Download URL: rubkey-2.0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 33.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.34.2

File hashes

Hashes for rubkey-2.0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 104b1720f5cb953dd273b409379cf18fa7550f4c69647027be4d0e3793d79bc2
MD5 14a35c4d555548d82466c4ca7dba787d
BLAKE2b-256 695e86e9629ef8d1e97fffde855b7eebeddeeb95cf7ff02df5d7b1699d8677b4

See more details on using hashes here.

File details

Details for the file rubkey-2.0.4-py3-none-any.whl.

File metadata

  • Download URL: rubkey-2.0.4-py3-none-any.whl
  • Upload date:
  • Size: 33.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.34.2

File hashes

Hashes for rubkey-2.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b6196f35faac3658910d015a2c5d972faf06d81fa4506c4d6b5cadf02e3d932b
MD5 0a9ff3206dfc032517703049a1b167ed
BLAKE2b-256 b6d18846719b27358b904856c2f4e6ac8de18240a2918330148daa7f5e8bb7b2

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