v2.2.1 — Stable

Build Soroush Plus Bots
with Python

A modern, asynchronous Python library for interacting with Soroush Plus — both as a user account and a bot account.
کتابخانه پایتون مدرن و ناهمگام برای تعامل با سروش پلاس — هم کاربر و هم ربات

$ pip install spluspy

Everything You Need

Packed with features for powerful Soroush Plus bots.

همه چیزی که برای ربات‌های قدرتمند سروش پلاس نیاز دارید

Fully Asynchronous

Built with asyncio. Non-blocking I/O for high-performance concurrent operations.

🔒

No API Key Required

Uses built-in Soroush Plus credentials. Install and start building immediately.

🎯

Event-Driven Handlers

Handle messages, edits, callbacks, inline queries, and more with decorators.

🧩

Composable Filters

Chain filters with & (AND), | (OR), ~ (NOT) for complex conditions.

🎟

Inline & Reply Buttons

Interactive keyboards with URL buttons, callback data, and more.

💬

Conversation API

Multi-step bot dialogs with context managers for interactive flows.

🔄

Finite State Machine

Built-in FSM with multiple storage backends and decorator routing.

🔧

Plugin System

Dynamic plugin loading. Modular architecture that scales.

🧠

Middleware

Pre/post processing of updates. Add logging and rate limiting.

Built-in Scheduler

Schedule messages and callbacks with interval or one-shot timing.

💾

Multiple Storage Backends

Memory, SQLite, Redis, PostgreSQL — choose what fits.

🛡

Rate Limiting

Token bucket algorithm with automatic flood wait handling.

🏜

AFK Auto-Reply

Smart auto-responder with per-chat rate limiting.

🛣

Chat Administration

Ban, mute, pin, purge — high-level admin API.

🔀

Message Mirroring

Real-time message cloning between chats.

📥

File Transfer

Upload/download with progress tracking and chunked transfers.

📄

Sync Wrapper

Use without async/await via spluspy.sync.

📊

Batch Operations

Send, delete, forward multiple messages at once.

Complete API Reference

Every class, method, and parameter documented.

مستندات کامل تمام کلاس‌ها، متدها و پارامترها — به دو زبان

Client

Main entry point for all SplusPy operations. Manages authentication, events, middleware, and API calls. Supports bot mode (bot_token) and user mode (phone).
نقطه ورود اصلی تمام عملیات SplusPy — مدیریت احراز هویت، رویدادها، میان‌افزار و فراخوانی‌های API

Client(session="spluspy", *, bot_token=None, phone=None, ...) -> Client
Create a new SplusPy client. Use bot_token for bots or phone for user accounts.
ساخت کلاینت جدید SplusPy. از bot_token برای ربات‌ها و phone برای حساب کاربری استفاده کنید.
ParamTypeDescription
sessionstr | SessionSession name for persisting auth data / نام نشست
bot_tokenstr | NoneBot token for bot mode / توکن ربات
phonestr | NonePhone for user mode auth / شماره تلفن
api_idint | NoneCustom API ID (uses built-in if None) / شناسه API سفارشی
api_hashstr | NoneCustom API hash / هش API سفارشی
flood_sleep_thresholdintAuto-sleep on FloodWait (default: 60) / آستانه انتظار سیلاب
request_timeoutfloatAPI request timeout in seconds / تایم‌اوت درخواست
async connect() -> None
Connect to the Soroush Plus server. Must be called before sending messages in user mode.
اتصال به سرور سروش پلاس. قبل از ارسال پیام در حالت کاربری باید فراخوانی شود.
async disconnect() -> None
Disconnect from the server and clean up resources.
قطع اتصال از سرور و پاکسازی منابع.
async start() -> None
Start the client with interactive auth prompts (phone/password/code).
شروع کلاینت با درخواست‌های تعاملی احراز هویت.
run() -> None
Blocking entry point. Connects, runs until disconnected, then cleans up. Simplest way to run a bot.
نقطه ورود بلوکه‌کننده. متصل می‌شود، اجرا می‌کند و سپس پاکسازی می‌کند. ساده‌ترین راه اجرای ربات.
async run_until_disconnected() -> None
Run the event loop until disconnected. Handles transient disconnections gracefully.
اجرای حلقه رویداد تا قطع اتصال. مدیریت خودکار قطعی‌های موقت.
async send_message(chat_id, text=None, *, reply_to=None, parse_mode=None, link_preview=True) -> Message
Send a text message to a chat. Returns the sent Message object.
ارسال پیام متنی به چت. شیء Message ارسال شده را برمی‌گرداند.
ParamTypeDescription
chat_idintTarget chat/user ID / شناسه چت مقصد
textstr | NoneMessage text / متن پیام
reply_toint | NoneMessage ID to reply to / پاسخ به پیام
parse_modestr | None"html", "markdown", or None / حالت پارس
async edit_message(message, *, text=None, delay=0) -> Message
Edit a message's text. Optional delay in seconds before editing.
ویرایش متن پیام. تاخیر اختیاری قبل از ویرایش.
async delete_messages(*messages) -> bool
Delete one or more messages. Accepts Message objects or integer IDs.
حذف یک یا چند پیام. اشیاء Message یا شناسه‌های عددی می‌پذیرد.
async forward_messages(chat_id, *messages) -> Message
Forward messages to another chat.
فوروارد پیام‌ها به چت دیگر.
async send_photo(chat_id, photo, *, caption=None) -> Message
Send a photo. photo can be file path, bytes, or file-like object.
ارسال عکس. photo می‌تواند مسیر فایل، بایت یا شیء فایل باشد.
async send_video(chat_id, video, *, caption=None, duration=0, progress_callback=None) -> Message
Send a video. Duration/width/height auto-detected if 0.
ارسال ویدیو. مدت زمان/عرض/ارتفاع در صورت 0 بودن خودکار تشخیص داده می‌شود.
async send_document(chat_id, document, *, caption=None, progress_callback=None) -> Message
Send a document/file.
ارسال سند/فایل.
async send_voice(chat_id, voice, *, caption=None) -> Message
Send a voice note (audio message).
ارسال یادداشت صوتی.
async send_audio(chat_id, audio, *, caption=None, performer=None, title=None) -> Message
Send an audio file with optional metadata.
ارسال فایل صوتی با متادیتای اختیاری.
async send_animation(chat_id, animation, *, caption=None) -> Message
Send an animation/GIF.
ارسال انیمیشن/گیف.
async send_location(chat_id, lat, lon) -> Message
Send a geographic location.
ارسال موقعیت جغرافیایی.
async send_contact(chat_id, phone, first_name, last_name="") -> Message
Send a contact card.
ارسال کارت مخاطب.
async send_poll(chat_id, question, options, *, is_anonymous=True) -> Message
Send a poll. Options: list of 2-10 strings.
ارسال نظرسنجی. گزینه‌ها: لیست ۲ تا ۱۰ رشته.
async send_dice(chat_id, emoji="🎲") -> Message
Send a dice animation. Emojis: 🎲 🎯 🏀 ⚽ 🎳 🎰
ارسال انیمیشن تاس.
async send_reaction(chat_id, message, emoji) -> bool
React to a message with an emoji.
واکنش به پیام با ایموجی.
async send_sticker(chat_id, sticker, *, emoji=None) -> Message
Send a sticker.
ارسال استیکر.
async send_chat_action(chat_id, action="typing") -> bool
Send typing indicator. Actions: "typing", "upload_photo", "record_video", "upload_video", "record_audio", "upload_audio", "upload_document", "find_location", "choose_sticker"
ارسال نشانگر تایپ کردن.
async ban_user(chat_id, user_id) -> bool
Ban a user from a chat.
مسدود کردن کاربر از چت.
async unban_user(chat_id, user_id) -> bool
Unban a user.
رفع مسدودیت کاربر.
async mute_user(chat_id, user_id) -> bool
Mute a user (restrict from sending messages).
بی‌صدا کردن کاربر.
async unmute_user(chat_id, user_id) -> bool
Unmute a user.
رفع بی‌صدایی کاربر.
async join_chat(chat_id) -> Any
Join a chat by ID, username, or invite link. Raises typed exceptions on failure.
پیوستن به چت با شناسه، نام کاربری یا لینک دعوت.
async leave_chat(chat_id) -> bool
Leave a chat. Auto-detects channel vs group.
خروج از چت. تشخیص خودکار کانال و گروه.
async get_me() -> User
Get the currently authenticated user.
دریافت کاربر احراز هویت شده فعلی.
async get_chat(chat_id) -> Any
Get a chat entity by ID or username.
دریافت موجودیت چت با شناسه یا نام کاربری.
async get_user(user_id) -> User | None
Get full user info by ID or @username.
دریافت اطلاعات کامل کاربر با شناسه یا نام کاربری.
async get_messages(chat_id, *, limit=100) -> list[Message]
Get messages from a chat, newest first.
دریافت پیام‌ها از چت، جدیدترین اول.
async iter_messages(chat_id, *, limit=1000, search=None) -> AsyncGenerator
Async generator yielding messages in memory-efficient batches.
ژنراتور ناهمگام برای پیمایش پیام‌ها به صورت دسته‌ای.
async search_messages(chat_id, query, *, limit=100) -> list[Message]
Search for messages by text query.
جستجوی پیام‌ها با پرسش متنی.
async get_chat_info(chat_id) -> dict | None
Get comprehensive chat info as a dict: id, title, username, link, description, member_count, type.
دریافت اطلاعات کامل چت به صورت دیکشنری.
async get_user_info(user_id) -> dict | None
Get comprehensive user info: id, first_name, last_name, full_name, username, link, bio, is_bot, is_premium, status.
دریافت اطلاعات کامل کاربر.
async get_members(chat_id, *, limit=100) -> list[ChatMember]
Get a list of chat members.
دریافت لیست اعضای چت.
async pin_message(chat_id, message, *, notify=False) -> bool
Pin a message. Accepts Message object or int ID.
سنجاق کردن پیام. شیء Message یا شناسه عددی می‌پذیرد.
async unpin_message(chat_id, message) -> bool
Unpin a message.
رفع سنجاق پیام.
async mark_read(chat_id, message=None) -> bool
Mark message(s) as read.
علامت خواندن پیام‌ها.
async resolve_username(username) -> int
Resolve a username to numeric ID. Returns 0 if not found.
تبدیل نام کاربری به شناسه عددی.
async update_profile(first_name=None, last_name=None, about=None) -> bool
Update the current user's profile fields.
به‌روزرسانی فیلدهای پروفایل کاربر فعلی.
async set_profile_photo(photo) -> bool
Upload and set a new profile photo.
آپلود و تنظیم عکس پروفایل جدید.
async set_username(username) -> bool
Change username. Empty string removes it.
تغییر نام کاربری. رشته خالی آن را حذف می‌کند.
async export_session_string() -> str
Export session as a portable base64 string.
خروجی نشست به صورت رشته base64 قابل حمل.
conversation(chat_id, *, timeout=30.0) -> Conversation
Create a conversation context manager for request/response flows.
ساخت مدیر زمینه مکالمه برای جریان‌های درخواست/پاسخ.
async invoke(*args, **kwargs) -> Any
Invoke a raw MTProto API method. Low-level escape hatch.
فراخوانی روش خام MTProto API.

Conversation

Interactive conversational flow for request/response style messaging. Used with async with client.conversation(peer) as conv:.
جریان مکالمه تعاملی برای پیام‌رسانی سبک درخواست/پاسخ

async send_message(text) -> Message
Send a message in this conversation.
ارسال پیام در این مکالمه.
async get_response(timeout=None) -> Message
Wait for the next incoming message. Raises ConversationTimeoutError on timeout.
انتظار پیام بعدی. در صورت تایم‌اوت ConversationTimeoutError پرتاب می‌شود.
async send_and_wait(text, *, timeout=None) -> Message
Send a message and wait for a reply in one call.
ارسال پیام و انتظار پاسخ در یک فراخوانی.
empty() -> bool
Returns True if the internal queue is empty.
برگرداندن True اگر صف داخلی خالی باشد.
clear() -> None
Discard any unread messages in the queue.
حذف پیام‌های خوانده نشده در صف.

Message

Represents a received or sent message with all its properties and methods.
نمایانگر پیام دریافت شده یا ارسال شده با تمام ویژگی‌ها و متدها

FieldTypeDescription
idintUnique message identifier / شناسه یکتای پیام
textstrMessage text or caption / متن پیام یا کپشن
datedatetime | NoneTimestamp / زمان پیام
chat_idintChat ID / شناسه چت
sender_idint | NoneSender user ID / شناسه فرستنده
senderUser | NoneResolved User object / شیء کاربر
mediaMedia | NoneAttached media / رسانه پیوست
media_typeMessageMediaTypeKind of media / نوع رسانه
reply_toint | NoneReplied-to message ID / شناسه پیام پاسخ داده شده
is_groupboolFrom a group / از گروه
is_channelboolFrom a channel / از کانال
is_privateboolFrom a private chat / از چت خصوصی
Properties: message_id, is_forwarded, is_reply, is_media
Convenience properties for common checks.
ویژگی‌های کمکی برای بررسی‌های رایج.
async reply(text=None, *, buttons=None, file=None) -> Message
Reply to this message (sends with reply header).
پاسخ به این پیام (ارسال با هدر پاسخ).
async edit(text=None, *, delay=0) -> Message
Edit this message's text.
ویرایش متن این پیام.
async delete(*, delay=0) -> bool
Delete this message.
حذف این پیام.
async forward(chat_id) -> Message
Forward to another chat (keeps forward header).
فوروارد به چت دیگر (با هدر فوروارد).
async copy(chat_id) -> Message
Copy to another chat (no forward header).
کپی به چت دیگر (بدون هدر فوروارد).
async pin(notify=True) -> bool
Pin this message in its chat.
سنجاق کردن این پیام در چت.
async react(emoji) -> bool
React with an emoji.
واکنش با ایموجی.
async mark_read() -> bool
Mark as read.
علامت خواندن.
async download(file_path=None, *, progress=None) -> str | None
Download attached media. Returns file path.
دانلود رسانه پیوست. مسیر فایل را برمی‌گرداند.
async reply_photo(photo, caption=None) -> Message
Reply with a photo.
پاسخ با عکس.
async reply_video(video, caption=None) -> Message
Reply with a video.
پاسخ با ویدیو.
async reply_document(document, caption=None) -> Message
Reply with a document.
پاسخ با سند.
async reply_voice(voice, caption=None) -> Message
Reply with a voice note.
پاسخ با یادداشت صوتی.
async reply_sticker(sticker) -> Message
Reply with a sticker.
پاسخ با استیکر.
async reply_location(lat, lon) -> Message
Reply with a location.
پاسخ با موقعیت.
async reply_poll(question, options) -> Message
Reply with a poll.
پاسخ با نظرسنجی.
async reply_dice(emoji="🎲") -> Message
Reply with a dice animation.
پاسخ با انیمیشن تاس.
async get_reply_message() -> Message | None
Fetch the full message this message replies to.
دریافت پیام کاملی که به آن پاسخ داده شده.
async unblock_sender() -> bool
Unblock the sender of this message.
رفع مسدودیت فرستنده این پیام.

User

FieldTypeDescription
idintUnique user identifier / شناسه یکتای کاربر
first_namestrFirst name / نام
last_namestrLast name / نام خانوادگی
usernamestr | NoneUsername without @ / نام کاربری
phonestr | NonePhone number / شماره تلفن
biostr | NoneBiography / بیوگرافی
is_botboolWhether this is a bot / آیا ربات است
is_premiumboolPremium subscription / اشتراک پریمیوم
statusUserStatusOnline status / وضعیت آنلاین
Properties: full_name, mention, link
full_name: combined first+last name. mention: @username or full name. link: t.me profile URL.
full_name: نام کامل. mention: @username یا نام. link: لینک پروفایل.

Chat

FieldTypeDescription
idintUnique chat identifier / شناسه چت
titlestrChat title / عنوان چت
typeChatTypePRIVATE, GROUP, SUPERGROUP, CHANNEL / نوع چت
usernamestr | NonePublic username / نام کاربری عمومی
descriptionstr | NoneDescription / توضیحات
member_countintNumber of members / تعداد اعضا
Properties: is_private, is_group, is_supergroup, is_channel, link, display_name
Convenience type checks and display properties.
بررسی‌های نوع کمکی و ویژگی‌های نمایشی.

Button

Static factory methods for creating keyboard buttons.

Button.inline(text, callback_data) -> InlineKeyboardButton
Create an inline button with callback data.
ساخت دکمه اینلاین با داده بازخورد.
Button.url(text, url) -> InlineKeyboardButton
Create an inline button that opens a URL.
ساخت دکمه اینلاین برای باز کردن لینک.
Button.text(text, resize=True, one_time=False) -> ReplyMarkup
Create a single-button reply keyboard.
ساخت کیبورد ریپلای تک دکمه‌ای.
Button.request_location(text) -> KeyboardButton
Create a button that requests the user's location.
ساخت دکمه برای درخواست موقعیت کاربر.
Button.request_phone(text) -> KeyboardButton
Create a button that requests the user's phone.
ساخت دکمه برای درخواست شماره تلفن.
Button.clear() -> ReplyMarkup
Create markup that removes the current keyboard.
ساخت مارک‌آپ برای حذف کیبورد فعلی.
Button.build_inline(*rows) -> ReplyMarkup
Build an inline keyboard from rows of buttons.
ساخت کیبورد اینلاین از ردیف‌های دکمه.
Button.build_reply(*rows, resize=True) -> ReplyMarkup
Build a reply keyboard from rows of buttons.
ساخت کیبورد ریپلای از ردیف‌های دکمه.

Filters

Composable predicates with & (AND), | (OR), ~ (NOT).

FilterMatchesتوضیحات
filters.privatePrivate chatsچت‌های خصوصی
filters.groupGroups / supergroupsگروه‌ها
filters.channelChannelsکانال‌ها
filters.textText messagesپیام‌های متنی
filters.photoPhotosعکس‌ها
filters.videoVideosویدیوها
filters.audioAudioصوت
filters.voiceVoice notesیادداشت صوتی
filters.documentDocumentsاسناد
filters.stickerStickersاستیکرها
filters.animationGIFsگیف‌ها
filters.contactContactsمخاطبین
filters.locationLocationsموقعیت‌ها
filters.pollPollsنظرسنجی‌ها
filters.diceDiceتاس
filters.mediaAny mediaهر رسانه‌ای
filters.replyRepliesپاسخ‌ها
filters.forwardedForwardedفوروارد شده
filters.meSent by youارسال شده توسط شما
filters.botSent by botsارسال شده توسط ربات‌ها
filters.outgoingOutgoingارسالی
filters.incomingIncomingدریافتی
filters.serviceService messagesپیام‌های سیستمی
filters.command(*commands, prefixes=None) -> Command
Match /command or !command. Default prefixes: ["/", "!"].
تطابق با /command یا !command.
filters.regex(pattern, flags=0) -> Regex
Match by regex. Match stored on message.pattern_match.
تطابق با عبارت باقاعده. نتیجه در message.pattern_match ذخیره می‌شود.
filters.user(*user_ids) -> UserFilter
Match messages from specific users.
تطابق با پیام‌های کاربران خاص.
filters.chat(*chat_ids) -> ChatFilter
Match messages from specific chats.
تطابق با پیام‌های چت‌های خاص.
filters.text_contains(substring, case_sensitive=True) -> TextContains
Match messages containing a substring.
تطابق با پیام‌های حاوی زیررشته.
filters.length(min=0, max=999999) -> Length
Match by message text length.
تطابق بر اساس طول متن پیام.

Events

Event.stop_propagation() -> None
Stop the event from reaching subsequent handlers.
توقف انتشار رویداد به هندلرهای بعدی.
HandlerPriority
FIRST(0), HIGH(10), NORMAL(50), LOW(100), LAST(200). Lower values run first.
اولویت‌های هندلر. مقادیر کمتر زودتر اجرا می‌شوند.
NewMessage Event
Fields: message, pattern_match. Properties: text, chat_id, sender_id, is_private, is_group, is_channel, media, photo, video, sticker, forward_origin.
رویداد پیام جدید با تمام فیلدها و ویژگی‌ها.
ErrorEvent
Fields: exception, handler, update. Properties: message, type.
رویداد خطا با استثناء، هندلر و به‌روزرسانی اصلی.
ChatAction Event
Properties: is_join, is_leave, is_pin, user_name.
رویداد عمل چت: پیوستن، خروج، سنجاق.
UserUpdate Event
Properties: is_online, is_offline.
رویداد به‌روزرسانی وضعیت کاربر.
MessageDeleted Event
Fields: deleted_ids, chat_id.
رویداد حذف پیام.
MessageRead Event
Fields: read_ids, chat_id, max_id.
رویداد خواندن پیام.

FSM (Finite State Machine)

State(name=None) -> State
Define a state. Auto-named from class attribute.
تعریف وضعیت. نام‌گذاری خودکار از ویژگی کلاس.
StateTransition(target, guard=None)
Define a transition with optional async guard function.
تعریف انتقال با تابع محافظ اختیاری.
FSMContext.get_state() -> State | None
Get current state for a user.
دریافت وضعیت فعلی کاربر.
FSMContext.set_state(state) -> None
Set current state. Pass None to clear.
تنظیم وضعیت فعلی. None برای پاک کردن.
FSMContext.get_data() -> dict
Get all stored data for the user.
دریافت تمام داده‌های ذخیره شده کاربر.
FSMContext.set_data(**kwargs) -> None
Update stored data with key-value pairs.
به‌روزرسانی داده‌های ذخیره شده.
FSMContext.get(key, default=None) -> Any
Get a single data value by key.
دریافت یک مقدار داده با کلید.
FSMContext.set(key, value) -> None
Set a single data value.
تنظیم یک مقدار داده.
FSMContext.reset() / finish() -> None
Clear state and all data for the user.
پاک کردن وضعیت و تمام داده‌های کاربر.
StateMachine.state(state) -> Decorator
Register a handler for a specific state.
ثبت هندلر برای یک وضعیت خاص.
StateMachine.context(user_id) -> FSMContext
Create an FSMContext for a specific user.
ساخت FSMContext برای یک کاربر خاص.
StateMachine.fallback() -> Decorator
Register a handler for unmatched states.
ثبت هندلر برای وضعیت‌های بدون هندلر.

Storage Backends

BackendClassDescription
MemoryMemoryStorage()In-memory, non-persistent / حافظه، غیردائمی
SQLiteSQLiteStorage(path)Persistent file-based / مبتنی بر فایل
RedisRedisStorage(url)Shared state (requires redis) / حالت مشترک
PostgreSQLPostgresStorage(dsn)Enterprise (requires asyncpg) / سازمانی
get_storage(backend="memory", **kwargs) -> Storage
Factory function. Create storage by name: "memory", "sqlite", "redis", "postgres".
تابع کارخانه. ساخت storage با نام.
Storage.get(key) / set(key, value, ttl=None) / delete(key) / exists(key) / clear()
Standard key-value operations. All async. TTL in seconds for auto-expiration.
عملیات کلید-مقدار استاندارد. همه ناهمگام. TTL برای انقضا خودکار.
EntityCache (storage)
SQLite-backed peer resolution cache. Methods: get, get_by_username, get_by_phone, put, put_entity, put_many, remove, clear, count.
کش حل‌کننده همتا مبتنی بر SQLite.

Middleware

Middleware.on_update(update, handler) -> Any
Abstract method. Process every update through the middleware chain.
روش انتزاعی. پردازش هر به‌روزرسانی از زنجیره میان‌افزار.
MiddlewareManager.add(mw) / remove(mw) / execute(update, handler)
Manage middleware chain. FIFO order with error isolation.
مدیریت زنجیره میان‌افزار. ترتیب FIFO با جداسازی خطا.
RateLimitMiddleware(rate=1.0, capacity=1.0)
Rate limiting middleware. Methods: on_update, handle_flood_wait, get_stats.
میان‌افزار محدودیت نرخ. روش‌ها: on_update, handle_flood_wait, get_stats.

AfkManager

Smart auto-responder for AFK mode with per-chat rate limiting.
پاسخگوی خودکار هوشمند حالت AFK با محدودیت نرخ به ازای هر چت

AfkManager(client, message="...", *, cooldown=60.0, max_replies=10, only_private=False)
Create an AFK manager with configurable auto-reply, cooldown, and limits.
ساخت مدیر AFK با پاسخ خودکار تنظیم شده، تایم‌اوت و محدودیت‌ها.
set_afk(enabled, *, reason="", message=None) -> None
Enable or disable AFK mode with optional reason and custom message.
فعال/غیرفعال کردن حالت AFK با دلیل و پیام سفارشی.
async handle(message) -> bool
Process incoming message while AFK. Returns True if reply was sent.
پردازش پیام دریافتی در حالت AFK. True اگر پاسخ ارسال شده باشد.
Properties: is_afk, afk_reason, afk_since, total_replies
Check AFK status and statistics.
بررسی وضعیت و آمار AFK.
get_stats() -> dict
Returns: is_afk, afk_reason, afk_since, total_replies, active_chats, cooldown, max_replies.
برگرداندن آمار کامل AFK.

ChatAdmin

High-level chat administration API with batch operations.

async ban_user(chat_id, user_id, *, delete_messages=False) -> bool
Ban a user. Optionally delete their recent messages.
مسدود کردن کاربر. حذف اختیاری پیام‌های اخیر.
async unban_user(chat_id, user_id) -> bool
Unban a user.
رفع مسدودیت کاربر.
async mute_user(chat_id, user_id, *, duration=None) -> bool
Mute a user. duration in seconds; None = permanent.
بی‌صدا کردن کاربر. مدت به ثانیه؛ None = دائمی.
async unmute_user(chat_id, user_id) -> bool
Unmute a user.
رفع بی‌صدایی کاربر.
async purge_messages(chat_id, *, limit=100) -> int
Delete a batch of messages. Returns count deleted.
حذف دسته‌ای پیام‌ها. تعداد حذف شده را برمی‌گرداند.
async pin_message / unpin_message / unpin_all(chat_id)
Pin/unpin messages.
سنجاق/رفع سنجاق پیام‌ها.
async bulk_action(chat_id, action, user_ids, *, delay=0.5) -> dict[int, bool]
Bulk ban/unban/mute/unmute. Returns user_id -> success mapping.
مسدود/رفع مسدود/بی‌صدا/رفع بی‌صدایی دسته‌ای.
async get_admin_log(chat_id, *, limit=100) -> list[dict]
Get admin event log.
دریافت لاگ رویدادهای مدیریتی.

MessageMirror

Real-time message cloning between chats.

add_route(source, targets, *, strip_forward=True, add_prefix=None) -> None
Add a mirroring route from source to target chats.
افزودن مسیر آینه‌سازی از چت مبدأ به چت‌های مقصد.
add_source(source) / add_target(target) / remove_route(source)
Build routes incrementally.
ساخت مسیرها به صورت تدریجی.
async start() / async stop()
Start/stop the mirroring engine.
شروع/توقف موتور آینه‌سازی.
get_stats() -> dict
Returns: active, routes, total_mirrored, sources.
برگرداندن آمار آینه‌سازی.

MessageScheduler

schedule_message(chat_id, text, *, delay=None, when=None, name=None) -> ScheduledTask
Schedule a single message after a delay or at a specific time.
زمان‌بندی یک پیام بعد از تاخیر یا در زمان خاص.
schedule_interval(chat_id, text, *, interval, name=None) -> ScheduledTask
Schedule a recurring message at a fixed interval (seconds).
زمان‌بندی پیام تکراری با فاصله ثابت (ثانیه).
schedule_callback(name, callback, *, delay=None, interval=None) -> ScheduledTask
Schedule a custom callback function.
زمان‌بندی تابع بازخورد سفارشی.
cancel(name) -> bool
Cancel a scheduled task by name.
لغو وظیفه زمان‌بندی شده با نام.
async start() / async stop()
Start/stop the scheduler loop.
شروع/توقف حلقه زمان‌بند.
pending_count (property) -> int
Number of pending scheduled tasks.
تعداد وظایف زمان‌بندی شده در انتظار.

Utils

LRUCache(max_size=1024, default_ttl=None)
Thread-safe LRU cache with optional TTL. Methods: get, set, delete, exists, clear, size, get_stats.
کش LRU سازگار با رشته با TTL اختیاری.
RateLimiter(default_rate=1.0, default_capacity=1.0)
Token bucket rate limiter. Methods: acquire, register_flood_wait, limit (decorator), get_wait_time, clear_flood_wait.
محدودکننده نرخ سطل توکن.
ChatLockManager()
Per-chat locking. Methods: acquire (async ctx mgr), release, is_locked, locked_count, pending_count.
قفل‌گذاری به ازای هر چت.
ProgressTracker(callback=None, update_interval=0.1)
Track file transfer progress. Methods: update, finish.
ردیابی پیشرفت انتقال فایل.
batch_send / batch_delete / batch_forward
Efficient batch operations with configurable delays and chunk sizes.
عملیات دسته‌ای کارآمد با تاخیر و اندازه دسته تنظیم شده.
setup_logging(level, log_file, log_dir, errors_only=False)
Configure the logging system. Additional: get_logger, set_level, log, log_event, log_error, log_performance.
پیکربندی سیستم لاگ.
check_for_update() -> str | None
Check PyPI for newer version. Returns version string or None.
بررسی PyPI برای نسخه جدیدتر.

Error Hierarchy

ExceptionConstructorDescription / توضیحات
SplusPyError(message)Base for all errors / پایه تمام خطاها
RPCError(message, code=0)API errors / خطاهای API
FloodWait(seconds, message="")Flood wait. Has .seconds / انتظار سیلاب
Unauthorized(message)Auth required / نیاز به احراز هویت
Forbidden(message)Permission denied / دسترسی غیرمجاز
BadRequest(message)Bad request / درخواست نادرست
ChatNotFound(message)Chat not found / چت یافت نشد
UserNotFound(message)User not found / کاربر یافت نشد
MessageNotFound(message)Message not found / پیام یافت نشد
SessionExpiredError(message)Session expired / نشست منقضی شده
AuthError(message)Auth failure / خطای احراز هویت
JoinChatError(message, link="")Join failure / خطای پیوستن
InvalidInviteLinkError(link, reason)Invalid link / لینک نامعتبر
InviteLinkExpiredError(link, reason)Expired link / لینک منقضی
ChatFullError(chat_id, limit)Chat is full / چت پر است
ChatDeactivatedError(chat_id)Chat deactivated / چت غیرفعال
MembershipRequiredError(chat_id, reason)Membership needed / نیاز به عضویت

Start in Seconds

Get a working Soroush Plus bot in just a few lines.

در چند خط کد، یک ربات سروش پلاس بسازید

bot.py
from spluspy import Client, filters

bot = Client("my_session")

@bot.on_message(filters.command("start"))
async def start_handler(client, message):
    await message.reply("Hello!")

@bot.on_message(filters.private & filters.text)
async def echo(client, message):
    await message.reply(f"You said: {message.text}")

bot.run()
fsm_example.py
from spluspy import Client, filters
from spluspy.fsm import State, StateMachine
from spluspy.storage import SQLiteStorage

bot = Client("bot")
sm = StateMachine(SQLiteStorage("fsm.db"))

class Form:
    name = State()
    age = State()

@sm.state(Form.name)
async def handle_name(ctx, msg):
    await ctx.set(name=msg.text)
    return StateTransition(to=Form.age)

@sm.state(Form.age)
async def handle_age(ctx, msg):
    data = await ctx.get()
    await msg.reply(f"Done: {data}")
    await ctx.finish()

Installation

Install with the features you need.

SplusPy را با قابلیت‌های مورد نیاز نصب کنید

Basic

pip install spluspy

Core library / کتابخانه اصلی

Fast Encryption

pip install spluspy[speed]

Performance optimized / بهینه عملکرد

Redis Backend

pip install spluspy[redis]

Shared state storage / ذخیره‌سازی مشترک

PostgreSQL

pip install spluspy[postgres]

Enterprise storage / ذخیره‌سازی سازمانی

All Dependencies

pip install spluspy[all]

Everything included / همه چیز

Sync Usage

from spluspy.sync import Client

No async needed / بدون async