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
rubigram/method.py DELETED
@@ -1,354 +0,0 @@
1
- from .network import Network
2
- from rubigram import enums
3
- from typing import Optional, Union
4
- from rubigram.types import Bot, Chat, Keypad, MessageId, Updates, BotCommand
5
-
6
-
7
- class Method(Network):
8
- def __init__(self, token: str):
9
- super().__init__(token)
10
-
11
- def clean_data(self, data: dict):
12
- return {key: value for key, value in data.items() if value is not None}
13
-
14
- async def get_me(self) -> "Bot":
15
- response = await self.request("getMe", {})
16
- return Bot.from_dict(response["bot"])
17
-
18
- async def get_chat(self, chat_id: str) -> "Chat":
19
- response = await self.request("getChat", {"chat_id": chat_id})
20
- return Chat.from_dict(response["chat"])
21
-
22
- async def get_update(self, limit: int = 1, offset_id: Optional[int] = None) -> "Updates":
23
- response = await self.request("getUpdates", {"limit": limit, "offset_id": offset_id})
24
- return Updates.from_dict(response)
25
-
26
- async def get_file(self, file_id: str) -> str:
27
- response = await self.request("getFile", {"file_id": file_id})
28
- return response["download_url"]
29
-
30
- async def set_command(self, commands: list[BotCommand]):
31
- response = await self.request("setCommands", {"bot_commands": [command.asdict() for command in commands]})
32
- return response
33
-
34
- async def update_bot_endpoint(self, url: str, type: enums.UpdateEndpointType):
35
- response = await self.request("updateBotEndpoints", {"url": url, "type": type})
36
- return response
37
-
38
- async def delete_message(self, chat_id: str, message_id: str):
39
- return await self.request("deleteMessage", {"chat_id": chat_id, "message_id": message_id})
40
-
41
- async def remove_chat_keypad(self, chat_id: str):
42
- return await self.request("editChatKeypad", {"chat_id": chat_id, "chat_keypad_type": "Remove"})
43
-
44
- async def edit_chat_keypad(self, chat_id: str, chat_keypad: Keypad):
45
- return await self.request("editChatKeypad", {"chat_id": chat_id, "chat_keypad_type": "New", "chat_keypad": chat_keypad.asdict()})
46
-
47
- async def edit_message_keypad(self, chat_id: str, message_id: str, inline_keypad: Keypad):
48
- return await self.request("editMessageKeypad", {"chat_id": chat_id, "message_id": message_id, "inline_keypad": inline_keypad.asdict()})
49
-
50
- async def edit_message_text(self, chat_id: str, message_id: str, text: str):
51
- return await self.request("editMessageText", {"chat_id": chat_id, "message_id": message_id, "text": text})
52
-
53
- async def edit_message(
54
- self,
55
- chat_id: str,
56
- message_id: str,
57
- text: Optional[str] = None,
58
- chat_keypad: Optional[Keypad] = None,
59
- inline_keypad: Optional[Keypad] = None
60
- ):
61
- if text:
62
- await self.edit_message_text(chat_id, message_id, text)
63
- if chat_keypad:
64
- await self.edit_chat_keypad(chat_id, chat_keypad)
65
- if inline_keypad:
66
- await self.edit_message_keypad(chat_id, message_id, inline_keypad)
67
-
68
- async def forward_message(self, from_chat_id: str, message_id: str, to_chat_id: str, disable_notification: bool = False) -> "MessageId":
69
- data = {"from_chat_id": from_chat_id, "message_id": message_id, "to_chat_id": to_chat_id, "disable_notification": disable_notification}
70
- response = await self.request("forwardMessage", data)
71
- message = MessageId.from_dict(response)
72
- message.chat_id = to_chat_id
73
- message.client = self
74
- return message
75
-
76
- async def send_message(
77
- self,
78
- chat_id: str,
79
- text: str,
80
- chat_keypad: Keypad = None,
81
- inline_keypad: Keypad = None,
82
- chat_keypad_type: Optional[enums.ChatKeypadType] = None,
83
- disable_notification: bool = None,
84
- reply_to_message_id=None
85
- ) -> "MessageId":
86
- data = {
87
- "chat_id": chat_id,
88
- "text": text,
89
- "chat_keypad": chat_keypad.asdict() if chat_keypad else None,
90
- "inline_keypad": inline_keypad.asdict() if inline_keypad else None,
91
- "chat_keypad_type": chat_keypad_type,
92
- "disable_notification": disable_notification,
93
- "reply_to_message_id": reply_to_message_id
94
- }
95
- response = await self.request("sendMessage", self.clean_data(data))
96
- message = MessageId.from_dict(response)
97
- message.chat_id = chat_id
98
- message.client = self
99
- return message
100
-
101
- async def send_poll(
102
- self,
103
- chat_id: str,
104
- question: str,
105
- options: list[str],
106
- chat_keypad: Keypad = None,
107
- inline_keypad: Keypad = None,
108
- chat_keypad_type: Optional[enums.ChatKeypadType] = None,
109
- disable_notification: bool = False,
110
- reply_to_message_id: str = None,
111
- ) -> "MessageId":
112
- data = {
113
- "chat_id": chat_id,
114
- "question": question,
115
- "options": options,
116
- "chat_keypad": chat_keypad.asdict() if chat_keypad else None,
117
- "inline_keypad": inline_keypad.asdict() if inline_keypad else None,
118
- "disable_notification": disable_notification,
119
- "reply_to_message_id": reply_to_message_id,
120
- "chat_keypad_type": chat_keypad_type
121
- }
122
- response = await self.request("sendPoll", self.clean_data(data))
123
- message = MessageId.from_dict(response)
124
- message.chat_id = chat_id
125
- message.client = self
126
- return message
127
-
128
- async def send_location(
129
- self,
130
- chat_id: str,
131
- latitude: str,
132
- longitude: str,
133
- chat_keypad: Keypad = None,
134
- inline_keypad: Keypad = None,
135
- chat_keypad_type: Optional[enums.ChatKeypadType] = None,
136
- disable_notification: bool = False,
137
- reply_to_message_id: str = None,
138
- ) -> "MessageId":
139
- data = {
140
- "chat_id": chat_id,
141
- "latitude": latitude,
142
- "longitude": longitude,
143
- "chat_keypad": chat_keypad.asdict() if chat_keypad else None,
144
- "inline_keypad": inline_keypad.asdict() if inline_keypad else None,
145
- "disable_notification": disable_notification,
146
- "reply_to_message_id": reply_to_message_id,
147
- "chat_keypad_type": chat_keypad_type
148
- }
149
- response = await self.request("sendLocation", self.clean_data(data))
150
- message = MessageId.from_dict(response)
151
- message.chat_id = chat_id
152
- message.client = self
153
- return message
154
-
155
- async def send_contact(
156
- self,
157
- chat_id: str,
158
- first_name: str,
159
- last_name: str,
160
- phone_number: str,
161
- chat_keypad: Keypad = None,
162
- inline_keypad: Keypad = None,
163
- chat_keypad_type: Optional[enums.ChatKeypadType] = None,
164
- disable_notification: bool = False,
165
- reply_to_message_id: str = None,
166
- ) -> "MessageId":
167
- data = {
168
- "chat_id": chat_id,
169
- "first_name": first_name,
170
- "last_name": last_name,
171
- "phone_number": phone_number,
172
- "chat_keypad": chat_keypad.asdict() if chat_keypad else None,
173
- "inline_keypad": inline_keypad.asdict() if inline_keypad else None,
174
- "disable_notification": disable_notification,
175
- "reply_to_message_id": reply_to_message_id,
176
- "chat_keypad_type": chat_keypad_type
177
- }
178
- response = await self.request("sendContact", self.clean_data(data))
179
- message = MessageId.from_dict(response)
180
- message.chat_id = chat_id
181
- message.client = self
182
- return message
183
-
184
- async def send_sticker(
185
- self,
186
- chat_id: str,
187
- sticker_id: str,
188
- chat_keypad: Keypad = None,
189
- inline_keypad: Keypad = None,
190
- chat_keypad_type: Optional[enums.ChatKeypadType] = None,
191
- disable_notification: bool = False,
192
- reply_to_message_id: str = None,
193
- ) -> "MessageId":
194
- data = {
195
- "chat_id": chat_id,
196
- "sticker_id": sticker_id,
197
- "chat_keypad": chat_keypad.asdict() if chat_keypad else None,
198
- "inline_keypad": inline_keypad.asdict() if inline_keypad else None,
199
- "disable_notification": disable_notification,
200
- "reply_to_message_id": reply_to_message_id,
201
- "chat_keypad_type": chat_keypad_type
202
- }
203
- response = await self.request("sendSticker", self.clean_data(data))
204
- message = MessageId.from_dict(response)
205
- message.chat_id = chat_id
206
- message.client = self
207
- return message
208
-
209
- async def request_send_file(self, type: str):
210
- response = await self.request("requestSendFile", {"type": type})
211
- return response["upload_url"]
212
-
213
- async def upload_file(self, file: Union[str, bytes], name: Optional[str] = None, type: str = "File"):
214
- upload_url = await self.request_send_file(type)
215
- response = await self.requestUpload(upload_url, file, name)
216
- return response
217
-
218
- async def download_file(self, file_id: str, filename: Optional[str] = None):
219
- download_url = await self.get_file(file_id)
220
- response = await self.requestDownload(download_url, filename)
221
- return response
222
-
223
- async def send_file(
224
- self,
225
- chat_id: str,
226
- file: Union[str, bytes],
227
- caption: Optional[str] = None,
228
- file_name: Optional[str] = None,
229
- type: enums.FileType = enums.FileType.File,
230
- chat_keypad: Keypad = None,
231
- inline_keypad: Keypad = None,
232
- chat_keypad_type: Optional[enums.ChatKeypadType] = None,
233
- disable_notification: bool = False,
234
- reply_to_message_id: Optional[str] = None,
235
- ) -> "MessageId":
236
- file_id = await self.upload_file(file, file_name, type)
237
-
238
- data = {
239
- "chat_id": chat_id,
240
- "file_id": file_id,
241
- "text": caption,
242
- "chat_keypad": chat_keypad.asdict() if chat_keypad else None,
243
- "inline_keypad": inline_keypad.asdict() if inline_keypad else None,
244
- "disable_notification": disable_notification,
245
- "reply_to_message_id": reply_to_message_id,
246
- "chat_keypad_type": chat_keypad_type,
247
- }
248
- response = await self.request("sendFile", self.clean_data(data))
249
- message = MessageId.from_dict(response)
250
- message.chat_id = chat_id
251
- message.file_id = file_id
252
- message.client = self
253
- return message
254
-
255
-
256
-
257
- async def send_document(self, chat_id: str, document: Union[str, bytes], caption: Optional[str] = None, file_name: Optional[str] = None, **kwargs):
258
- return await self.send_file(chat_id, document, caption, file_name, "File", **kwargs)
259
-
260
- async def send_photo(self, chat_id: str, photo: Union[str, bytes], caption: Optional[str] = None, file_name: Optional[str] = None, **kwargs):
261
- return await self.send_file(chat_id, photo, caption, file_name, "Image", **kwargs)
262
-
263
- async def send_video(self, chat_id: str, video: Union[str, bytes], caption: Optional[str] = None, file_name: Optional[str] = None, **kwargs):
264
- return await self.send_file(chat_id, video, caption, file_name, "Video", **kwargs)
265
-
266
- async def send_gif(self, chat_id: str, gif: Union[str, bytes], caption: Optional[str] = None, file_name: Optional[str] = None, **kwargs):
267
- return await self.send_file(chat_id, gif, caption, file_name, "Gif", **kwargs)
268
-
269
- async def send_music(self, chat_id: str, music: Union[str, bytes], caption: Optional[str] = None, file_name: Optional[str] = None, **kwargs):
270
- return await self.send_file(chat_id, music, caption, file_name, "Music", **kwargs)
271
-
272
- async def send_voice(self, chat_id: str, voice: Union[str, bytes], caption: Optional[str] = None, file_name: Optional[str] = None, **kwargs):
273
- return await self.send_file(chat_id, voice, caption, file_name, "Voice", **kwargs)
274
-
275
- # async def get_messages(self, chat_id: str, message_ids: Optional[list[str]] = None):
276
- # return await self.request("getMessages", {"chat_id": chat_id, "message_ids": message_ids})
277
-
278
- # async def get_bot_command(self):
279
- # return await self.request("getBotCommands", {})
280
-
281
- # async def send_chat_action(self, chat_id: str, action: enums.ChatAction):
282
- # return await self.request("sendChatAction", {"chat_id": chat_id, "action": action})
283
-
284
- # async def set_username(self, username: str):
285
- # return await self.request("setUsername", {"username": username})
286
-
287
- async def get_bot_name(self):
288
- bot = await self.get_me()
289
- return bot.bot_title
290
-
291
- async def get_bot_id(self):
292
- bot = await self.get_me()
293
- return bot.bot_id
294
-
295
- async def get_bot_username(self):
296
- bot = await self.get_me()
297
- return bot.username
298
-
299
- async def get_bot_share_url(self):
300
- bot = await self.get_me()
301
- return bot.share_url
302
-
303
- async def get_bot_descriptionl(self):
304
- bot = await self.get_me()
305
- return bot.description
306
-
307
- async def get_bot_start_messagel(self):
308
- bot = await self.get_me()
309
- return bot.start_message
310
-
311
- # async def pin_message(self):
312
- # return
313
-
314
- # async def unpin_message(self):
315
- # return
316
-
317
- # async def ban_chat_member(self):
318
- # return
319
-
320
- # async def unban_chat_member(self):
321
- # return
322
-
323
- # async def get_chat_member(self):
324
- # return
325
-
326
- # async def copy_message(self):
327
- # return
328
-
329
- # async def edit_message_caption(self):
330
- # return
331
-
332
- # async def get_chat_administrators(self):
333
- # return
334
-
335
- # async def get_chat_member_count(self):
336
- # return
337
-
338
- # async def join_chat(self):
339
- # return
340
-
341
- # async def leave_chat(self):
342
- # return
343
-
344
- # async def set_chat_description(self):
345
- # return
346
-
347
- # async def set_chat_photo(self):
348
- # return
349
-
350
- # async def set_chat_title(self):
351
- # return
352
-
353
- # async def unpin_all_message(self):
354
- # return
rubigram/network.py DELETED
@@ -1,80 +0,0 @@
1
- from aiohttp import ClientSession, FormData
2
- from typing import Any, Optional, Union
3
- from pathlib import Path
4
- from urllib.parse import urlparse
5
- import aiofiles
6
- import os
7
-
8
-
9
- class Network:
10
- def __init__(self, token: str) -> None:
11
- self.token: str = token
12
- self.session: Optional[ClientSession] = None
13
- self.api: str = f"https://botapi.rubika.ir/v3/{token}/"
14
-
15
- async def start(self):
16
- if not self.session:
17
- self.session = ClientSession()
18
-
19
- async def stop(self):
20
- if self.session:
21
- await self.session.close()
22
- self.session = None
23
-
24
- async def __aenter__(self):
25
- await self.start()
26
- return self
27
-
28
- async def __aexit__(self, exc_type, exc_val, exc_tb):
29
- await self.stop()
30
-
31
- async def request(self, method: str, json: dict[str, Any]):
32
- await self.start()
33
- async with self.session.post(self.api + method, json=json) as response:
34
- response.raise_for_status()
35
- data: dict = await response.json()
36
- return data.get("data", {})
37
-
38
- async def getBytes(self, url: str) -> bytes:
39
- await self.start()
40
- async with self.session.get(url) as response:
41
- response.raise_for_status()
42
- return await response.read()
43
-
44
- async def getName(self, url: str) -> str:
45
- parser = urlparse(url)
46
- return os.path.basename(parser.path)
47
-
48
- async def requestUpload(self, upload_url: str, file: Union[str, bytes], name: Optional[str] = None):
49
- data, filename = None, None
50
- if isinstance(file, str):
51
- path = Path(file)
52
-
53
- if path.is_file():
54
- data, filename = path.read_bytes(), name if name else path.name
55
-
56
- elif file.startswith("http"):
57
- data, filename = await self.getBytes(file), name if name else await self.getName(file)
58
-
59
- else:
60
- raise Exception(f"Can't find this file : {file}")
61
-
62
- elif isinstance(file, bytes):
63
- if name:
64
- data, filename = file, name
65
- else:
66
- raise Exception("choice name for bytes file")
67
-
68
- form = FormData()
69
- form.add_field("file", data, filename=filename, content_type="application/octet-stream")
70
- await self.start()
71
- async with self.session.post(upload_url, data=form) as response:
72
- response.raise_for_status()
73
- data: dict = await response.json()
74
- return data.get("data", {})["file_id"]
75
-
76
- async def requestDownload(self, url: str, filename: Optional[str] = None):
77
- file, name = await self.getBytes(url), filename if filename else await self.getName(url)
78
- async with aiofiles.open(name, "wb") as f:
79
- await f.write(file)
80
- return name