Rubka 7.2.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. rubka/__init__.py +79 -0
  2. rubka/adaptorrubka/__init__.py +4 -0
  3. rubka/adaptorrubka/client/__init__.py +1 -0
  4. rubka/adaptorrubka/client/client.py +60 -0
  5. rubka/adaptorrubka/crypto/__init__.py +1 -0
  6. rubka/adaptorrubka/crypto/crypto.py +82 -0
  7. rubka/adaptorrubka/enums.py +36 -0
  8. rubka/adaptorrubka/exceptions.py +22 -0
  9. rubka/adaptorrubka/methods/__init__.py +1 -0
  10. rubka/adaptorrubka/methods/methods.py +90 -0
  11. rubka/adaptorrubka/network/__init__.py +3 -0
  12. rubka/adaptorrubka/network/helper.py +22 -0
  13. rubka/adaptorrubka/network/network.py +221 -0
  14. rubka/adaptorrubka/network/socket.py +31 -0
  15. rubka/adaptorrubka/sessions/__init__.py +1 -0
  16. rubka/adaptorrubka/sessions/sessions.py +72 -0
  17. rubka/adaptorrubka/types/__init__.py +1 -0
  18. rubka/adaptorrubka/types/socket/__init__.py +1 -0
  19. rubka/adaptorrubka/types/socket/message.py +187 -0
  20. rubka/adaptorrubka/utils/__init__.py +2 -0
  21. rubka/adaptorrubka/utils/configs.py +18 -0
  22. rubka/adaptorrubka/utils/utils.py +251 -0
  23. rubka/api.py +1723 -0
  24. rubka/asynco.py +2541 -0
  25. rubka/button.py +404 -0
  26. rubka/config.py +3 -0
  27. rubka/context.py +1077 -0
  28. rubka/decorators.py +30 -0
  29. rubka/exceptions.py +37 -0
  30. rubka/filters.py +330 -0
  31. rubka/helpers.py +1461 -0
  32. rubka/jobs.py +15 -0
  33. rubka/keyboards.py +16 -0
  34. rubka/keypad.py +298 -0
  35. rubka/logger.py +12 -0
  36. rubka/metadata.py +114 -0
  37. rubka/rubino.py +1271 -0
  38. rubka/tv.py +145 -0
  39. rubka/update.py +1038 -0
  40. rubka/utils.py +3 -0
  41. rubka-7.2.8.dist-info/METADATA +1047 -0
  42. rubka-7.2.8.dist-info/RECORD +45 -0
  43. rubka-7.2.8.dist-info/WHEEL +5 -0
  44. rubka-7.2.8.dist-info/entry_points.txt +2 -0
  45. rubka-7.2.8.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1047 @@
1
+ Metadata-Version: 2.4
2
+ Name: Rubka
3
+ Version: 7.2.8
4
+ Summary: Rubika: A Python library for interacting with the Rubika Bot API. This library provides an easy-to-use interface to send messages, polls, stickers, media files, manage groups and channels, handle inline keyboards, and implement advanced bot features like subscription management, user authentication, and message handling. Ideal for developers looking to automate and extend their Rubika bots with Python.
5
+ Home-page: https://github.com/Mahdy-Ahmadi/Rubka
6
+ Download-URL: https://github.com/Mahdy-Ahmadi/rubka/archive/refs/tags/v6.6.4.zip
7
+ Author: Mahdi Ahmadi
8
+ Author-email: mahdiahmadi.1208@gmail.com
9
+ Maintainer: Mahdi Ahmadi
10
+ Maintainer-email: mahdiahmadi.1208@gmail.com
11
+ License: MIT
12
+ Project-URL: Bug Tracker, https://t.me/Bprogrammer
13
+ Project-URL: Documentation, https://github.com/Mahdy-Ahmadi/rubka/blob/main/README.md
14
+ Project-URL: Source Code, https://github.com/Mahdy-Ahmadi/Rubka
15
+ Keywords: rubika bot api library chat messaging rubpy pyrubi rubigram rubika_bot rubika_api fast_rub
16
+ Classifier: Development Status :: 5 - Production/Stable
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: License :: OSI Approved :: MIT License
23
+ Classifier: Operating System :: OS Independent
24
+ Classifier: Topic :: Communications :: Chat
25
+ Classifier: Topic :: Software Development :: Libraries
26
+ Classifier: Natural Language :: Persian
27
+ Requires-Python: >=3.6
28
+ Description-Content-Type: text/markdown
29
+ Requires-Dist: requests
30
+ Requires-Dist: websocket-client
31
+ Requires-Dist: pycryptodome
32
+ Requires-Dist: aiohttp
33
+ Requires-Dist: httpx
34
+ Requires-Dist: tqdm
35
+ Requires-Dist: mutagen
36
+ Requires-Dist: markdownify
37
+ Requires-Dist: filetype
38
+ Requires-Dist: aiofiles
39
+ Dynamic: author
40
+ Dynamic: author-email
41
+ Dynamic: classifier
42
+ Dynamic: description
43
+ Dynamic: description-content-type
44
+ Dynamic: download-url
45
+ Dynamic: home-page
46
+ Dynamic: keywords
47
+ Dynamic: license
48
+ Dynamic: maintainer
49
+ Dynamic: maintainer-email
50
+ Dynamic: project-url
51
+ Dynamic: requires-dist
52
+ Dynamic: requires-python
53
+ Dynamic: summary
54
+
55
+ برای مشاهده مستندات کامل و وب هوک رایگان به آدرس زیر مراجعه کنید:
56
+ [rubka.ir](rubka.ir)
57
+ # 📚 Rubka Bot Python Library Documentation
58
+ # نمونه تنظیم وب‌هوک (Webhook) در کتابخونه rubka
59
+
60
+ برای مشاهده مستندات کامل و آخرین نسخه راهنما، لطفاً به آدرس زیر مراجعه کنید:
61
+ [github.com/Mahdy-Ahmadi](https://github.com/Mahdy-Ahmadi/rubka/blob/main/webhook.md)
62
+
63
+
64
+ ## 🧠 Introduction
65
+ `rubka` is a Python library to interact with the [Rubika Bot API](https://rubika.ir/). This library helps you create Telegram-like bots with support for messages, inline buttons, chat keypads, and callback handling.
66
+
67
+ ---
68
+
69
+ ## ⚙️ Installation
70
+
71
+ ```bash
72
+ pip install rubka
73
+ ```
74
+
75
+ If `importlib.metadata` is not available, it installs `importlib-metadata` automatically.
76
+
77
+ ---
78
+
79
+ ## 🚀 Getting Started
80
+
81
+ ```python
82
+ from rubka.asynco import Robot
83
+ from rubka.context import Message
84
+ import asyncio
85
+ bot = Robot(token="YOUR_TOKEN_HERE")
86
+
87
+ @bot.on_message(commands=["start"])
88
+ async def start(bot: Robot, message: Message):
89
+ await message.reply("سلام! خوش آمدید!")
90
+
91
+ asyncio.run(bot.run())
92
+ ```
93
+
94
+ ---
95
+
96
+ ## 📬 Handling Messages
97
+
98
+ You can handle incoming text messages using `@bot.on_message()`:
99
+
100
+ ```python
101
+ @bot.on_message(commands=["hello"])
102
+ async def greet(bot: Robot, message: Message):
103
+ await message.reply("سلام کاربر عزیز 👋")
104
+ ```
105
+
106
+ You can also add filters.
107
+
108
+ ---
109
+
110
+ ## 🎮 Handling Callback Buttons
111
+
112
+ ```python
113
+ from rubka.keypad import ChatKeypadBuilder
114
+
115
+ @bot.on_message(commands=["gender"])
116
+ def gender(bot: Robot, message: Message):
117
+ keypad = ChatKeypadBuilder().row(
118
+ ChatKeypadBuilder().button(id="male", text="👨 مرد"),
119
+ ChatKeypadBuilder().button(id="female", text="👩 زن")
120
+ ).build()
121
+ message.reply_keypad("جنسیت خود را انتخاب کنید:", keypad)
122
+
123
+ @bot.on_callback("male")
124
+ def on_male(bot: Robot, message: Message):
125
+ message.reply("شما مرد هستید")
126
+
127
+ @bot.on_callback("female")
128
+ def on_female(bot: Robot, message: Message):
129
+ message.reply("شما زن هستید")
130
+ ```
131
+
132
+ ---
133
+
134
+ ## 🔘 Inline Button Builder
135
+
136
+ ```python
137
+ from rubka.button import InlineBuilder
138
+
139
+ builder = InlineBuilder().row(
140
+ InlineBuilder().button_simple(id="info", text="اطلاعات")
141
+ ).build()
142
+ ```
143
+
144
+ ---
145
+
146
+ ## 🔄 Check if User Joined a Channel
147
+
148
+ ```python
149
+ channel_guid = "c0xABCDEF..."
150
+
151
+ @bot.on_message(commands=["check"])
152
+ def check(bot: Robot, message: Message):
153
+ if bot.check_join(channel_guid, message.chat_id):
154
+ message.reply("✅ شما عضو کانال هستید")
155
+ else:
156
+ message.reply("❌ لطفاً ابتدا در کانال عضو شوید")
157
+ ```
158
+
159
+ ---
160
+
161
+ ## 💬 Utility Methods
162
+
163
+ | Method | Description |
164
+ |--------|-------------|
165
+ | `get_chat(chat_id)` | دریافت اطلاعات چت |
166
+ | `get_name(chat_id)` | دریافت نام کاربر |
167
+ | `get_username(chat_id)` | دریافت نام‌کاربری |
168
+ | `send_message(...)` | ارسال پیام متنی |
169
+ | `edit_message_text(...)` | ویرایش پیام |
170
+ | `delete_message(...)` | حذف پیام |
171
+ | `send_location(...)` | ارسال موقعیت مکانی |
172
+ | `send_poll(...)` | ارسال نظرسنجی |
173
+ | `send_contact(...)` | ارسال مخاطب |
174
+ | `forward_message(...)` | فوروارد پیام |
175
+
176
+ ---
177
+
178
+ ## 🎛 Inline Query Support
179
+
180
+ ```python
181
+ @bot.on_inline_query()
182
+ def inline(bot: Robot, message: InlineMessage):
183
+ message.answer("نتیجه اینلاین")
184
+ ```
185
+
186
+ ---
187
+
188
+ ## 🧱 Button Types
189
+
190
+ Supported inline button types include:
191
+
192
+ - `Simple`
193
+ - `Payment`
194
+ - `Calendar`
195
+ - `Location`
196
+ - `CameraImage`, `CameraVideo`
197
+ - `GalleryImage`, `GalleryVideo`
198
+ - `File`, `Audio`, `RecordAudio`
199
+ - `MyPhoneNumber`, `MyLocation`
200
+ - `Textbox`, `Barcode`, `Link`
201
+
202
+ See `InlineBuilder` for more.
203
+
204
+ ---
205
+
206
+ ## 🧩 Dynamic Chat Keypad
207
+
208
+ ```python
209
+ builder = ChatKeypadBuilder()
210
+ keypad = builder.row(
211
+ builder.button(id="play", text="🎮 بازی کن"),
212
+ builder.button(id="exit", text="❌ خروج")
213
+ ).build()
214
+ ```
215
+
216
+ ---
217
+
218
+ ## 🧪 Set Commands
219
+
220
+ ```python
221
+ bot.set_commands([
222
+ {"command": "start", "description": "شروع"},
223
+ {"command": "help", "description": "راهنما"}
224
+ ])
225
+ ```
226
+
227
+ ---
228
+
229
+ ## 🔄 Update Offset Automatically
230
+
231
+ Bot updates are handled using `get_updates()` and `offset_id` is managed internally.
232
+
233
+ ---
234
+
235
+ ## 🛠 Advanced Features
236
+
237
+ - `update_bot_endpoint()` – تنظیم webhook یا polling
238
+ - `remove_keypad()` – حذف صفحه‌کلید چت
239
+ - `edit_chat_keypad()` – ویرایش یا افزودن صفحه‌کلید چت
240
+
241
+ ---
242
+
243
+ # 📘 Rubka Bot Method Reference
244
+
245
+ مستندات مربوط به متدهای اصلی کلاس `Robot` در کتابخانه Rubka.
246
+
247
+ ---
248
+
249
+ ## ✅ پیام‌ها و هندلرها
250
+
251
+ ### `on_message(filters=None, commands=None)`
252
+ **توضیح:** ثبت هندلر برای پیام‌های ورودی.
253
+ - `filters`: تابع شرطی برای فیلتر پیام‌ها (اختیاری)
254
+ - `commands`: لیست دستورهایی که شروع با `/` هستند (اختیاری)
255
+
256
+ ### `on_callback(button_id=None)`
257
+ **توضیح:** ثبت هندلر برای دکمه‌های فشرده‌شده
258
+ - `button_id`: آیدی دکمه‌ای که باید هندل شود (اختیاری)
259
+
260
+ ### `on_inline_query()`
261
+ **توضیح:** ثبت هندلر برای پیام‌های اینلاین (inline query)
262
+
263
+ ---
264
+
265
+ ## 📨 ارسال پیام
266
+
267
+ ### `send_message(...)`
268
+ **توضیح:** ارسال پیام متنی به چت
269
+ - `chat_id`: آیدی چت مقصد *(str)* ✅
270
+ - `text`: محتوای پیام *(str)* ✅
271
+ - `chat_keypad`: کی‌پد معمولی *(dict)*
272
+ - `inline_keypad`: کی‌پد اینلاین *(dict)*
273
+ - `reply_to_message_id`: پاسخ به پیام خاص *(str)*
274
+ - `disable_notification`: بدون نوتیف *(bool)*
275
+ - `chat_keypad_type`: حالت کی‌پد *("New" | "Removed")*
276
+
277
+ ---
278
+
279
+ ## 📁 ارسال فایل‌ها
280
+
281
+ ### متدهای مشترک (فایل، موزیک، ویس، گیف، عکس):
282
+ - `send_document(...)`
283
+ - `send_music(...)`
284
+ - `send_voice(...)`
285
+ - `send_gif(...)`
286
+ - `send_image(...)`
287
+
288
+ **پارامترهای اصلی:**
289
+ - `chat_id`: آیدی چت
290
+ - `path`: مسیر فایل یا URL (اختیاری)
291
+ - `file_id`: اگر فایل قبلاً آپلود شده باشد
292
+ - `text`: کپشن فایل
293
+ - `file_name`: نام فایل
294
+ - `inline_keypad`, `chat_keypad`, `reply_to_message_id`, `disable_notification`, `chat_keypad_type`
295
+
296
+ ---
297
+
298
+ ## 📍 سایر متدهای مهم
299
+
300
+ ### `get_me()`
301
+ دریافت اطلاعات ربات
302
+
303
+ ### `get_chat(chat_id)`
304
+ دریافت اطلاعات یک چت
305
+
306
+ ### `get_name(chat_id)`
307
+ دریافت نام مخاطب بر اساس `first_name` و `last_name`
308
+
309
+ ### `get_username(chat_id)`
310
+ دریافت نام کاربری چت (در صورت وجود)
311
+
312
+ ### `check_join(channel_guid, chat_id)`
313
+ بررسی عضویت کاربر در کانال خاص
314
+
315
+ ### `remove_keypad(chat_id)`
316
+ حذف کی‌پد معمولی چت
317
+
318
+ ### `edit_chat_keypad(chat_id, chat_keypad)`
319
+ ویرایش یا اضافه کردن کی‌پد چت
320
+
321
+ ### `edit_message_text(chat_id, message_id, text)`
322
+ ویرایش متن پیام ارسال‌شده
323
+
324
+ ### `edit_inline_keypad(chat_id, message_id, inline_keypad)`
325
+ ویرایش کی‌پد اینلاین پیام
326
+
327
+ ### `delete_message(chat_id, message_id)`
328
+ حذف پیام از چت
329
+
330
+ ### `send_poll(chat_id, question, options)`
331
+ ارسال نظرسنجی به چت
332
+
333
+ ### `send_location(chat_id, latitude, longitude, ...)`
334
+ ارسال موقعیت مکانی به چت
335
+
336
+ ### `send_contact(chat_id, first_name, last_name, phone_number)`
337
+ ارسال مخاطب به چت
338
+
339
+ ### `forward_message(from_chat_id, message_id, to_chat_id)`
340
+ فروارد کردن پیام از یک چت به چت دیگر
341
+
342
+ ### `set_commands(bot_commands)`
343
+ تنظیم دستورات رسمی ربات (برای `/help` و ...)
344
+
345
+ ### `update_bot_endpoint(url, type)`
346
+ تنظیم وب‌هوک یا polling برای دریافت پیام‌ها
347
+
348
+ ---
349
+
350
+ ## 📦 مدیریت فایل و آپلود
351
+
352
+ ### `get_upload_url(media_type)`
353
+ دریافت آدرس آپلود فایل برای انواع مختلف: File, Image, Voice, Music, Gif
354
+
355
+ ### `upload_media_file(upload_url, name, path)`
356
+ آپلود فایل از مسیر محلی یا URL به Rubika و دریافت `file_id`
357
+
358
+ ---
359
+
360
+ ## 🔄 دریافت بروزرسانی‌ها
361
+
362
+ ### `get_updates(offset_id=None, limit=None)`
363
+ دریافت بروزرسانی‌ها (برای polling)
364
+
365
+
366
+ ---
367
+
368
+ # 📦 Rubka `Message` Class & Media Reply API Documentation
369
+
370
+ ## 🧾 معرفی کلاس `Message`
371
+
372
+ کلاس `Message` در کتابخانه Rubka ابزاری کلیدی برای مدیریت پیام‌های دریافتی در ربات است. این کلاس، قابلیت‌هایی همچون پاسخ به پیام، ارسال مدیا، حذف یا ویرایش پیام، و استفاده از صفحه‌کلید و دکمه‌های اینلاین را فراهم می‌کند.
373
+
374
+ ---
375
+
376
+ ## ⚙️ مشخصات کلاس `Message`
377
+
378
+ ```python
379
+ Message(bot, chat_id, message_id, sender_id, text=None, raw_data=None)
380
+ ```
381
+
382
+ ### پارامترها:
383
+
384
+ | پارامتر | توضیح |
385
+ | ------------ | ---------------------------------------- |
386
+ | `bot` | نمونه‌ی شی ربات |
387
+ | `chat_id` | شناسه چت |
388
+ | `message_id` | آیدی پیام |
389
+ | `sender_id` | شناسه فرستنده |
390
+ | `text` | متن پیام |
391
+ | `raw_data` | داده‌ی خام پیام (دیکشنری دریافتی از API) |
392
+
393
+ ### ویژگی‌ها (Attributes):
394
+
395
+ - `reply_to_message_id` – اگر پیام در پاسخ ارسال شده باشد، آیدی پیام اولیه
396
+ - `file`, `sticker`, `poll`, `contact_message`, `location`, ... – داده‌های مربوطه اگر وجود داشته باشند
397
+
398
+ ---
399
+
400
+ ## 📩 متدهای پاسخ‌دهی
401
+
402
+ ### ✉️ `reply(text: str, **kwargs)`
403
+
404
+ پاسخ متنی به پیام با قابلیت ارسال دکمه و گزینه‌های اضافی.
405
+
406
+ ### 📊 `reply_poll(question, options, **kwargs)`
407
+
408
+ ارسال نظرسنجی در پاسخ به پیام.
409
+
410
+ ### 📎 `reply_document(...)`
411
+
412
+ ارسال فایل یا سند با متن اختیاری و دکمه.
413
+
414
+ ### 🖼 `reply_image(...)`
415
+
416
+ ارسال تصویر با قابلیت reply همراه دکمه‌های chat یا inline.
417
+
418
+ ### 🎵 `reply_music(...)`
419
+
420
+ ارسال موزیک در پاسخ.
421
+
422
+ ### 🎤 `reply_voice(...)`
423
+
424
+ ارسال پیام صوتی (voice).
425
+
426
+ ### 🎞 `reply_gif(...)`
427
+
428
+ ارسال گیف در پاسخ به پیام.
429
+
430
+ ### 🗺 `reply_location(latitude, longitude, **kwargs)`
431
+
432
+ ارسال لوکیشن در پاسخ.
433
+
434
+ ### 📇 `reply_contact(first_name, last_name, phone_number, **kwargs)`
435
+
436
+ ارسال مخاطب در پاسخ.
437
+
438
+ ---
439
+
440
+ ## 🔘 پاسخ با دکمه‌ها
441
+
442
+ ### `reply_keypad(text, keypad, **kwargs)`
443
+
444
+ ارسال پیام با صفحه‌کلید چتی (ChatKeypad).
445
+
446
+ ### `reply_inline(text, inline_keypad, **kwargs)`
447
+
448
+ ارسال پیام با دکمه‌های شیشه‌ای (Inline).
449
+
450
+ ---
451
+
452
+ ## 📦 پاسخ با فایل‌ها و استیکر
453
+
454
+ ### `reply_sticker(sticker_id, **kwargs)`
455
+
456
+ ارسال استیکر در پاسخ به پیام.
457
+
458
+ ### `reply_file(file_id, **kwargs)`
459
+
460
+ ارسال فایل بر اساس File ID.
461
+
462
+ ---
463
+
464
+ ## ✏️ ویرایش و حذف
465
+
466
+ ### `edit(new_text)`
467
+
468
+ ویرایش متن پیام.
469
+
470
+ ### `delete()`
471
+
472
+ حذف پیام فعلی.
473
+
474
+ ---
475
+
476
+ ## 📤 مثال کاربردی کامل
477
+
478
+ ```python
479
+ @bot.on_message()
480
+ def handler(bot: Robot, message: Message):
481
+ # پاسخ با تصویر و دکمه‌های مختلف
482
+ message.reply_image(
483
+ path="https://s6.uupload.ir/files/sample.png",
484
+ text="📷 تصویر پاسخ‌داده‌شده با دکمه‌ها",
485
+ inline_keypad=inline_keypad
486
+ )
487
+
488
+ message.reply_image(
489
+ path="https://s6.uupload.ir/files/sample.png",
490
+ text="📷 تصویر دوم با صفحه‌کلید",
491
+ chat_keypad=chat_keypad,
492
+ chat_keypad_type="New"
493
+ )
494
+
495
+ @bot.on_callback()
496
+ def callback_handler(bot: Robot, message: Message):
497
+ data = message.aux_data.button_id
498
+ if data == "btn_male":
499
+ message.reply("سلام آقا 👨")
500
+ elif data == "btn_female":
501
+ message.reply("سلام خانم 👩")
502
+ else:
503
+ message.reply(f"دکمه ناشناخته: {data}")
504
+ ```
505
+
506
+ ---
507
+
508
+ ## 🧠 نکته
509
+
510
+ تمامی متدهای `reply_*` به‌صورت خودکار پیام جدید را در پاسخ به پیام اصلی ارسال می‌کنند (`reply_to_message_id` به‌صورت داخلی تنظیم می‌شود).
511
+
512
+ ---
513
+
514
+ ---
515
+
516
+ ## 📤 مثال کاربردی کامل
517
+
518
+ ```python
519
+ from rubka import Robot
520
+ from rubka.keypad import ChatKeypadBuilder
521
+ from rubka.button import InlineBuilder
522
+ from rubka.context import Message
523
+
524
+ chat_keypad = ChatKeypadBuilder().row(
525
+ ChatKeypadBuilder().button(id="btn_female", text="زن"),
526
+ ChatKeypadBuilder().button(id="btn_male", text="مرد")
527
+ ).build()
528
+
529
+ inline_keypad = (
530
+ InlineBuilder()
531
+ .row(
532
+ InlineBuilder().button_simple("btn_bets", "button1"),
533
+ InlineBuilder().button_simple("btn_rps", "button2")
534
+ )
535
+ .row(
536
+ InlineBuilder().button_simple("btn_chatid", "butthon3")
537
+ )
538
+ .build()
539
+ )
540
+
541
+ bot = Robot("توکن شما")
542
+
543
+ @bot.on_message()
544
+ def handler(bot: Robot, message: Message):
545
+ message.reply_image(
546
+ path="https://s6.uupload.ir/files/chatgpt_image_jul_20,_2025,_10_22_47_pm_oiql.png",
547
+ text="📷 عکس ریپلای شده دکمه شیشه ای",
548
+ inline_keypad=inline_keypad
549
+ )
550
+
551
+ message.reply_image(
552
+ path="https://s6.uupload.ir/files/chatgpt_image_jul_20,_2025,_10_22_47_pm_oiql.png",
553
+ text="📷 عکس ریپلای شده دکمه کیبوردی",
554
+ chat_keypad=chat_keypad,
555
+ chat_keypad_type="New"
556
+ )
557
+
558
+ @bot.on_callback()
559
+ def callback_handler(bot: Robot, message: Message):
560
+ data = message.aux_data.button_id
561
+ if data == "btn_male":
562
+ message.reply("سلام مرد")
563
+ elif data == "btn_female":
564
+ message.reply("سلام زن")
565
+ else:
566
+ message.reply(f"دکمه ناشناخته: {data}")
567
+
568
+ bot.run()
569
+ ```
570
+
571
+ ---
572
+
573
+ ## 🧱 مستندات کلاس `InlineBuilder`
574
+
575
+ کلاس `InlineBuilder` برای ساخت دکمه‌های اینلاین استفاده می‌شود که در پیام‌های ربات قابل استفاده هستند.
576
+
577
+ ### ✅ روش استفاده
578
+
579
+ ```python
580
+ from rubka.button import InlineBuilder
581
+
582
+ builder = InlineBuilder()
583
+ inline_keypad = builder.row(
584
+ builder.button_simple("btn_1", "دکمه ۱"),
585
+ builder.button_simple("btn_2", "دکمه ۲")
586
+ ).build()
587
+ ```
588
+
589
+ ### 📚 دکمه‌های پشتیبانی‌شده
590
+
591
+ - `button_simple(id, text)` – دکمه ساده
592
+ - `button_payment(id, title, amount, description=None)` – پرداخت
593
+ - `button_calendar(id, title, type_, ...)` – انتخاب تاریخ
594
+ - `button_location(id, type_, image_url, ...)` – ارسال موقعیت مکانی
595
+ - `button_string_picker(...)` – انتخاب گزینه از لیست
596
+ - `button_number_picker(...)` – انتخاب عدد از بازه
597
+ - `button_textbox(...)` – فیلد ورود متنی
598
+ - `button_selection(...)` – انتخاب چندگزینه‌ای پیشرفته
599
+ - `button_camera_image(...)`, `button_camera_video(...)`
600
+ - `button_gallery_image(...)`, `button_gallery_video(...)`
601
+ - `button_file(...)`, `button_audio(...)`, `button_record_audio(...)`
602
+ - `button_my_phone_number(...)`, `button_my_location(...)`
603
+ - `button_ask_my_phone_number(...)`, `button_ask_location(...)`
604
+ - `button_barcode(...)`
605
+ - `button_link(id, title, url)` – لینک خارجی
606
+
607
+ ### 🧱 ساخت نهایی
608
+
609
+ ```python
610
+ keypad = builder.build()
611
+ ```
612
+
613
+ خروجی به صورت دیکشنری با کلید `rows` خواهد بود که می‌توانید در متد `send_message` یا `reply_*` استفاده کنید.
614
+
615
+ ---
616
+
617
+ ## ⌨️ مستندات کلاس `ChatKeypadBuilder`
618
+
619
+ کلاس `ChatKeypadBuilder` برای ساخت صفحه‌کلید چتی (chat keypad) استفاده می‌شود.
620
+
621
+ ### 🛠 روش استفاده
622
+
623
+ ```python
624
+ from rubka.keypad import ChatKeypadBuilder
625
+
626
+ keypad = ChatKeypadBuilder().row(
627
+ ChatKeypadBuilder().button("btn_1", "دکمه ۱"),
628
+ ChatKeypadBuilder().button("btn_2", "دکمه ۲")
629
+ ).build()
630
+ ```
631
+
632
+ ### 📋 متدها
633
+
634
+ - `button(id, text, type="Simple")` – ساخت یک دکمه ساده یا از نوع خاص
635
+ - `row(*buttons)` – افزودن یک ردیف به کیبورد (دکمه‌ها باید با `button()` ساخته شوند)
636
+ - `build(resize_keyboard=True, on_time_keyboard=False)` – ساخت خروجی نهایی برای ارسال به کاربر
637
+
638
+ ### 📦 خروجی `build()`
639
+
640
+ ```json
641
+ {
642
+ "rows": [
643
+ {"buttons": [
644
+ {"id": "btn_1", "type": "Simple", "button_text": "دکمه ۱"},
645
+ {"id": "btn_2", "type": "Simple", "button_text": "دکمه ۲"}
646
+ ]}
647
+ ],
648
+ "resize_keyboard": true,
649
+ "on_time_keyboard": false
650
+ }
651
+ ```
652
+
653
+ ---
654
+
655
+ # مستندات پروژه: تایمر پیام در ربات Rubika
656
+
657
+ این پروژه یک ربات بر پایه کتابخانه‌ی `rubka` است که به کاربر امکان می‌دهد با استفاده از کی‌پد، یک تایمر تنظیم کرده و پس از پایان تایمر، پیامی برای او ارسال شود. تمرکز اصلی این مستند، بر روی کلاس `Job` است که برای زمان‌بندی اجرای دستورات استفاده شده است.
658
+
659
+ ## ساختار کلی پروژه
660
+ - استفاده از کتابخانه `rubka` برای ارتباط با Rubika Bot API
661
+ - تعریف یک کی‌پد با گزینه‌های تاخیر زمانی مختلف (۱۰ الی ۱۵۰ ثانیه)
662
+ - استفاده از کلاس `Job` برای مدیریت اجرای زمان‌بندی‌شده یک تابع
663
+ - نمایش شمارش معکوس با به‌روزرسانی مداوم پیام
664
+
665
+ ---
666
+
667
+ ## کلاس `Job` چیست؟
668
+ کلاس `Job` در فایل `rubka.jobs` تعریف شده و هدف آن اجرای یک تابع خاص پس از گذشت یک بازه زمانی مشخص است.
669
+
670
+ ### نحوه استفاده:
671
+ ```python
672
+ from rubka.jobs import Job
673
+
674
+ job = Job(delay_in_seconds, callback_function)
675
+ ```
676
+
677
+ ### پارامترها:
678
+ | پارامتر | نوع | توضیح |
679
+ |--------|-----|-------|
680
+ | `delay_in_seconds` | `int` | مدت زمانی که باید قبل از اجرای تابع منتظر بماند |
681
+ | `callback_function` | `function` | تابعی که بعد از پایان زمان باید اجرا شود |
682
+
683
+ ### ویژگی‌ها:
684
+ - اجرای غیرهمزمان (با استفاده از Thread داخلی)
685
+ - مناسب برای سناریوهایی مانند تایمرها، یادآورها و اعلان‌های زمان‌بندی شده
686
+
687
+ ---
688
+
689
+ ## مثال از استفاده در پروژه:
690
+
691
+ ```python
692
+ def delayed_send():
693
+ if user_id not in active_jobs:
694
+ return
695
+ bot.send_message(
696
+ message.chat_id,
697
+ f"✅ کاربر {user_id} : زمان {seconds} ثانیه گذشت و دستور اجرا شد! ⏰"
698
+ )
699
+ active_jobs.pop(user_id, None)
700
+
701
+ job = Job(seconds, delayed_send)
702
+ active_jobs[user_id] = job
703
+ ```
704
+
705
+ در این مثال، پس از انتخاب تاخیر زمانی توسط کاربر، یک شی از کلاس `Job` ساخته می‌شود که تابع `delayed_send` را پس از `seconds` ثانیه اجرا می‌کند.
706
+
707
+ ---
708
+
709
+ ## تابع `countdown_edit`
710
+ این تابع تایمر فعال را به صورت زنده باقیمانده زمان را به‌روزرسانی می‌کند:
711
+ ```python
712
+ def countdown_edit(chat_id, message_id, duration_sec):
713
+ # اجرای یک Thread برای به‌روزرسانی پیام در هر ثانیه
714
+ ```
715
+
716
+ ---
717
+ ## نمونه کد ساخته شده
718
+ ```python
719
+ from rubka import Robot
720
+ from rubka.context import Message
721
+ from rubka.keypad import ChatKeypadBuilder
722
+ from rubka.jobs import Job
723
+ from datetime import datetime, timedelta
724
+ import threading
725
+ import time
726
+
727
+ bot = Robot("token")
728
+
729
+ active_jobs = {}
730
+
731
+ def build_delay_keypad():
732
+ delays = [10, 20, 30, 40, 50, 60, 75, 90, 120, 150]
733
+ builder = ChatKeypadBuilder()
734
+ buttons = []
735
+ for sec in delays:
736
+ buttons.append(builder.button(id=f"delay_{sec}", text=f"⏳ بعد از {sec} ثانیه"))
737
+ buttons.append(builder.button(id="cancel", text="❌ انصراف"))
738
+
739
+ rows = [buttons[i:i+3] for i in range(0, len(buttons), 3)]
740
+ keypad = ChatKeypadBuilder()
741
+ for row in rows:
742
+ keypad.row(*row)
743
+ return keypad.build()
744
+
745
+ def countdown_edit(chat_id: str, message_id: str, duration_sec: int):
746
+ start_time = datetime.now()
747
+ end_time = start_time + timedelta(seconds=duration_sec)
748
+
749
+ def run():
750
+ while True:
751
+ now = datetime.now()
752
+ if now >= end_time:
753
+ try:
754
+ bot.edit_message_text(chat_id, message_id, "⏰ زمان تمام شد!")
755
+ except Exception as e:
756
+ print("خطا در ویرایش پیام:", e)
757
+ break
758
+
759
+ remaining = end_time - now
760
+ text = (
761
+ f"⏳ تایمر فعال است...\n"
762
+ f"🕰 شروع: {start_time.strftime('%H:%M:%S')}\n"
763
+ f"⏲ پایان: {end_time.strftime('%H:%M:%S')}\n"
764
+ f"⌛ باقی‌مانده: {str(remaining).split('.')[0]}"
765
+ )
766
+ try:
767
+ bot.edit_message_text(chat_id, message_id, text)
768
+ except Exception as e:
769
+ print("خطا در ویرایش پیام:", e)
770
+ time.sleep(1)
771
+
772
+ threading.Thread(target=run, daemon=True).start()
773
+
774
+ @bot.on_message(commands=["start"])
775
+ def start_handler(bot: Robot, message: Message):
776
+ keypad = build_delay_keypad()
777
+ message.reply_keypad(
778
+ "سلام 👋\n"
779
+ "یک زمان برای ارسال پیام انتخاب کنید:\n"
780
+ "📅 تاریخ و ساعت فعلی: " + datetime.now().strftime("%Y/%m/%d %H:%M:%S"),
781
+ keypad
782
+ )
783
+
784
+ @bot.on_callback()
785
+ def callback_delay(bot: Robot, message: Message):
786
+ btn_id = message.aux_data.button_id
787
+ user_id = message.sender_id
788
+
789
+ if btn_id == "cancel":
790
+ if user_id in active_jobs:
791
+ active_jobs.pop(user_id)
792
+ message.reply("❌ همه ارسال‌های زمان‌بندی شده لغو شدند.")
793
+ else:
794
+ message.reply("⚠️ شما هیچ ارسال زمان‌بندی شده‌ای ندارید.")
795
+ return
796
+
797
+ if not btn_id.startswith("delay_"):
798
+ message.reply("❌ دکمه نامعتبر است!")
799
+ return
800
+
801
+ seconds = int(btn_id.split("_")[1])
802
+
803
+ if user_id in active_jobs:
804
+ active_jobs.pop(user_id)
805
+
806
+ sent_msg = bot.send_message(
807
+ message.chat_id,
808
+ f"⏳ تایمر {seconds} ثانیه‌ای شروع شد...\n🕰 زمان شروع: {datetime.now().strftime('%H:%M:%S')}"
809
+ )
810
+
811
+ countdown_edit(message.chat_id, sent_msg['data']['message_id'], seconds)
812
+ def delayed_send():
813
+ if user_id not in active_jobs:
814
+ return
815
+ bot.send_message(
816
+ message.chat_id,
817
+ f"✅ کاربر {user_id} : زمان {seconds} ثانیه گذشت و دستور اجرا شد! ⏰"
818
+ )
819
+ active_jobs.pop(user_id, None)
820
+
821
+ job = Job(seconds, delayed_send)
822
+ active_jobs[user_id] = job
823
+
824
+ message.reply(
825
+ f"⏳ ثبت شد! پیام شما پس از {seconds} ثانیه ارسال خواهد شد.\n"
826
+ f"🕰 زمان شروع ثبت شده: {datetime.now().strftime('%H:%M:%S')}"
827
+ )
828
+ bot.run()
829
+ ```
830
+
831
+ ##مثال ساده تر
832
+ ```python
833
+ from rubka import Robot
834
+ from rubka.context import Message
835
+ from rubka.jobs import Job
836
+ from datetime import datetime
837
+
838
+ bot = Robot("")
839
+
840
+ active_jobs = {}
841
+
842
+ @bot.on_message(commands=["timer"])
843
+ def timer_handler(bot: Robot, message: Message):
844
+ user_id = message.sender_id
845
+ chat_id = message.chat_id
846
+ parts = message.text.split()
847
+
848
+ if len(parts) != 2 or not parts[1].isdigit():
849
+ return message.reply("⚠️ لطفاً مدت زمان را به صورت صحیح وارد کنید. مثل: `/timer 30`", parse_mode="markdown")
850
+
851
+ seconds = int(parts[1])
852
+ if user_id in active_jobs:
853
+ active_jobs.pop(user_id)
854
+
855
+ message.reply(f"⏳ تایمر {seconds} ثانیه‌ای شروع شد!\n🕰 زمان شروع: {datetime.now().strftime('%H:%M:%S')}")
856
+
857
+ def after_delay():
858
+ if user_id not in active_jobs:
859
+ return
860
+ bot.send_message(chat_id, f"✅ تایمر {seconds} ثانیه‌ای تمام شد! ⏰")
861
+ active_jobs.pop(user_id, None)
862
+
863
+ job = Job(seconds, after_delay)
864
+ active_jobs[user_id] = job
865
+
866
+ bot.run()
867
+
868
+ ```
869
+
870
+ ##نمونه کد ادیت تایم و کرون جاب با اینلاین کیبورد
871
+
872
+ ```python
873
+ from rubka import Robot
874
+ from rubka.context import Message
875
+ from rubka.keypad import ChatKeypadBuilder
876
+ from rubka.jobs import Job
877
+ from datetime import datetime, timedelta
878
+ import threading
879
+ import time
880
+
881
+ bot = Robot("token")
882
+ bot.edit_inline_keypad
883
+ active_jobs = {}
884
+
885
+ def build_delay_keypad():
886
+ delays = [10, 20, 30, 40, 50, 60, 75, 90, 120, 150]
887
+ builder = ChatKeypadBuilder()
888
+ buttons = []
889
+ for sec in delays:
890
+ buttons.append(builder.button(id=f"delay_{sec}", text=f"⏳ بعد از {sec} ثانیه"))
891
+ buttons.append(builder.button(id="cancel", text="❌ انصراف"))
892
+
893
+ rows = [buttons[i:i+3] for i in range(0, len(buttons), 3)]
894
+ keypad = ChatKeypadBuilder()
895
+ for row in rows:
896
+ keypad.row(*row)
897
+ return keypad.build()
898
+
899
+ def countdown_edit(chat_id: str, message_id: str, duration_sec: int):
900
+ start_time = datetime.now()
901
+ end_time = start_time + timedelta(seconds=duration_sec)
902
+
903
+ def run():
904
+ while True:
905
+ now = datetime.now()
906
+ if now >= end_time:
907
+ try:
908
+ bot.edit_message_text(chat_id, message_id, "⏰ زمان تمام شد!")
909
+ except Exception as e:
910
+ print("خطا در ویرایش پیام:", e)
911
+ break
912
+
913
+ remaining = end_time - now
914
+ text = (
915
+ f"⏳ تایمر فعال است...\n"
916
+ f"🕰 شروع: {start_time.strftime('%H:%M:%S')}\n"
917
+ f"⏲ پایان: {end_time.strftime('%H:%M:%S')}\n"
918
+ f"⌛ باقی‌مانده: {str(remaining).split('.')[0]}"
919
+ )
920
+ try:
921
+ bot.edit_message_text(chat_id, message_id, text)
922
+ except Exception as e:
923
+ print("خطا در ویرایش پیام:", e)
924
+ time.sleep(1)
925
+
926
+ threading.Thread(target=run, daemon=True).start()
927
+
928
+ @bot.on_message(commands=["start"])
929
+ def start_handler(bot: Robot, message: Message):
930
+ keypad = build_delay_keypad()
931
+ message.reply_keypad(
932
+ "سلام 👋\n"
933
+ "یک زمان برای ارسال پیام انتخاب کنید:\n"
934
+ "📅 تاریخ و ساعت فعلی: " + datetime.now().strftime("%Y/%m/%d %H:%M:%S"),
935
+ keypad
936
+ )
937
+
938
+ @bot.on_callback()
939
+ def callback_delay(bot: Robot, message: Message):
940
+ btn_id = message.aux_data.button_id
941
+ user_id = message.sender_id
942
+
943
+ if btn_id == "cancel":
944
+ if user_id in active_jobs:
945
+ active_jobs.pop(user_id)
946
+ message.reply("❌ همه ارسال‌های زمان‌بندی شده لغو شدند.")
947
+ else:
948
+ message.reply("⚠️ شما هیچ ارسال زمان‌بندی شده‌ای ندارید.")
949
+ return
950
+ if not btn_id.startswith("delay_"):
951
+ message.reply("❌ دکمه نامعتبر است!")
952
+ return
953
+ seconds = int(btn_id.split("_")[1])
954
+ if user_id in active_jobs:
955
+ active_jobs.pop(user_id)
956
+ sent_msg = bot.edit_inline_keypad(
957
+ message.chat_id,
958
+ f"⏳ تایمر {seconds} ثانیه‌ای شروع شد...\n🕰 زمان شروع: {datetime.now().strftime('%H:%M:%S')}"
959
+ )
960
+ print(sent_msg)
961
+ countdown_edit(message.chat_id, sent_msg['data']['message_id'], seconds)
962
+ def delayed_send():
963
+ if user_id not in active_jobs:
964
+ return
965
+
966
+ bot.send_message(
967
+ message.chat_id,
968
+ f"✅ کاربر {user_id} : زمان {seconds} ثانیه گذشت و دستور اجرا شد! ⏰"
969
+ )
970
+ active_jobs.pop(user_id, None)
971
+
972
+ job = Job(seconds, delayed_send)
973
+ active_jobs[user_id] = job
974
+
975
+ message.reply(
976
+ f"⏳ ثبت شد! پیام شما پس از {seconds} ثانیه ارسال خواهد شد.\n"
977
+ f"🕰 زمان شروع ثبت شده: {datetime.now().strftime('%H:%M:%S')}"
978
+ )
979
+
980
+ bot.run()
981
+ ```
982
+ # ✅ Force Join (اجبار به عضویت در کانال) — Rubka Bot
983
+
984
+ این مستند نحوه استفاده از قابلیت **اجبار به عضویت در یک کانال (Force Join)** در ربات‌های ساخته‌شده با کتابخانه Rubka را توضیح می‌دهد.
985
+
986
+ ---
987
+
988
+ ## 🎯 هدف
989
+
990
+ اطمینان از اینکه کاربر عضو یک کانال خاص است، قبل از ادامه تعامل با ربات. اگر عضو نبود، به او اطلاع داده شود یا لینک عضویت ارسال گردد.
991
+
992
+ ---
993
+
994
+ ## 📦 پیش‌نیازها
995
+
996
+ - نصب و راه‌اندازی کتابخانه `rubka`
997
+ - توکن معتبر ربات Rubika
998
+ - دسترسی به `channel_guid` (شناسه عددی کانال)
999
+ - ربات باید در کانال، **ادمین** باشد
1000
+
1001
+ ---
1002
+
1003
+ ## 💡 نحوه استفاده
1004
+
1005
+ ### کد بهینه‌شده:
1006
+
1007
+ ```python
1008
+ from rubka import Robot
1009
+ from rubka.context import Message
1010
+
1011
+ bot = Robot(token="your_token")
1012
+ CHANNEL_GUID = "c0xABCDEF..." # GUID کانال هدف
1013
+
1014
+ @bot.on_message()
1015
+ def handle_force_join(bot: Robot, message: Message):
1016
+ name = bot.get_name(message.chat_id)
1017
+
1018
+ if bot.check_join(CHANNEL_GUID, message.chat_id):
1019
+ message.reply(f"سلام {name} 👋\nشما عضو کانال هستید ✅")
1020
+ else:
1021
+ join_link = "https://rubika.ir/rubka_library"
1022
+ message.reply(
1023
+ f"سلام {name} 👋\nشما عضو کانال نیستید ❌\n\n"
1024
+ f"لطفاً ابتدا عضو کانال شوید سپس دوباره تلاش کنید:\n{join_link}"
1025
+ )
1026
+
1027
+ bot.run()
1028
+ ```
1029
+
1030
+ ---
1031
+
1032
+ ## 🔍 شرح متدها
1033
+
1034
+ | متد | کاربرد |
1035
+ | ------------------------------------- | ------------------------------------ |
1036
+ | `check_join(channel_guid, user_guid)` | بررسی عضویت کاربر در کانال مشخص‌شده |
1037
+ | `get_name(user_guid)` | دریافت نام نمایشی کاربر از طریق GUID |
1038
+ | `message.reply(text)` | پاسخ مستقیم به پیام دریافت‌شده |
1039
+
1040
+ ---
1041
+
1042
+ ## 🔐 نکات مهم امنیتی
1043
+
1044
+ - ربات باید حتماً **ادمین کانال** باشد.
1045
+ - در صورت عدم عضویت، بهتر است لینک دعوت به کانال نمایش داده شود.
1046
+
1047
+ ##Mahdi Ahmadi