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