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

Files changed (74) hide show
  1. rubigram/__init__.py +1 -5
  2. rubigram/client.py +102 -154
  3. rubigram/enums.py +4 -3
  4. rubigram/filters.py +600 -139
  5. rubigram/handler.py +24 -0
  6. rubigram/http.py +32 -0
  7. rubigram/logger.py +20 -0
  8. rubigram/method/__init__.py +18 -0
  9. rubigram/method/chat/__init__.py +10 -0
  10. rubigram/method/chat/get_chat.py +26 -0
  11. rubigram/method/chat/get_me.py +22 -0
  12. rubigram/method/chat/get_update.py +32 -0
  13. rubigram/method/decorator/__init__.py +19 -0
  14. rubigram/method/decorator/on_delete_message.py +37 -0
  15. rubigram/method/decorator/on_edit_message.py +37 -0
  16. rubigram/method/decorator/on_inline_message.py +40 -0
  17. rubigram/method/decorator/on_message.py +38 -0
  18. rubigram/method/decorator/on_start.py +30 -0
  19. rubigram/method/decorator/on_stop.py +29 -0
  20. rubigram/method/decorator/register.py +43 -0
  21. rubigram/method/file/__init__.py +32 -0
  22. rubigram/method/file/download_file.py +34 -0
  23. rubigram/method/file/get_bytes.py +25 -0
  24. rubigram/method/file/get_file.py +27 -0
  25. rubigram/method/file/get_file_name.py +29 -0
  26. rubigram/method/file/request_download_file.py +35 -0
  27. rubigram/method/file/request_send_file.py +28 -0
  28. rubigram/method/file/request_upload_file.py +62 -0
  29. rubigram/method/file/send_document.py +58 -0
  30. rubigram/method/file/send_file.py +78 -0
  31. rubigram/method/file/send_gif.py +58 -0
  32. rubigram/method/file/send_music.py +58 -0
  33. rubigram/method/file/send_photo.py +58 -0
  34. rubigram/method/file/send_video.py +58 -0
  35. rubigram/method/file/send_voice.py +55 -0
  36. rubigram/method/messages/__init__.py +29 -0
  37. rubigram/method/messages/delete_message.py +50 -0
  38. rubigram/method/messages/edit_chat_keypad.py +34 -0
  39. rubigram/method/messages/edit_message.py +41 -0
  40. rubigram/method/messages/edit_message_keypad.py +38 -0
  41. rubigram/method/messages/edit_message_text.py +34 -0
  42. rubigram/method/messages/forward_message.py +43 -0
  43. rubigram/method/messages/remove_chat_keypad.py +28 -0
  44. rubigram/method/messages/send_contact.py +74 -0
  45. rubigram/method/messages/send_location.py +70 -0
  46. rubigram/method/messages/send_message.py +67 -0
  47. rubigram/method/messages/send_poll.py +71 -0
  48. rubigram/method/messages/send_sticker.py +66 -0
  49. rubigram/method/network/__init__.py +7 -0
  50. rubigram/method/network/request.py +20 -0
  51. rubigram/method/setting/__init__.py +9 -0
  52. rubigram/method/setting/set_command.py +32 -0
  53. rubigram/method/setting/update_bot_endpoint.py +31 -0
  54. rubigram/method/utilities/__init__.py +11 -0
  55. rubigram/method/utilities/dispatch.py +25 -0
  56. rubigram/method/utilities/setup_endpoint.py +16 -0
  57. rubigram/method/utilities/updater.py +17 -0
  58. rubigram/rubino/client.py +16 -130
  59. rubigram/rubino/network.py +121 -0
  60. rubigram/state.py +14 -19
  61. rubigram/types/__init__.py +3 -0
  62. rubigram/types/messages.py +175 -0
  63. rubigram/types/object.py +112 -0
  64. rubigram/types/types.py +211 -0
  65. rubigram/types/updates.py +572 -0
  66. {rubigramclient-1.7.1.dist-info → rubigramclient-1.7.3.dist-info}/METADATA +4 -3
  67. rubigramclient-1.7.3.dist-info/RECORD +71 -0
  68. rubigram/method.py +0 -354
  69. rubigram/network.py +0 -80
  70. rubigram/types.py +0 -538
  71. rubigramclient-1.7.1.dist-info/RECORD +0 -15
  72. {rubigramclient-1.7.1.dist-info → rubigramclient-1.7.3.dist-info}/WHEEL +0 -0
  73. {rubigramclient-1.7.1.dist-info → rubigramclient-1.7.3.dist-info}/licenses/LICENSE +0 -0
  74. {rubigramclient-1.7.1.dist-info → rubigramclient-1.7.3.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,112 @@
1
+ import sys
2
+ from typing import Union, TypeVar, Type, get_origin, get_args, get_type_hints
3
+ from dataclasses import dataclass, fields
4
+ from json import dumps
5
+
6
+ T = TypeVar("T", bound="Object")
7
+
8
+
9
+ @dataclass
10
+ class Object:
11
+
12
+ def asdict(self):
13
+ data = {}
14
+ for f in fields(self):
15
+ value = getattr(self, f.name)
16
+ if isinstance(value, Object):
17
+ inner = value.asdict()
18
+ data[f.name] = {"_": value.__class__.__name__, **inner}
19
+ elif isinstance(value, list):
20
+ data[f.name] = [
21
+ {"_": v.__class__.__name__, **v.asdict()} if isinstance(v, Object) else v for v in value
22
+ ]
23
+ else:
24
+ data[f.name] = value
25
+ return data
26
+
27
+ def jsonify(self, exclude_none: bool = False) -> str:
28
+ def clear(obj):
29
+ if isinstance(obj, dict):
30
+ return {k: clear(v) for k, v in obj.items() if v is not None}
31
+ elif isinstance(obj, list):
32
+ return [clear(i) for i in obj if i is not None]
33
+ else:
34
+ return obj
35
+
36
+ data = self.asdict()
37
+ data.pop("client", None)
38
+ if exclude_none:
39
+ data = clear(data)
40
+ return dumps(
41
+ {"_": self.__class__.__name__, **data},
42
+ ensure_ascii=False,
43
+ indent=4
44
+ )
45
+
46
+ @classmethod
47
+ def parse(cls: Type[T], data: dict) -> T:
48
+ data = data or {}
49
+ init_data = {}
50
+
51
+ try:
52
+ module = sys.modules[cls.__module__]
53
+ type_hints = get_type_hints(
54
+ cls, globalns=module.__dict__, localns=None)
55
+ except Exception:
56
+ type_hints = {}
57
+
58
+ for field in fields(cls):
59
+ raw_value = data.get(field.name)
60
+ if isinstance(raw_value, dict) and "_" in raw_value:
61
+ raw_value = {k: v for k, v in raw_value.items() if k != "_"}
62
+
63
+ field_type = type_hints.get(field.name, field.type)
64
+ origin = get_origin(field_type)
65
+
66
+ if origin is Union:
67
+ args = get_args(field_type)
68
+ non_none_args = [arg for arg in args if arg is not type(None)]
69
+ if len(non_none_args) == 1:
70
+ field_type = non_none_args[0]
71
+ origin = get_origin(field_type)
72
+ else:
73
+ pass
74
+
75
+ if isinstance(raw_value, dict) and isinstance(field_type, type) and issubclass(field_type, Object):
76
+ init_data[field.name] = field_type.parse(raw_value)
77
+
78
+ elif origin == list:
79
+ inner_type = get_args(field_type)[0]
80
+ inner_origin = get_origin(inner_type)
81
+ if inner_origin is Union:
82
+ inner_args = [a for a in get_args(
83
+ inner_type) if a is not type(None)]
84
+ inner_type = inner_args[0] if inner_args else inner_type
85
+
86
+ if isinstance(raw_value, list):
87
+ if isinstance(inner_type, type) and issubclass(inner_type, Object):
88
+ init_data[field.name] = [
89
+ inner_type.parse(v) if isinstance(v, dict) else v for v in raw_value
90
+ ]
91
+ else:
92
+ init_data[field.name] = raw_value
93
+ else:
94
+ init_data[field.name] = [
95
+ ] if raw_value is None else raw_value
96
+
97
+ elif origin is Union:
98
+ args = get_args(field_type)
99
+ obj_arg = next((arg for arg in args if isinstance(
100
+ arg, type) and issubclass(arg, Object)), None)
101
+ if obj_arg and isinstance(raw_value, dict):
102
+ init_data[field.name] = obj_arg.parse(raw_value)
103
+ else:
104
+ init_data[field.name] = raw_value
105
+
106
+ else:
107
+ init_data[field.name] = raw_value
108
+
109
+ return cls(**init_data)
110
+
111
+ def __str__(self):
112
+ return self.jsonify(True)
@@ -0,0 +1,211 @@
1
+ from typing import Optional, Union
2
+ from dataclasses import dataclass, field
3
+ from .. import enums
4
+ from .object import Object
5
+
6
+
7
+ @dataclass
8
+ class Chat(Object):
9
+ chat_id: Optional[str] = None
10
+ chat_type: Optional[enums.ChatType] = None
11
+ user_id: Optional[str] = None
12
+ first_name: Optional[str] = None
13
+ last_name: Optional[str] = None
14
+ title: Optional[str] = None
15
+ username: Optional[str] = None
16
+
17
+
18
+ @dataclass
19
+ class File(Object):
20
+ file_id: Optional[str] = None
21
+ file_name: Optional[str] = None
22
+ size: Optional[int] = None
23
+
24
+
25
+ @dataclass
26
+ class ForwardedFrom(Object):
27
+ type_from: Optional[enums.ForwardedFrom] = None
28
+ message_id: Optional[str] = None
29
+ from_chat_id: Optional[str] = None
30
+ from_sender_id: Optional[str] = None
31
+
32
+
33
+ @dataclass
34
+ class PaymentStatus(Object):
35
+ payment_id: Optional[str] = None
36
+ status: Optional[Union[str, enums.PaymentStatus]] = None
37
+
38
+
39
+ @dataclass
40
+ class Bot(Object):
41
+ bot_id: Optional[str] = None
42
+ bot_title: Optional[str] = None
43
+ avatar: Optional[File] = None
44
+ description: Optional[str] = None
45
+ username: Optional[str] = None
46
+ start_message: Optional[str] = None
47
+ share_url: Optional[str] = None
48
+
49
+
50
+ @dataclass
51
+ class BotCommand(Object):
52
+ command: Optional[str] = None
53
+ description: Optional[str] = None
54
+
55
+
56
+ @dataclass
57
+ class Sticker(Object):
58
+ sticker_id: Optional[str] = None
59
+ file: Optional[File] = None
60
+ emoji_character: Optional[str] = None
61
+
62
+
63
+ @dataclass
64
+ class ContactMessage(Object):
65
+ phone_number: Optional[str] = None
66
+ first_name: Optional[str] = None
67
+ last_name: Optional[str] = None
68
+
69
+
70
+ @dataclass
71
+ class PollStatus(Object):
72
+ state: Optional[Union[str, enums.PollStatus]] = None
73
+ selection_index: Optional[int] = None
74
+ percent_vote_options: Optional[list[int]] = None
75
+ total_vote: Optional[int] = None
76
+ show_total_votes: Optional[bool] = None
77
+
78
+
79
+ @dataclass
80
+ class Poll(Object):
81
+ question: Optional[str] = None
82
+ options: Optional[list[str]] = None
83
+ poll_status: Optional[PollStatus] = None
84
+
85
+
86
+ @dataclass
87
+ class Location(Object):
88
+ longitude: Optional[str] = None
89
+ latitude: Optional[str] = None
90
+
91
+
92
+ @dataclass
93
+ class LiveLocation(Object):
94
+ start_time: Optional[str] = None
95
+ live_period: Optional[int] = None
96
+ current_location: Optional[Location] = None
97
+ user_id: Optional[str] = None
98
+ status: Optional[Union[str, enums.LiveLocationStatus]] = None
99
+ last_update_time: Optional[str] = None
100
+
101
+
102
+ @dataclass
103
+ class ButtonSelectionItem(Object):
104
+ text: Optional[str] = None
105
+ image_url: Optional[str] = None
106
+ type: Optional[Union[str, enums.ButtonSelectionType]] = None
107
+
108
+
109
+ @dataclass
110
+ class ButtonSelection(Object):
111
+ selection_id: Optional[str] = None
112
+ search_type: Optional[str] = None
113
+ get_type: Optional[str] = None
114
+ items: Optional[list[ButtonSelectionItem]] = None
115
+ is_multi_selection: Optional[bool] = None
116
+ columns_count: Optional[str] = None
117
+ title: Optional[str] = None
118
+
119
+
120
+ @dataclass
121
+ class ButtonCalendar(Object):
122
+ default_value: Optional[str] = None
123
+ type: Optional[Union[str, enums.ButtonCalendarType]] = None
124
+ min_year: Optional[str] = None
125
+ max_year: Optional[str] = None
126
+ title: Optional[str] = None
127
+
128
+
129
+ @dataclass
130
+ class ButtonNumberPicker(Object):
131
+ min_value: Optional[str] = None
132
+ max_value: Optional[str] = None
133
+ default_value: Optional[str] = None
134
+ title: Optional[str] = None
135
+
136
+
137
+ @dataclass
138
+ class ButtonStringPicker(Object):
139
+ items: Optional[list[str]] = None
140
+ default_value: Optional[str] = None
141
+ title: Optional[str] = None
142
+
143
+
144
+ @dataclass
145
+ class ButtonTextbox(Object):
146
+ type_line: Optional[Union[str, enums.ButtonTextboxTypeLine]] = None
147
+ type_keypad: Optional[Union[str, enums.ButtonTextboxTypeKeypad]] = None
148
+ place_holder: Optional[str] = None
149
+ title: Optional[str] = None
150
+ default_value: Optional[str] = None
151
+
152
+
153
+ @dataclass
154
+ class ButtonLocation(Object):
155
+ default_pointer_location: Optional[Location] = None
156
+ default_map_location: Optional[Location] = None
157
+ type: Optional[Union[str, enums.ButtonLocationType]] = None
158
+ title: Optional[str] = None
159
+ location_image_url: Optional[str] = None
160
+
161
+
162
+ @dataclass
163
+ class OpenChatData(Object):
164
+ Object_guid: Optional[str] = None
165
+ Object_type: Optional[Union[str, enums.ChatType]] = None
166
+
167
+
168
+ @dataclass
169
+ class JoinChannelData(Object):
170
+ username: Optional[str] = None
171
+ ask_join: bool = False
172
+
173
+
174
+ @dataclass
175
+ class ButtonLink(Object):
176
+ type: Optional[Union[str, enums.ButtonLinkType]] = None
177
+ link_url: Optional[str] = None
178
+ joinchannel_data: Optional[JoinChannelData] = None
179
+ open_chat_data: Optional[OpenChatData] = None
180
+
181
+
182
+ @dataclass
183
+ class AuxData(Object):
184
+ start_id: Optional[str] = None
185
+ button_id: Optional[str] = None
186
+
187
+
188
+ @dataclass
189
+ class Button(Object):
190
+ id: Optional[str] = None
191
+ button_text: Optional[str] = None
192
+ type: Optional[Union[str, enums.ButtonType]] = enums.ButtonType.Simple
193
+ button_selection: Optional[ButtonSelection] = None
194
+ button_calendar: Optional[ButtonCalendar] = None
195
+ button_number_picker: Optional[ButtonNumberPicker] = None
196
+ button_string_picker: Optional[ButtonStringPicker] = None
197
+ button_location: Optional[ButtonLocation] = None
198
+ button_textbox: Optional[ButtonTextbox] = None
199
+ button_link: Optional[ButtonLink] = None
200
+
201
+
202
+ @dataclass
203
+ class KeypadRow(Object):
204
+ buttons: list[Button] = field(default_factory=list)
205
+
206
+
207
+ @dataclass
208
+ class Keypad(Object):
209
+ rows: list[KeypadRow] = field(default_factory=list)
210
+ resize_keyboard: bool = True
211
+ on_time_keyboard: bool = False