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
rubka/button.py ADDED
@@ -0,0 +1,404 @@
1
+ from typing import Dict
2
+
3
+ from typing import Dict, List, Optional, Union
4
+ from typing import Dict, List, Optional
5
+
6
+ class InlineBuilder:
7
+ def __init__(self):
8
+ self.rows: List[Dict] = []
9
+
10
+ def row(self, *buttons: Dict) -> "InlineBuilder":
11
+ """
12
+ افزودن یک ردیف دکمه به کیبورد
13
+ حداقل یک دکمه باید داده شود.
14
+ """
15
+ if not buttons:
16
+ raise ValueError("حداقل یک دکمه باید به row داده شود")
17
+ self.rows.append({"buttons": list(buttons)})
18
+ return self
19
+ def button_open_chat(self, id: str, text: str, object_guid: str, object_type: str ="User") -> Dict:
20
+ return {
21
+ "id": id,
22
+ "type": 'Link',
23
+ "button_text": text,
24
+ "button_link": {
25
+ "type": 'openchat',
26
+ "open_chat_data": {
27
+ "object_guid": object_guid,
28
+ "object_type": object_type
29
+ }
30
+ }
31
+ }
32
+ def button_join_channel(self, id: str, text: str, username: str, ask_join: bool = False) -> Dict:
33
+ """
34
+ Creates an inline button that prompts the user to join a Rubika channel.
35
+
36
+ Args:
37
+ id (str): Unique identifier for the button (used for event handling).
38
+ text (str): The text displayed on the button.
39
+ username (str): The channel username (can be with or without '@').
40
+ ask_join (bool, optional): If True, the user will be prompted with a
41
+ confirmation dialog before joining.
42
+ Defaults to False.
43
+
44
+ Returns:
45
+ dict: A dictionary representing the inline button, which can be passed
46
+ to inline keyboard builder methods.
47
+
48
+ Example:
49
+ ```python
50
+ from rubka.button import InlineBuilder
51
+
52
+ buttons = (
53
+ InlineBuilder()
54
+ .row(
55
+ InlineBuilder().button_join_channel(
56
+ id="join_btn",
57
+ text="Join our channel 📢",
58
+ username="rubka_library",
59
+ ask_join=True
60
+ )
61
+ )
62
+ .build()
63
+ )
64
+
65
+ await message.reply_inline(
66
+ text="Please join our channel before using the bot.",
67
+ inline_keypad=buttons
68
+ )
69
+ ```
70
+ """
71
+ return {
72
+ "id": id,
73
+ "type": 'Link',
74
+ "button_text": text,
75
+ "button_link": {
76
+ "type": 'joinchannel',
77
+ "joinchannel_data": {
78
+ "username": username.replace("@", ""),
79
+ "ask_join": ask_join
80
+ }
81
+ }
82
+ }
83
+
84
+ def button_url_link(self, id: str, text: str, url: str) -> Dict:
85
+ """
86
+ Creates an inline button that opens a given URL when clicked.
87
+
88
+ Args:
89
+ id (str): Unique identifier for the button (used for event handling if needed).
90
+ text (str): The text displayed on the button.
91
+ url (str): The destination URL that will be opened when the button is clicked.
92
+
93
+ Returns:
94
+ dict: A dictionary representing the inline button, which can be passed
95
+ to inline keyboard builder methods.
96
+
97
+ Example:
98
+ ```python
99
+ from rubka.button import InlineBuilder
100
+
101
+ buttons = (
102
+ InlineBuilder()
103
+ .row(
104
+ InlineBuilder().button_url_link(
105
+ id="website_btn",
106
+ text="Visit our website 🌐",
107
+ url="https://api-free.ir"
108
+ )
109
+ )
110
+ .build()
111
+ )
112
+
113
+ await message.reply_inline(
114
+ text="Click the button below to visit our website.",
115
+ inline_keypad=buttons
116
+ )
117
+ ```
118
+ """
119
+ return {
120
+ "id": id,
121
+ "type": 'Link',
122
+ "button_text": text,
123
+ "button_link": {
124
+ "type": 'url',
125
+ "link_url": url
126
+ }
127
+ }
128
+
129
+ def button_simple(self, id: str, text: str) -> Dict:
130
+ return {"id": id, "type": "Simple", "button_text": text}
131
+
132
+ def button_selection(self, id: str, text: str, selection: Dict) -> Dict:
133
+ """
134
+ selection: dict با فیلدهای:
135
+ - selection_id (str)
136
+ - search_type (str) [ButtonSelectionSearchEnum: None, Local, Api]
137
+ - get_type (str) [ButtonSelectionGetEnum: Local, Api]
138
+ - items (list of ButtonSelectionItem)
139
+ - is_multi_selection (bool)
140
+ - columns_count (str)
141
+ - title (str)
142
+ """
143
+ return {
144
+ "id": id,
145
+ "type": "Selection",
146
+ "button_text": text,
147
+ "button_selection": selection
148
+ }
149
+
150
+ def button_calendar(self, id: str, title: str, type_: str,
151
+ default_value: Optional[str] = None,
152
+ min_year: Optional[str] = None,
153
+ max_year: Optional[str] = None) -> Dict:
154
+ """
155
+ type_: ButtonCalendarTypeEnum = "DatePersian" | "DateGregorian"
156
+ """
157
+ calendar = {
158
+ "title": title,
159
+ "type": type_,
160
+ }
161
+ if default_value:
162
+ calendar["default_value"] = default_value
163
+ if min_year:
164
+ calendar["min_year"] = min_year
165
+ if max_year:
166
+ calendar["max_year"] = max_year
167
+
168
+ return {
169
+ "id": id,
170
+ "type": "Calendar",
171
+ "button_text": title,
172
+ "button_calendar": calendar
173
+ }
174
+
175
+ def button_number_picker(self, id: str, title: str, min_value: str, max_value: str,
176
+ default_value: Optional[str] = None) -> Dict:
177
+ picker = {
178
+ "title": title,
179
+ "min_value": min_value,
180
+ "max_value": max_value,
181
+ }
182
+ if default_value:
183
+ picker["default_value"] = default_value
184
+
185
+ return {
186
+ "id": id,
187
+ "type": "NumberPicker",
188
+ "button_text": title,
189
+ "button_number_picker": picker
190
+ }
191
+
192
+ def button_string_picker(self, id: str, title: Optional[str], items: List[str],
193
+ default_value: Optional[str] = None) -> Dict:
194
+ picker = {
195
+ "items": items
196
+ }
197
+ if default_value:
198
+ picker["default_value"] = default_value
199
+ if title:
200
+ picker["title"] = title
201
+
202
+ return {
203
+ "id": id,
204
+ "type": "StringPicker",
205
+ "button_text": title if title else "انتخاب",
206
+ "button_string_picker": picker
207
+ }
208
+
209
+ def button_location(self, id: str, type_: str, location_image_url: str,
210
+ default_pointer_location: Optional[Dict] = None,
211
+ default_map_location: Optional[Dict] = None,
212
+ title: Optional[str] = None) -> Dict:
213
+ """
214
+ type_: ButtonLocationTypeEnum = "Picker" | "View"
215
+ location_image_url: str آدرس عکس دکمه موقعیت
216
+ default_pointer_location و default_map_location هر کدام دیکشنری Location (latitude, longitude)
217
+ """
218
+ loc = {
219
+ "type": type_,
220
+ "location_image_url": location_image_url,
221
+ }
222
+ if default_pointer_location:
223
+ loc["default_pointer_location"] = default_pointer_location
224
+ if default_map_location:
225
+ loc["default_map_location"] = default_map_location
226
+ if title:
227
+ loc["title"] = title
228
+
229
+ return {
230
+ "id": id,
231
+ "type": "Location",
232
+ "button_text": title if title else "موقعیت مکانی",
233
+ "button_location": loc
234
+ }
235
+
236
+ def button_textbox(self, id: str, title: Optional[str],
237
+ type_line: str, type_keypad: str,
238
+ place_holder: Optional[str] = None,
239
+ default_value: Optional[str] = None) -> Dict:
240
+ """
241
+ type_line: ButtonTextboxTypeLineEnum = "SingleLine" | "MultiLine"
242
+ type_keypad: ButtonTextboxTypeKeypadEnum = "String" | "Number"
243
+ """
244
+ textbox = {
245
+ "type_line": type_line,
246
+ "type_keypad": type_keypad
247
+ }
248
+ if place_holder:
249
+ textbox["place_holder"] = place_holder
250
+ if default_value:
251
+ textbox["default_value"] = default_value
252
+ if title:
253
+ textbox["title"] = title
254
+
255
+ return {
256
+ "id": id,
257
+ "type": "Textbox",
258
+ "button_text": title if title else "متن",
259
+ "button_textbox": textbox
260
+ }
261
+
262
+ def button_payment(self, id: str, title: str, amount: int, description: Optional[str] = None) -> Dict:
263
+ """
264
+ نمونه‌ای ساده برای دکمه پرداخت (مقدار و توضیح دلخواه)
265
+ """
266
+ payment = {
267
+ "title": title,
268
+ "amount": amount
269
+ }
270
+ if description:
271
+ payment["description"] = description
272
+
273
+ return {
274
+ "id": id,
275
+ "type": "Payment",
276
+ "button_text": title,
277
+ "button_payment": payment
278
+ }
279
+
280
+ def button_camera_image(self, id: str, title: str) -> Dict:
281
+ return {
282
+ "id": id,
283
+ "type": "CameraImage",
284
+ "button_text": title
285
+ }
286
+
287
+ def button_camera_video(self, id: str, title: str) -> Dict:
288
+ return {
289
+ "id": id,
290
+ "type": "CameraVideo",
291
+ "button_text": title
292
+ }
293
+
294
+ def button_gallery_image(self, id: str, title: str) -> Dict:
295
+ return {
296
+ "id": id,
297
+ "type": "GalleryImage",
298
+ "button_text": title
299
+ }
300
+
301
+ def button_gallery_video(self, id: str, title: str) -> Dict:
302
+ return {
303
+ "id": id,
304
+ "type": "GalleryVideo",
305
+ "button_text": title
306
+ }
307
+
308
+ def button_file(self, id: str, title: str) -> Dict:
309
+ return {
310
+ "id": id,
311
+ "type": "File",
312
+ "button_text": title
313
+ }
314
+
315
+ def button_audio(self, id: str, title: str) -> Dict:
316
+ return {
317
+ "id": id,
318
+ "type": "Audio",
319
+ "button_text": title
320
+ }
321
+
322
+ def button_record_audio(self, id: str, title: str) -> Dict:
323
+ return {
324
+ "id": id,
325
+ "type": "RecordAudio",
326
+ "button_text": title
327
+ }
328
+
329
+ def button_my_phone_number(self, id: str, title: str) -> Dict:
330
+ return {
331
+ "id": id,
332
+ "type": "MyPhoneNumber",
333
+ "button_text": title
334
+ }
335
+
336
+ def button_my_location(self, id: str, title: str) -> Dict:
337
+ return {
338
+ "id": id,
339
+ "type": "MyLocation",
340
+ "button_text": title
341
+ }
342
+
343
+ def button_link(self, id: str, title: str, url: str) -> Dict:
344
+ return {
345
+ "id": id,
346
+ "type": "Link",
347
+ "button_text": title,
348
+ "url": url
349
+ }
350
+
351
+ def button_ask_my_phone_number(self, id: str, title: str) -> Dict:
352
+ return {
353
+ "id": id,
354
+ "type": "AskMyPhoneNumber",
355
+ "button_text": title
356
+ }
357
+
358
+ def button_ask_location(self, id: str, title: str) -> Dict:
359
+ return {
360
+ "id": id,
361
+ "type": "AskLocation",
362
+ "button_text": title
363
+ }
364
+
365
+ def button_barcode(self, id: str, title: str) -> Dict:
366
+ return {
367
+ "id": id,
368
+ "type": "Barcode",
369
+ "button_text": title
370
+ }
371
+
372
+ def build(self) -> Dict:
373
+ return {"rows": self.rows}
374
+ class ChatKeypadBuilder(InlineBuilder):
375
+ def __init__(self):
376
+ self.rows: List[Dict[str, List[Dict[str, str]]]] = []
377
+
378
+ def row(self, *buttons: Dict[str, str]) -> "ChatKeypadBuilder":
379
+ """
380
+ یک ردیف دکمه به کی‌پد اضافه می‌کند.
381
+ ورودی: چند دیکشنری که نماینده دکمه‌ها هستند.
382
+ """
383
+ self.rows.append({"buttons": list(buttons)})
384
+ return self
385
+
386
+ def button(self, id: str, text: str, type: str = "Simple") -> Dict[str, str]:
387
+ """
388
+ دیکشنری یک دکمه می‌سازد.
389
+ """
390
+ return {"id": id, "type": type, "button_text": text}
391
+
392
+ def build(
393
+ self,
394
+ resize_keyboard: bool = True,
395
+ on_time_keyboard: bool = False
396
+ ) -> Dict[str, object]:
397
+ """
398
+ ساختار نهایی chat_keypad را می‌سازد.
399
+ """
400
+ return {
401
+ "rows": self.rows,
402
+ "resize_keyboard": resize_keyboard,
403
+ "on_time_keyboard": on_time_keyboard
404
+ }
rubka/config.py ADDED
@@ -0,0 +1,3 @@
1
+ API_URL = "https://botapi.rubika.ir/v3"
2
+ REQUEST_TIMEOUT = 10
3
+ MAX_RETRY = 3