RubigramClient 1.6.8__py3-none-any.whl → 1.7.0__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.

Potentially problematic release.


This version of RubigramClient might be problematic. Click here for more details.

rubigram/types.py CHANGED
@@ -1,24 +1,86 @@
1
- from typing import Optional, Union, Any
2
- from pydantic import BaseModel
1
+ from typing import Optional, Union, TypeVar, Type, get_origin, get_args
2
+ from dataclasses import dataclass, fields
3
3
  from rubigram import enums
4
-
5
-
6
- class DataManager(BaseModel):
7
- class Config:
8
- use_enum_values = True
9
- arbitrary_types_allowed = True
4
+ from json import dumps
5
+ import rubigram
6
+
7
+
8
+ T = TypeVar("T", bound="DataManager")
9
+
10
+
11
+ @dataclass
12
+ class DataManager:
13
+
14
+ def asdict(self):
15
+ data = {}
16
+ for field in fields(self):
17
+ if field.name == "client": continue
18
+ value = getattr(self, field.name)
19
+ if isinstance(value, DataManager):
20
+ data[field.name] = value.asdict()
21
+ elif isinstance(value, list):
22
+ data[field.name] = [
23
+ v.asdict() if isinstance(v, DataManager) else v for v in value if v is not None
24
+ ]
25
+ else:
26
+ data[field.name] = value
27
+ return data
28
+
29
+
30
+ def asjson(self, remove_none: Optional[bool] = False):
31
+ def clear(object):
32
+ if isinstance(object, dict):
33
+ return {key: clear(value) for key, value in object.items() if value is not None}
34
+ elif isinstance(object, list):
35
+ return [clear(i) for i in object if i is not None]
36
+ else:
37
+ return object
38
+
39
+ data = self.asdict().copy()
40
+ data.pop("client", None)
41
+ if remove_none:
42
+ data = clear(data)
43
+ return dumps(data, ensure_ascii=False, indent=4)
10
44
 
11
45
  @classmethod
12
- def from_dict(cls, data: dict):
13
- return cls.model_validate(data or {})
14
-
15
- def asdict(self, exclude_none: bool = True) -> dict:
16
- return self.model_dump(exclude_none=exclude_none, exclude={"client"})
17
-
18
- def asjson(self, exclude_none: bool = True) -> str:
19
- return self.model_dump_json(indent=4, exclude_none=exclude_none, exclude={"client"})
20
-
21
-
46
+ def from_dict(cls: Type[T], data: dict) -> T:
47
+ data = data or {}
48
+ init_data = {}
49
+
50
+ for field in fields(cls):
51
+ value = data.get(field.name)
52
+ field_type = field.type
53
+ origin = get_origin(field_type)
54
+
55
+ if isinstance(value, dict) and isinstance(field_type, type) and issubclass(field_type, DataManager):
56
+ init_data[field.name] = field_type.from_dict(value)
57
+
58
+ elif origin == list:
59
+ inner_type = get_args(field_type)[0]
60
+ if isinstance(inner_type, type) and issubclass(inner_type, DataManager):
61
+ init_data[field.name] = [
62
+ inner_type.from_dict(v) if isinstance(v, dict) else v for v in (value or [])
63
+ ]
64
+ else:
65
+ init_data[field.name] = value or []
66
+
67
+ elif origin == Union:
68
+ args = get_args(field_type)
69
+ dict_type = next((
70
+ a for a in args if isinstance(a, type) and issubclass(a, DataManager)
71
+ ), None)
72
+ if dict_type and isinstance(value, dict):
73
+ init_data[field.name] = dict_type.from_dict(value)
74
+ else:
75
+ init_data[field.name] = value
76
+
77
+ else:
78
+ init_data[field.name] = value
79
+
80
+ return cls(**init_data)
81
+
82
+
83
+ @dataclass
22
84
  class Chat(DataManager):
23
85
  chat_id: Optional[str] = None
24
86
  chat_type: Optional[enums.ChatType] = None
@@ -28,106 +90,35 @@ class Chat(DataManager):
28
90
  title: Optional[str] = None
29
91
  username: Optional[str] = None
30
92
 
31
- def __init__(
32
- self,
33
- chat_id: Optional[str] = None,
34
- chat_type: Optional[enums.ChatType] = None,
35
- user_id: Optional[str] = None,
36
- first_name: Optional[str] = None,
37
- last_name: Optional[str] = None,
38
- title: Optional[str] = None,
39
- username: Optional[str] = None,
40
- **kwargs
41
- ):
42
- super().__init__(
43
- chat_id=chat_id,
44
- chat_type=chat_type,
45
- user_id=user_id,
46
- first_name=first_name,
47
- last_name=last_name,
48
- title=title,
49
- username=username,
50
- **kwargs
51
- )
52
-
53
93
 
94
+ @dataclass
54
95
  class File(DataManager):
55
96
  file_id: Optional[str] = None
56
97
  file_name: Optional[str] = None
57
- size: Optional[str] = None
58
-
59
- def __init__(
60
- self,
61
- file_id: Optional[str] = None,
62
- file_name: Optional[str] = None,
63
- size: Optional[str] = None,
64
- **kwargs
65
- ):
66
- super().__init__(
67
- file_id=file_id,
68
- file_name=file_name,
69
- size=size,
70
- **kwargs
71
- )
98
+ size: Optional[int] = None
72
99
 
73
100
 
101
+ @dataclass
74
102
  class ForwardedFrom(DataManager):
75
103
  type_from: Optional[enums.ForwardedFrom] = None
76
104
  message_id: Optional[str] = None
77
105
  from_chat_id: Optional[str] = None
78
106
  from_sender_id: Optional[str] = None
79
107
 
80
- def __init__(
81
- self,
82
- type_from: Optional[enums.ForwardedFrom] = None,
83
- message_id: Optional[str] = None,
84
- from_chat_id: Optional[str] = None,
85
- from_sender_id: Optional[str] = None,
86
- **kwargs
87
- ):
88
- super().__init__(
89
- type_from=type_from,
90
- message_id=message_id,
91
- from_chat_id=from_chat_id,
92
- from_sender_id=from_sender_id,
93
- **kwargs
94
- )
95
-
96
108
 
109
+ @dataclass
97
110
  class PaymentStatus(DataManager):
98
111
  payment_id: Optional[str] = None
99
112
  status: Optional[enums.PaymentStatus] = None
100
113
 
101
- def __init__(
102
- self,
103
- payment_id: Optional[str] = None,
104
- status: Optional[enums.PaymentStatus] = None,
105
- **kwargs
106
- ):
107
- super().__init__(
108
- payment_id=payment_id,
109
- status=status,
110
- **kwargs
111
- )
112
-
113
114
 
115
+ @dataclass
114
116
  class MessageTextUpdate(DataManager):
115
117
  message_id: Optional[str] = None
116
118
  text: Optional[str] = None
117
119
 
118
- def __init__(
119
- self,
120
- message_id: Optional[str] = None,
121
- text: Optional[str] = None,
122
- **kwargs
123
- ):
124
- super().__init__(
125
- message_id=message_id,
126
- text=text,
127
- **kwargs
128
- )
129
-
130
120
 
121
+ @dataclass
131
122
  class Bot(DataManager):
132
123
  bot_id: Optional[str] = None
133
124
  bot_title: Optional[str] = None
@@ -137,86 +128,28 @@ class Bot(DataManager):
137
128
  start_message: Optional[str] = None
138
129
  share_url: Optional[str] = None
139
130
 
140
- def __init__(
141
- self,
142
- bot_id: Optional[str] = None,
143
- bot_title: Optional[str] = None,
144
- avatar: Optional[File] = None,
145
- description: Optional[str] = None,
146
- username: Optional[str] = None,
147
- start_message: Optional[str] = None,
148
- share_url: Optional[str] = None,
149
- **kwargs
150
- ):
151
- super().__init__(
152
- bot_id=bot_id,
153
- bot_title=bot_title,
154
- avatar=avatar,
155
- description=description,
156
- username=username,
157
- start_message=start_message,
158
- share_url=share_url,
159
- **kwargs
160
- )
161
-
162
131
 
132
+ @dataclass
163
133
  class BotCommand(DataManager):
164
134
  command: Optional[str] = None
165
135
  description: Optional[str] = None
166
136
 
167
- def __init__(
168
- self,
169
- command: Optional[str] = None,
170
- description: Optional[str] = None,
171
- **kwargs
172
- ):
173
- super().__init__(
174
- command=command,
175
- description=description,
176
- **kwargs
177
- )
178
-
179
137
 
138
+ @dataclass
180
139
  class Sticker(DataManager):
181
140
  sticker_id: Optional[str] = None
182
141
  file: Optional[File] = None
183
142
  emoji_character: Optional[str] = None
184
143
 
185
- def __init__(
186
- self,
187
- sticker_id: Optional[str] = None,
188
- file: Optional[File] = None,
189
- emoji_character: Optional[str] = None,
190
- **kwargs
191
- ):
192
- super().__init__(
193
- sticker_id=sticker_id,
194
- file=file,
195
- emoji_character=emoji_character,
196
- **kwargs
197
- )
198
-
199
144
 
145
+ @dataclass
200
146
  class ContactMessage(DataManager):
201
147
  phone_number: Optional[str] = None
202
148
  first_name: Optional[str] = None
203
149
  last_name: Optional[str] = None
204
150
 
205
- def __init__(
206
- self,
207
- phone_number: Optional[str] = None,
208
- first_name: Optional[str] = None,
209
- last_name: Optional[str] = None,
210
- **kwargs
211
- ):
212
- super().__init__(
213
- phone_number=phone_number,
214
- first_name=first_name,
215
- last_name=last_name,
216
- **kwargs
217
- )
218
-
219
151
 
152
+ @dataclass
220
153
  class PollStatus(DataManager):
221
154
  state: Optional[enums.PollStatus] = None
222
155
  selection_index: Optional[int] = None
@@ -224,62 +157,21 @@ class PollStatus(DataManager):
224
157
  total_vote: Optional[int] = None
225
158
  show_total_votes: Optional[bool] = None
226
159
 
227
- def __init__(
228
- self,
229
- state: Optional[enums.PollStatus] = None,
230
- selection_index: Optional[int] = None,
231
- percent_vote_options: Optional[list[int]] = None,
232
- total_vote: Optional[int] = None,
233
- show_total_votes: Optional[bool] = None,
234
- **kwargs
235
- ):
236
- super().__init__(
237
- state=state,
238
- selection_index=selection_index,
239
- percent_vote_options=percent_vote_options,
240
- total_vote=total_vote,
241
- show_total_votes=show_total_votes,
242
- **kwargs
243
- )
244
-
245
160
 
161
+ @dataclass
246
162
  class Poll(DataManager):
247
163
  question: Optional[str] = None
248
164
  options: Optional[list[str]] = None
249
165
  poll_status: Optional[PollStatus] = None
250
166
 
251
- def __init__(
252
- self,
253
- question: Optional[str] = None,
254
- options: Optional[list[str]] = None,
255
- poll_status: Optional[PollStatus] = None,
256
- **kwargs
257
- ):
258
- super().__init__(
259
- question=question,
260
- options=options,
261
- poll_status=poll_status,
262
- **kwargs
263
- )
264
-
265
167
 
168
+ @dataclass
266
169
  class Location(DataManager):
267
170
  longitude: Optional[str] = None
268
171
  latitude: Optional[str] = None
269
172
 
270
- def __init__(
271
- self,
272
- longitude: Optional[str] = None,
273
- latitude: Optional[str] = None,
274
- **kwargs
275
- ):
276
- super().__init__(
277
- longitude=longitude,
278
- latitude=latitude,
279
- **kwargs
280
- )
281
-
282
173
 
174
+ @dataclass
283
175
  class LiveLocation(DataManager):
284
176
  start_time: Optional[str] = None
285
177
  live_period: Optional[int] = None
@@ -288,47 +180,15 @@ class LiveLocation(DataManager):
288
180
  status: Optional[enums.LiveLocationStatus] = None
289
181
  last_update_time: Optional[str] = None
290
182
 
291
- def __init__(
292
- self,
293
- start_time: Optional[str] = None,
294
- live_period: Optional[int] = None,
295
- current_location: Optional[Location] = None,
296
- user_id: Optional[str] = None,
297
- status: Optional[enums.LiveLocationStatus] = None,
298
- last_update_time: Optional[str] = None,
299
- **kwargs
300
- ):
301
- super().__init__(
302
- start_time=start_time,
303
- live_period=live_period,
304
- current_location=current_location,
305
- user_id=user_id,
306
- status=status,
307
- last_update_time=last_update_time,
308
- **kwargs
309
- )
310
-
311
183
 
184
+ @dataclass
312
185
  class ButtonSelectionItem(DataManager):
313
186
  text: Optional[str] = None
314
187
  image_url: Optional[str] = None
315
188
  type: Optional[enums.ButtonSelectionType] = None
316
189
 
317
- def __init__(
318
- self,
319
- text: Optional[str] = None,
320
- image_url: Optional[str] = None,
321
- type: Optional[enums.ButtonSelectionType] = None,
322
- **kwargs
323
- ):
324
- super().__init__(
325
- text=text,
326
- image_url=image_url,
327
- type=type,
328
- **kwargs
329
- )
330
-
331
190
 
191
+ @dataclass
332
192
  class ButtonSelection(DataManager):
333
193
  selection_id: Optional[str] = None
334
194
  search_type: Optional[str] = None
@@ -338,29 +198,8 @@ class ButtonSelection(DataManager):
338
198
  columns_count: Optional[str] = None
339
199
  title: Optional[str] = None
340
200
 
341
- def __init__(
342
- self,
343
- selection_id: Optional[str] = None,
344
- search_type: Optional[str] = None,
345
- get_type: Optional[str] = None,
346
- items: Optional[list[ButtonSelectionItem]] = None,
347
- is_multi_selection: Optional[bool] = None,
348
- columns_count: Optional[str] = None,
349
- title: Optional[str] = None,
350
- **kwargs
351
- ):
352
- super().__init__(
353
- selection_id=selection_id,
354
- search_type=search_type,
355
- get_type=get_type,
356
- items=items,
357
- is_multi_selection=is_multi_selection,
358
- columns_count=columns_count,
359
- title=title,
360
- **kwargs
361
- )
362
-
363
201
 
202
+ @dataclass
364
203
  class ButtonCalendar(DataManager):
365
204
  default_value: Optional[str] = None
366
205
  type: Optional[enums.ButtonCalendarType] = None
@@ -368,68 +207,23 @@ class ButtonCalendar(DataManager):
368
207
  max_year: Optional[str] = None
369
208
  title: Optional[str] = None
370
209
 
371
- def __init__(
372
- self,
373
- default_value: Optional[str] = None,
374
- type: Optional[enums.ButtonCalendarType] = None,
375
- min_year: Optional[str] = None,
376
- max_year: Optional[str] = None,
377
- title: Optional[str] = None,
378
- **kwargs
379
- ):
380
- super().__init__(
381
- default_value=default_value,
382
- type=type,
383
- min_year=min_year,
384
- max_year=max_year,
385
- title=title,
386
- **kwargs
387
- )
388
-
389
210
 
211
+ @dataclass
390
212
  class ButtonNumberPicker(DataManager):
391
213
  min_value: Optional[str] = None
392
214
  max_value: Optional[str] = None
393
215
  default_value: Optional[str] = None
394
216
  title: Optional[str] = None
395
217
 
396
- def __init__(
397
- self,
398
- min_value: Optional[str] = None,
399
- max_value: Optional[str] = None,
400
- default_value: Optional[str] = None,
401
- title: Optional[str] = None,
402
- **kwargs
403
- ):
404
- super().__init__(
405
- min_value=min_value,
406
- max_value=max_value,
407
- default_value=default_value,
408
- title=title,
409
- **kwargs
410
- )
411
-
412
218
 
219
+ @dataclass
413
220
  class ButtonStringPicker(DataManager):
414
221
  items: Optional[list[str]] = None
415
222
  default_value: Optional[str] = None
416
223
  title: Optional[str] = None
417
224
 
418
- def __init__(
419
- self,
420
- items: Optional[list[str]] = None,
421
- default_value: Optional[str] = None,
422
- title: Optional[str] = None,
423
- **kwargs
424
- ):
425
- super().__init__(
426
- items=items,
427
- default_value=default_value,
428
- title=title,
429
- **kwargs
430
- )
431
-
432
225
 
226
+ @dataclass
433
227
  class ButtonTextbox(DataManager):
434
228
  type_line: Optional[enums.ButtonTextboxTypeLine] = None
435
229
  type_keypad: Optional[enums.ButtonTextboxTypeKeypad] = None
@@ -437,25 +231,8 @@ class ButtonTextbox(DataManager):
437
231
  title: Optional[str] = None
438
232
  default_value: Optional[str] = None
439
233
 
440
- def __init__(
441
- self,
442
- type_line: Optional[enums.ButtonTextboxTypeLine] = None,
443
- type_keypad: Optional[enums.ButtonTextboxTypeKeypad] = None,
444
- place_holder: Optional[str] = None,
445
- title: Optional[str] = None,
446
- default_value: Optional[str] = None,
447
- **kwargs
448
- ):
449
- super().__init__(
450
- type_line=type_line,
451
- type_keypad=type_keypad,
452
- place_holder=place_holder,
453
- title=title,
454
- default_value=default_value,
455
- **kwargs
456
- )
457
-
458
234
 
235
+ @dataclass
459
236
  class ButtonLocation(DataManager):
460
237
  default_pointer_location: Optional[Location] = None
461
238
  default_map_location: Optional[Location] = None
@@ -463,99 +240,34 @@ class ButtonLocation(DataManager):
463
240
  title: Optional[str] = None
464
241
  location_image_url: Optional[str] = None
465
242
 
466
- def __init__(
467
- self,
468
- default_pointer_location: Optional[Location] = None,
469
- default_map_location: Optional[Location] = None,
470
- type: Optional[enums.ButtonLocationType] = None,
471
- title: Optional[str] = None,
472
- location_image_url: Optional[str] = None,
473
- **kwargs
474
- ):
475
- super().__init__(
476
- default_pointer_location=default_pointer_location,
477
- default_map_location=default_map_location,
478
- type=type,
479
- title=title,
480
- location_image_url=location_image_url,
481
- **kwargs
482
- )
483
-
484
243
 
244
+ @dataclass
485
245
  class OpenChatData(DataManager):
486
246
  object_guid: Optional[str] = None
487
247
  object_type: Optional[enums.ChatType] = None
488
248
 
489
- def __init__(
490
- self,
491
- object_guid: Optional[str] = None,
492
- object_type: Optional[enums.ChatType] = None,
493
- **kwargs
494
- ):
495
- super().__init__(
496
- object_guid=object_guid,
497
- object_type=object_type,
498
- **kwargs
499
- )
500
-
501
249
 
250
+ @dataclass
502
251
  class JoinChannelData(DataManager):
503
252
  username: Optional[str] = None
504
253
  ask_join: bool = False
505
254
 
506
- def __init__(
507
- self,
508
- username: Optional[str] = None,
509
- ask_join: bool = False,
510
- **kwargs
511
- ):
512
- super().__init__(
513
- username=username,
514
- ask_join=ask_join,
515
- **kwargs
516
- )
517
-
518
255
 
256
+ @dataclass
519
257
  class ButtonLink(DataManager):
520
258
  type: Optional[enums.ButtonLinkType] = None
521
259
  link_url: Optional[str] = None
522
260
  joinchannel_data: Optional[JoinChannelData] = None
523
261
  open_chat_data: Optional[OpenChatData] = None
524
262
 
525
- def __init__(
526
- self,
527
- type: Optional[enums.ButtonLinkType] = None,
528
- link_url: Optional[str] = None,
529
- joinchannel_data: Optional[JoinChannelData] = None,
530
- open_chat_data: Optional[OpenChatData] = None,
531
- **kwargs
532
- ):
533
- super().__init__(
534
- type=type,
535
- link_url=link_url,
536
- joinchannel_data=joinchannel_data,
537
- open_chat_data=open_chat_data,
538
- **kwargs
539
- )
540
-
541
263
 
264
+ @dataclass
542
265
  class AuxData(DataManager):
543
266
  start_id: Optional[str] = None
544
267
  button_id: Optional[str] = None
545
268
 
546
- def __init__(
547
- self,
548
- start_id: Optional[str] = None,
549
- button_id: Optional[str] = None,
550
- **kwargs
551
- ):
552
- super().__init__(
553
- start_id=start_id,
554
- button_id=button_id,
555
- **kwargs
556
- )
557
-
558
269
 
270
+ @dataclass
559
271
  class Button(DataManager):
560
272
  id: Optional[str] = None
561
273
  button_text: Optional[str] = None
@@ -568,86 +280,26 @@ class Button(DataManager):
568
280
  button_textbox: Optional[ButtonTextbox] = None
569
281
  button_link: Optional[ButtonLink] = None
570
282
 
571
- def __init__(
572
- self,
573
- id: Optional[str] = None,
574
- button_text: Optional[str] = None,
575
- type: enums.ButtonType = enums.ButtonType.Simple,
576
- button_selection: Optional[ButtonSelection] = None,
577
- button_calendar: Optional[ButtonCalendar] = None,
578
- button_number_picker: Optional[ButtonNumberPicker] = None,
579
- button_string_picker: Optional[ButtonStringPicker] = None,
580
- button_location: Optional[ButtonLocation] = None,
581
- button_textbox: Optional[ButtonTextbox] = None,
582
- button_link: Optional[ButtonLink] = None,
583
- **kwargs
584
- ):
585
- super().__init__(
586
- id=id,
587
- button_text=button_text,
588
- type=type,
589
- button_selection=button_selection,
590
- button_calendar=button_calendar,
591
- button_number_picker=button_number_picker,
592
- button_string_picker=button_string_picker,
593
- button_location=button_location,
594
- button_textbox=button_textbox,
595
- button_link=button_link,
596
- **kwargs
597
- )
598
-
599
283
 
284
+ @dataclass
600
285
  class KeypadRow(DataManager):
601
286
  buttons: list[Button]
602
287
 
603
- def __init__(
604
- self,
605
- buttons: list[Button],
606
- **kwargs
607
- ):
608
- super().__init__(
609
- buttons=buttons,
610
- **kwargs
611
- )
612
-
613
288
 
289
+ @dataclass
614
290
  class Keypad(DataManager):
615
291
  rows: list[KeypadRow]
616
292
  resize_keyboard: bool = True
617
293
  on_time_keyboard: bool = False
618
294
 
619
- def __init__(
620
- self,
621
- rows: list[KeypadRow],
622
- resize_keyboard: bool = True,
623
- on_time_keyboard: bool = False,
624
- **kwargs
625
- ):
626
- super().__init__(
627
- rows=rows,
628
- resize_keyboard=resize_keyboard,
629
- on_time_keyboard=on_time_keyboard,
630
- **kwargs
631
- )
632
-
633
295
 
296
+ @dataclass
634
297
  class MessageKeypadUpdate(DataManager):
635
298
  message_id: Optional[str] = None
636
299
  inline_keypad: Optional[Keypad] = None
637
300
 
638
- def __init__(
639
- self,
640
- message_id: Optional[str] = None,
641
- inline_keypad: Optional[Keypad] = None,
642
- **kwargs
643
- ):
644
- super().__init__(
645
- message_id=message_id,
646
- inline_keypad=inline_keypad,
647
- **kwargs
648
- )
649
-
650
301
 
302
+ @dataclass
651
303
  class Message(DataManager):
652
304
  message_id: Optional[str] = None
653
305
  text: Optional[str] = None
@@ -666,72 +318,17 @@ class Message(DataManager):
666
318
  poll: Optional[Poll] = None
667
319
  live_location: Optional[LiveLocation] = None
668
320
 
669
- def __init__(
670
- self,
671
- message_id: Optional[str] = None,
672
- text: Optional[str] = None,
673
- time: Optional[str] = None,
674
- is_edited: Optional[bool] = None,
675
- sender_type: Optional[enums.MessageSender] = None,
676
- sender_id: Optional[str] = None,
677
- aux_data: Optional[AuxData] = None,
678
- file: Optional[File] = None,
679
- reply_to_message_id: Optional[str] = None,
680
- forwarded_from: Optional[ForwardedFrom] = None,
681
- forwarded_no_link: Optional[str] = None,
682
- location: Optional[Location] = None,
683
- sticker: Optional[Sticker] = None,
684
- contact_message: Optional[ContactMessage] = None,
685
- poll: Optional[Poll] = None,
686
- live_location: Optional[LiveLocation] = None,
687
- **kwargs
688
- ):
689
- super().__init__(
690
- message_id=message_id,
691
- text=text,
692
- time=time,
693
- is_edited=is_edited,
694
- sender_type=sender_type,
695
- sender_id=sender_id,
696
- aux_data=aux_data,
697
- file=file,
698
- reply_to_message_id=reply_to_message_id,
699
- forwarded_from=forwarded_from,
700
- forwarded_no_link=forwarded_no_link,
701
- location=location,
702
- sticker=sticker,
703
- contact_message=contact_message,
704
- poll=poll,
705
- live_location=live_location,
706
- **kwargs
707
- )
708
-
709
321
 
322
+ @dataclass
710
323
  class MessageId(DataManager):
711
324
  message_id: Optional[str] = None
712
325
  file_id: Optional[str] = None
713
326
  chat_id: Optional[str] = None
714
- client: Optional[Any] = None
715
-
716
- def __init__(
717
- self,
718
- message_id: Optional[str] = None,
719
- file_id: Optional[str] = None,
720
- chat_id: Optional[str] = None,
721
- client: Optional[Any] = None,
722
- **kwargs
723
- ):
724
- super().__init__(
725
- message_id=message_id,
726
- file_id=file_id,
727
- chat_id=chat_id,
728
- client=client,
729
- **kwargs
730
- )
327
+ client: Optional["rubigram.Client"] = None
731
328
 
732
329
  async def delete(self):
733
330
  return await self.client.delete_message(self.chat_id, self.message_id)
734
-
331
+
735
332
  async def edit(self, text: Optional[str] = None, inline: Optional[Keypad] = None, keypad: Optional[Keypad] = None):
736
333
  if text:
737
334
  await self.edit_text(text)
@@ -745,7 +342,7 @@ class MessageId(DataManager):
745
342
 
746
343
  async def edit_inline(self, inline: Keypad):
747
344
  return await self.client.edit_message_keypad(self.chat_id, self.message_id, inline)
748
-
345
+
749
346
  async def edit_keypad(self, keypad: Keypad):
750
347
  return await self.client.edit_chat_keypad(self.chat_id, keypad)
751
348
 
@@ -753,34 +350,16 @@ class MessageId(DataManager):
753
350
  return await self.client.forward_message(self.chat_id, self.message_id, chat_id)
754
351
 
755
352
 
353
+ @dataclass
756
354
  class Update(DataManager):
757
- client: Optional[Any] = None
758
355
  type: Optional[enums.UpdateType] = None
759
356
  chat_id: Optional[str] = None
760
357
  removed_message_id: Optional[str] = None
761
358
  new_message: Optional[Message] = None
762
359
  updated_message: Optional[Message] = None
763
360
  updated_payment: Optional[PaymentStatus] = None
361
+ client: Optional["rubigram.Client"] = None
764
362
 
765
- def __init__(
766
- self,
767
- type: Optional[enums.UpdateType] = None,
768
- chat_id: Optional[str] = None,
769
- removed_message_id: Optional[str] = None,
770
- new_message: Optional[Message] = None,
771
- updated_message: Optional[Message] = None,
772
- updated_payment: Optional[PaymentStatus] = None,
773
- **kwargs
774
- ):
775
- super().__init__(
776
- type=type,
777
- chat_id=chat_id,
778
- removed_message_id=removed_message_id,
779
- new_message=new_message,
780
- updated_message=updated_message,
781
- updated_payment=updated_payment,
782
- **kwargs
783
- )
784
363
 
785
364
  async def download(self, file_name: str):
786
365
  return await self.client.download_file(self.new_message.file.file_id, file_name)
@@ -929,8 +508,8 @@ class Update(DataManager):
929
508
  return await self.reply_file(voice, caption, file_name, "Voice", **kwargs)
930
509
 
931
510
 
511
+ @dataclass
932
512
  class InlineMessage(DataManager):
933
- client: Optional[Any] = None
934
513
  sender_id: Optional[str] = None
935
514
  text: Optional[str] = None
936
515
  message_id: Optional[str] = None
@@ -938,42 +517,22 @@ class InlineMessage(DataManager):
938
517
  file: Optional[File] = None
939
518
  location: Optional[Location] = None
940
519
  aux_data: Optional[AuxData] = None
941
-
942
- def __init__(
943
- self,
944
- sender_id: Optional[str] = None,
945
- text: Optional[str] = None,
946
- message_id: Optional[str] = None,
947
- chat_id: Optional[str] = None,
948
- file: Optional[File] = None,
949
- location: Optional[Location] = None,
950
- aux_data: Optional[AuxData] = None,
951
- **kwargs
952
- ):
953
- super().__init__(
954
- sender_id=sender_id,
955
- text=text,
956
- message_id=message_id,
957
- chat_id=chat_id,
958
- file=file,
959
- location=location,
960
- aux_data=aux_data,
961
- **kwargs
962
- )
520
+ client: Optional["rubigram.Client"] = None
963
521
 
964
522
 
523
+ @dataclass
965
524
  class Updates(DataManager):
966
525
  updates: Optional[list[Update]] = None
967
526
  next_offset_id: Optional[str] = None
968
527
 
969
- def __init__(
970
- self,
971
- updates: Optional[list[Update]] = None,
972
- next_offset_id: Optional[str] = None,
973
- **kwargs
974
- ):
975
- super().__init__(
976
- updates=updates,
977
- next_offset_id=next_offset_id,
978
- **kwargs
528
+ @classmethod
529
+ def from_dict(cls, data: dict):
530
+ data = data or {}
531
+ updates_list = data.get("updates") or []
532
+ updates_objects = [
533
+ Update.from_dict(update) if isinstance(update, dict) else update for update in updates_list
534
+ ]
535
+ return cls(
536
+ updates=updates_objects,
537
+ next_offset_id=data.get("next_offset_id")
979
538
  )