RubigramClient 0.1.0__tar.gz
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.
- rubigramclient-0.1.0/LICENSE +0 -0
- rubigramclient-0.1.0/PKG-INFO +11 -0
- rubigramclient-0.1.0/README.md +1 -0
- rubigramclient-0.1.0/RubigramClient.egg-info/PKG-INFO +11 -0
- rubigramclient-0.1.0/RubigramClient.egg-info/SOURCES.txt +11 -0
- rubigramclient-0.1.0/RubigramClient.egg-info/dependency_links.txt +1 -0
- rubigramclient-0.1.0/RubigramClient.egg-info/top_level.txt +2 -0
- rubigramclient-0.1.0/pyproject.toml +17 -0
- rubigramclient-0.1.0/rubigram/__init__.py +3 -0
- rubigramclient-0.1.0/rubigram/client.py +317 -0
- rubigramclient-0.1.0/rubigram/filters.py +50 -0
- rubigramclient-0.1.0/rubigram/types.py +235 -0
- rubigramclient-0.1.0/setup.cfg +4 -0
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: RubigramClient
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python library for connect to Rubika API
|
|
5
|
+
Author-email: Javad RJ <Javad.Py1385@gmail.com>
|
|
6
|
+
Requires-Python: >=3.7
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Dynamic: license-file
|
|
10
|
+
|
|
11
|
+
python -m twine upload -u token -p pypi-AgEIcHlwaS5vcmcCJDM3ZGM2OTFmLWJkNDQtNDRkNy1hOWQ5LWRmNGZlM2Y2NjkwNAACKlszLCI1YzNiYjZiYS01YWEzLTQwZjQtYmQyNC1kMTdiOTg0MjRjNWMiXQAABiCdw4uqs3lDpnGPuPeSZSfYSacF21-SYevphQLzU5G2vg dist/*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
python -m twine upload -u token -p pypi-AgEIcHlwaS5vcmcCJDM3ZGM2OTFmLWJkNDQtNDRkNy1hOWQ5LWRmNGZlM2Y2NjkwNAACKlszLCI1YzNiYjZiYS01YWEzLTQwZjQtYmQyNC1kMTdiOTg0MjRjNWMiXQAABiCdw4uqs3lDpnGPuPeSZSfYSacF21-SYevphQLzU5G2vg dist/*
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: RubigramClient
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python library for connect to Rubika API
|
|
5
|
+
Author-email: Javad RJ <Javad.Py1385@gmail.com>
|
|
6
|
+
Requires-Python: >=3.7
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Dynamic: license-file
|
|
10
|
+
|
|
11
|
+
python -m twine upload -u token -p pypi-AgEIcHlwaS5vcmcCJDM3ZGM2OTFmLWJkNDQtNDRkNy1hOWQ5LWRmNGZlM2Y2NjkwNAACKlszLCI1YzNiYjZiYS01YWEzLTQwZjQtYmQyNC1kMTdiOTg0MjRjNWMiXQAABiCdw4uqs3lDpnGPuPeSZSfYSacF21-SYevphQLzU5G2vg dist/*
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
RubigramClient.egg-info/PKG-INFO
|
|
5
|
+
RubigramClient.egg-info/SOURCES.txt
|
|
6
|
+
RubigramClient.egg-info/dependency_links.txt
|
|
7
|
+
RubigramClient.egg-info/top_level.txt
|
|
8
|
+
rubigram/__init__.py
|
|
9
|
+
rubigram/client.py
|
|
10
|
+
rubigram/filters.py
|
|
11
|
+
rubigram/types.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "RubigramClient"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A Python library for connect to Rubika API"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [
|
|
11
|
+
{ name = "Javad RJ", email = "Javad.Py1385@gmail.com" }
|
|
12
|
+
]
|
|
13
|
+
license = { file = "LICENSE" }
|
|
14
|
+
requires-python = ">=3.7"
|
|
15
|
+
|
|
16
|
+
[tool.setuptools.packages.find]
|
|
17
|
+
where = ["."]
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
from rubigram.types import Message, InlineMessage, MessageId, Chat, Bot
|
|
2
|
+
from aiohttp import ClientSession, FormData, web
|
|
3
|
+
from typing import Literal
|
|
4
|
+
import aiofiles
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Client:
|
|
8
|
+
def __init__(self, token: str, webhook_url: str = "0.0.0.0", port: int = 5000):
|
|
9
|
+
self.token = token
|
|
10
|
+
self.webhook = webhook_url
|
|
11
|
+
self.port = port
|
|
12
|
+
self.messages_handler = []
|
|
13
|
+
self.api = "https://botapi.rubika.ir/v3"
|
|
14
|
+
|
|
15
|
+
async def request(self, method: str, data: dict):
|
|
16
|
+
async with ClientSession() as session:
|
|
17
|
+
async with session.post(f"{self.api}/{self.token}/{method}", json=data) as response:
|
|
18
|
+
return await response.json()
|
|
19
|
+
|
|
20
|
+
def on_message(self, *filters):
|
|
21
|
+
def decorator(func):
|
|
22
|
+
async def wrapped(client, update):
|
|
23
|
+
if all(f(update) for f in filters):
|
|
24
|
+
await func(client, update)
|
|
25
|
+
self.messages_handler.append(wrapped)
|
|
26
|
+
return func
|
|
27
|
+
return decorator
|
|
28
|
+
|
|
29
|
+
async def update(self, data: dict):
|
|
30
|
+
update_object = Message(self, data["update"]) if data.get("update") else InlineMessage(data["inline_message"])
|
|
31
|
+
for handler in self.messages_handler:
|
|
32
|
+
await handler(self, update_object)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
async def get_me(self) -> "Bot":
|
|
36
|
+
response = await self.request("getMe", {})
|
|
37
|
+
return Bot(response["data"]["bot"])
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
async def get_chat(self, chat_id: str) -> "Chat":
|
|
41
|
+
response = await self.request("getChat", {"chat_id": chat_id})
|
|
42
|
+
return Chat(response["data"])
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
async def get_updates(self, limit: int = 1, offset_id: str = None):
|
|
46
|
+
response = await self.request("getUpdates", {"limit": limit, "offset_id": offset_id})
|
|
47
|
+
return response
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
async def set_command(self, commands: list):
|
|
51
|
+
response = await self.request("setCommands", {"bot_commands": commands})
|
|
52
|
+
return response
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
async def update_bot_endpoint(
|
|
56
|
+
self,
|
|
57
|
+
url: str,
|
|
58
|
+
type: Literal["ReceiveUpdate", "ReceiveInlineMessage", "ReceiveQuery", "GetSelectionItem", "SearchSelectionItems"]
|
|
59
|
+
):
|
|
60
|
+
response = await self.request("updateBotEndpoints", {"url": url, "type": type})
|
|
61
|
+
return response
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
async def send_message(
|
|
65
|
+
self,
|
|
66
|
+
chat_id: str,
|
|
67
|
+
text: str,
|
|
68
|
+
chat_keypad = None, # مشخص کردن تایپ
|
|
69
|
+
inline_keypad = None, # مشخص کردن تایپ
|
|
70
|
+
chat_keypad_type: Literal["New", "Remove"] = None,
|
|
71
|
+
disable_notification: bool = None,
|
|
72
|
+
reply_to_message_id = None
|
|
73
|
+
) -> "MessageId":
|
|
74
|
+
data = {
|
|
75
|
+
"chat_id": chat_id,
|
|
76
|
+
"text": text,
|
|
77
|
+
"chat_keypad": chat_keypad,
|
|
78
|
+
"inline_keypad": inline_keypad,
|
|
79
|
+
"chat_keypad_type": chat_keypad_type,
|
|
80
|
+
"disable_notification": disable_notification,
|
|
81
|
+
"reply_to_message_id": reply_to_message_id
|
|
82
|
+
}
|
|
83
|
+
response = await self.request("sendMessage", data)
|
|
84
|
+
return MessageId(response["data"])
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
async def send_poll(
|
|
88
|
+
self,
|
|
89
|
+
chat_id: str,
|
|
90
|
+
question: str,
|
|
91
|
+
options: list[str],
|
|
92
|
+
chat_keypad = None, # مشخص کردن تایپ
|
|
93
|
+
inline_keypad = None, # مشخص کردن تایپ
|
|
94
|
+
disable_notification: bool = False,
|
|
95
|
+
reply_to_message_id: str = None,
|
|
96
|
+
chat_keypad_type: Literal[None, "New", "Remove"] = None
|
|
97
|
+
) -> "MessageId":
|
|
98
|
+
data = {
|
|
99
|
+
"chat_id": chat_id,
|
|
100
|
+
"question": question,
|
|
101
|
+
"options": options,
|
|
102
|
+
"chat_keypad": chat_keypad,
|
|
103
|
+
"inline_keypad": inline_keypad,
|
|
104
|
+
"disable_notification": disable_notification,
|
|
105
|
+
"reply_to_message_id": reply_to_message_id,
|
|
106
|
+
"chat_keypad_type": chat_keypad_type
|
|
107
|
+
}
|
|
108
|
+
response = await self.request("sendPoll", data)
|
|
109
|
+
return MessageId(response["data"])
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
async def send_location(
|
|
113
|
+
self,
|
|
114
|
+
chat_id: str,
|
|
115
|
+
latitude: str,
|
|
116
|
+
longitude: str,
|
|
117
|
+
chat_keypad = None, # مشخص کردن تایپ
|
|
118
|
+
inline_keypad = None, # مشخص کردن تایپ
|
|
119
|
+
disable_notification: bool = False,
|
|
120
|
+
reply_to_message_id: str = None,
|
|
121
|
+
chat_keypad_type: Literal[None, "New", "Remove"] = None
|
|
122
|
+
) -> "MessageId":
|
|
123
|
+
data = {
|
|
124
|
+
"chat_id": chat_id,
|
|
125
|
+
"latitude": latitude,
|
|
126
|
+
"longitude": longitude,
|
|
127
|
+
"chat_keypad": chat_keypad,
|
|
128
|
+
"inline_keypad": inline_keypad,
|
|
129
|
+
"disable_notification": disable_notification,
|
|
130
|
+
"reply_to_message_id": reply_to_message_id,
|
|
131
|
+
"chat_keypad_type": chat_keypad_type
|
|
132
|
+
}
|
|
133
|
+
response = await self.request("sendLocation", data)
|
|
134
|
+
return MessageId(response["data"])
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
async def send_contact(
|
|
138
|
+
self,
|
|
139
|
+
chat_id: str,
|
|
140
|
+
first_name: str,
|
|
141
|
+
last_name: str,
|
|
142
|
+
phone_number: str,
|
|
143
|
+
chat_keypad = None, # مشخص کردن تایپ
|
|
144
|
+
inline_keypad = None, # مشخص کردن تایپ
|
|
145
|
+
disable_notification: bool = False,
|
|
146
|
+
reply_to_message_id: str = None,
|
|
147
|
+
chat_keypad_type: Literal[None, "New", "Remove"] = None
|
|
148
|
+
) -> "MessageId":
|
|
149
|
+
data = {
|
|
150
|
+
"chat_id": chat_id,
|
|
151
|
+
"first_name": first_name,
|
|
152
|
+
"last_name": last_name,
|
|
153
|
+
"phone_number": phone_number,
|
|
154
|
+
"chat_keypad": chat_keypad,
|
|
155
|
+
"inline_keypad": inline_keypad,
|
|
156
|
+
"disable_notification": disable_notification,
|
|
157
|
+
"reply_to_message_id": reply_to_message_id,
|
|
158
|
+
"chat_keypad_type": chat_keypad_type
|
|
159
|
+
}
|
|
160
|
+
response = await self.request("sendContact", data)
|
|
161
|
+
return MessageId(response["data"])
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
async def send_sticker(
|
|
165
|
+
self,
|
|
166
|
+
chat_id: str,
|
|
167
|
+
sticker_id: str,
|
|
168
|
+
chat_keypad = None, # مشخص کردن تایپ
|
|
169
|
+
inline_keypad = None, # مشخص کردن تایپ
|
|
170
|
+
disable_notification: bool = False,
|
|
171
|
+
reply_to_message_id: str = None,
|
|
172
|
+
chat_keypad_type: Literal[None, "New", "Remove"] = None,
|
|
173
|
+
) -> "MessageId":
|
|
174
|
+
data = {
|
|
175
|
+
"chat_id": chat_id,
|
|
176
|
+
"sticker_id": sticker_id,
|
|
177
|
+
"chat_keypad": chat_keypad,
|
|
178
|
+
"disable_notification": disable_notification,
|
|
179
|
+
"inline_keypad": inline_keypad,
|
|
180
|
+
"reply_to_message_id": reply_to_message_id,
|
|
181
|
+
"chat_keypad_type": chat_keypad_type
|
|
182
|
+
}
|
|
183
|
+
response = await self.request("sendSticker", data)
|
|
184
|
+
return MessageId(response["data"])
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
async def forward_message(
|
|
188
|
+
self,
|
|
189
|
+
from_chat_id: str,
|
|
190
|
+
message_id: str,
|
|
191
|
+
to_chat_id: str,
|
|
192
|
+
disable_notification: bool = False
|
|
193
|
+
) -> "MessageId":
|
|
194
|
+
data = {
|
|
195
|
+
"from_chat_id": from_chat_id,
|
|
196
|
+
"message_id": message_id,
|
|
197
|
+
"to_chat_id": to_chat_id,
|
|
198
|
+
"disable_notification": disable_notification
|
|
199
|
+
}
|
|
200
|
+
response = await self.request("forwardMessage", data)
|
|
201
|
+
return MessageId(response["data"])
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
async def edit_message_text(
|
|
205
|
+
self,
|
|
206
|
+
chat_id: str,
|
|
207
|
+
message_id: str,
|
|
208
|
+
text: str
|
|
209
|
+
) -> None:
|
|
210
|
+
data = {"chat_id": chat_id, "message_id": message_id, "text": text}
|
|
211
|
+
await self.request("editMessageText", data)
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
async def edit_message_keypad(
|
|
215
|
+
self,
|
|
216
|
+
chat_id: str,
|
|
217
|
+
message_id: str,
|
|
218
|
+
inline_keypad # مشخص کردن تایپ
|
|
219
|
+
) -> None:
|
|
220
|
+
data = {"chat_id": chat_id, "message_id": message_id, "inline_keypad": inline_keypad}
|
|
221
|
+
await self.request("editMessageKeypad", data)
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
async def edit_chat_keypad(
|
|
225
|
+
self,
|
|
226
|
+
chat_id: str,
|
|
227
|
+
chat_keypad # مشخص کردن تایپ
|
|
228
|
+
) -> None:
|
|
229
|
+
data = {"chat_id": chat_id, "chat_keypad_type": "New", "chat_keypad": chat_keypad}
|
|
230
|
+
await self.request("editChatKeypad", data)
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
async def remove_chat_keypad(
|
|
234
|
+
self,
|
|
235
|
+
chat_id: str
|
|
236
|
+
) -> None:
|
|
237
|
+
data = {"chat_id": chat_id, "chat_keypad_type": "Remove"}
|
|
238
|
+
await self.request("editChatKeypad", data)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
async def delete_message(
|
|
242
|
+
self,
|
|
243
|
+
chat_id: str,
|
|
244
|
+
message_id: str
|
|
245
|
+
) -> None:
|
|
246
|
+
data = {"chat_id": chat_id, "message_id": message_id}
|
|
247
|
+
await self.request("deleteMessage", data)
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
async def get_file(self, file_id: str) -> str:
|
|
251
|
+
response = await self.request("getFile", {"file_id": file_id})
|
|
252
|
+
return response["data"]["download_url"]
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
async def request_send_file(self, type: Literal["File", "Image", "Voice", "Music", "Gif", "Video"]) -> str:
|
|
256
|
+
response = await self.request("requestSendFile", {"type": type})
|
|
257
|
+
return response["data"]["upload_url"]
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
async def upload_file(self, path: str, file_name: str, type: Literal["File", "Image", "Voice", "Music", "Gif", "Video"]) -> str:
|
|
261
|
+
upload_url = await self.request_send_file(type)
|
|
262
|
+
form = FormData()
|
|
263
|
+
form.add_field("file", open(path, "rb"), filename=file_name, content_type="application/octet-stream")
|
|
264
|
+
async with ClientSession() as session:
|
|
265
|
+
async with session.post(upload_url, data=form) as response:
|
|
266
|
+
result = await response.json()
|
|
267
|
+
return result["data"]["file_id"]
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
async def send_file(
|
|
271
|
+
self,
|
|
272
|
+
chat_id: str,
|
|
273
|
+
path: str,
|
|
274
|
+
file_name: str,
|
|
275
|
+
type: Literal["File", "Image", "Voice", "Music", "Gif", "Video"] = "File",
|
|
276
|
+
chat_keypad = None,
|
|
277
|
+
inline_keypad = None,
|
|
278
|
+
disable_notification: bool = False,
|
|
279
|
+
reply_to_message_id: str = None,
|
|
280
|
+
chat_keypad_type: Literal["New", "Remove"] = None,
|
|
281
|
+
) -> str:
|
|
282
|
+
file_id = await self.upload_file(path, file_name, type)
|
|
283
|
+
data = {
|
|
284
|
+
"chat_id": chat_id,
|
|
285
|
+
"file_id": file_id,
|
|
286
|
+
"chat_keypad": chat_keypad,
|
|
287
|
+
"disable_notification": disable_notification,
|
|
288
|
+
"inline_keypad": inline_keypad,
|
|
289
|
+
"reply_to_message_id": reply_to_message_id,
|
|
290
|
+
"chat_keypad_type": chat_keypad_type,
|
|
291
|
+
}
|
|
292
|
+
response = await self.request("sendFile", data)
|
|
293
|
+
return MessageId(response["data"])
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
async def download_file(self, file_id: str, file_name: str):
|
|
297
|
+
download_url = await self.get_file(file_id)
|
|
298
|
+
async with ClientSession() as session:
|
|
299
|
+
async with session.get(download_url) as response:
|
|
300
|
+
if response.status == 200:
|
|
301
|
+
async with aiofiles.open(file_name, "wb") as file:
|
|
302
|
+
await file.write(await response.read())
|
|
303
|
+
return {"status": "OK", "file": file_name}
|
|
304
|
+
raise Exception(f"Download Error | status_code : {response.status}")
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def run(self):
|
|
308
|
+
routes = web.RouteTableDef()
|
|
309
|
+
@routes.post("/receiveUpdate")
|
|
310
|
+
@routes.post("/receiveInlineMessage")
|
|
311
|
+
async def webhook(request):
|
|
312
|
+
data = await request.json()
|
|
313
|
+
await self.update(data)
|
|
314
|
+
return web.json_response({"status": "ok"})
|
|
315
|
+
app = web.Application()
|
|
316
|
+
app.add_routes(routes)
|
|
317
|
+
web.run_app(app, host=self.webhook, port=self.port)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from rubigram.types import Message
|
|
2
|
+
from typing import Union
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class filter:
|
|
6
|
+
@staticmethod
|
|
7
|
+
def text():
|
|
8
|
+
def inner(update: Message):
|
|
9
|
+
return update.new_message.text
|
|
10
|
+
return inner
|
|
11
|
+
|
|
12
|
+
@staticmethod
|
|
13
|
+
def private():
|
|
14
|
+
def inner(update: Message):
|
|
15
|
+
return update.new_message.sender_type == "User"
|
|
16
|
+
return inner
|
|
17
|
+
|
|
18
|
+
@staticmethod
|
|
19
|
+
def command(cmd: Union[str, list[str]]):
|
|
20
|
+
def inner(update: Message):
|
|
21
|
+
if not update.new_message.text:
|
|
22
|
+
return False
|
|
23
|
+
if not update.new_message.text.startswith("/"):
|
|
24
|
+
return False
|
|
25
|
+
return update.new_message.text.lstrip("/").split()[0] == cmd
|
|
26
|
+
return inner
|
|
27
|
+
|
|
28
|
+
@staticmethod
|
|
29
|
+
def text_filter(text: str):
|
|
30
|
+
def inner(update: Message):
|
|
31
|
+
return update.new_message.text == text if update.new_message.text else False
|
|
32
|
+
return inner
|
|
33
|
+
|
|
34
|
+
@staticmethod
|
|
35
|
+
def chat(chat_id: str):
|
|
36
|
+
def inner(update: Message):
|
|
37
|
+
return update.chat_id == chat_id
|
|
38
|
+
return inner
|
|
39
|
+
|
|
40
|
+
@staticmethod
|
|
41
|
+
def file():
|
|
42
|
+
def inner(update: Message):
|
|
43
|
+
return update.new_message.file
|
|
44
|
+
return inner
|
|
45
|
+
|
|
46
|
+
@staticmethod
|
|
47
|
+
def button(id: str):
|
|
48
|
+
def inner(update: Message):
|
|
49
|
+
return update.new_message.aux_data.button_id == id if update.new_message.aux_data else False
|
|
50
|
+
return inner
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import rubigram
|
|
2
|
+
from typing import Literal
|
|
3
|
+
from json import dumps
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ForwardFrom:
|
|
8
|
+
def __init__(self, data: dict):
|
|
9
|
+
self.type_from: str = data["type_from"]
|
|
10
|
+
self.message_id: str = data["message_id"]
|
|
11
|
+
self.from_sender_id: str = data.get("from_sender_id")
|
|
12
|
+
self.from_chat_id: str = data.get("from_chat_id")
|
|
13
|
+
|
|
14
|
+
def _dict(self):
|
|
15
|
+
return {
|
|
16
|
+
"type_from": self.type_from,
|
|
17
|
+
"message_id": self.message_id,
|
|
18
|
+
"from_sender_id": self.from_sender_id,
|
|
19
|
+
"from_chat_id": self.from_chat_id
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
def __str__(self):
|
|
23
|
+
return dumps(self._dict(), indent=4, ensure_ascii=False)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class File:
|
|
27
|
+
def __init__(self, data: dict):
|
|
28
|
+
self.file_id: str = data["file_id"]
|
|
29
|
+
self.file_name: str = data.get("file_name")
|
|
30
|
+
self.size: int = data.get("size")
|
|
31
|
+
|
|
32
|
+
def _dict(self):
|
|
33
|
+
return {"file_id": self.file_id, "file_name": self.file_name, "size": self.size}
|
|
34
|
+
|
|
35
|
+
def __str__(self):
|
|
36
|
+
return dumps(self._dict(), indent=4, ensure_ascii=False)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class Location:
|
|
40
|
+
def __init__(self, data: dict):
|
|
41
|
+
self.longitude: int = data["longitude"]
|
|
42
|
+
self.latitude: int = data["latitude"]
|
|
43
|
+
|
|
44
|
+
def _dict(self):
|
|
45
|
+
return {"longitude": self.longitude, "latitude": self.latitude}
|
|
46
|
+
|
|
47
|
+
def __str__(self):
|
|
48
|
+
return dumps(self._dict(), indent=4, ensure_ascii=False)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class AuxData:
|
|
52
|
+
def __init__(self, data: dict):
|
|
53
|
+
self.start_id = data.get("start_id")
|
|
54
|
+
self.button_id: str = data.get("button_id")
|
|
55
|
+
|
|
56
|
+
def _dict(self):
|
|
57
|
+
return {"start_id": self.start_id, "button_id": self.button_id}
|
|
58
|
+
|
|
59
|
+
def __str__(self):
|
|
60
|
+
return dumps(self._dict(), indent=4, ensure_ascii=False)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class MessageId:
|
|
64
|
+
def __init__(self, data: dict):
|
|
65
|
+
self.message_id = data["message_id"]
|
|
66
|
+
|
|
67
|
+
def _dict(self):
|
|
68
|
+
return {"message_id": self.message_id}
|
|
69
|
+
|
|
70
|
+
def __str__(self):
|
|
71
|
+
return dumps(self._dict(), indent=4, ensure_ascii=False)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class UpdateMessage:
|
|
75
|
+
def __init__(self, data: dict):
|
|
76
|
+
self.message_id: str = data["message_id"]
|
|
77
|
+
self.text: str = data["text"]
|
|
78
|
+
self.time: str = data["time"]
|
|
79
|
+
self.is_edited: bool = data["is_edited"]
|
|
80
|
+
self.sender_type: str = data["sender_type"]
|
|
81
|
+
self.sender_id: str = data["sender_id"]
|
|
82
|
+
|
|
83
|
+
def _dict(self):
|
|
84
|
+
return {
|
|
85
|
+
"message_id": self.message_id,
|
|
86
|
+
"text": self.text,
|
|
87
|
+
"time": self.time,
|
|
88
|
+
"is_edited": self.is_edited,
|
|
89
|
+
"sender_type": self.sender_type,
|
|
90
|
+
"sender_id": self.sender_id
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
def __str__(self):
|
|
94
|
+
return dumps(self._dict(), indent=4, ensure_ascii=False)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class NewMessage:
|
|
98
|
+
def __init__(self, data: dict):
|
|
99
|
+
self.message_id: str = data["message_id"]
|
|
100
|
+
self.time: str = data["time"]
|
|
101
|
+
self.is_edited: bool = data["is_edited"]
|
|
102
|
+
self.sender_type: str = data["sender_type"]
|
|
103
|
+
self.sender_id: str = data["sender_id"]
|
|
104
|
+
self.text: str = data.get("text")
|
|
105
|
+
self.forwarded_from: ForwardFrom = ForwardFrom(data["forwarded_from"]) if data.get("forwarded_from") else None
|
|
106
|
+
self.file: File = File(data["file"]) if data.get("file") else None
|
|
107
|
+
self.location: Location = Location(data["location"]) if data.get("location") else None
|
|
108
|
+
self.aux_data: AuxData = AuxData(data["aux_data"]) if data.get("aux_data") else None
|
|
109
|
+
|
|
110
|
+
def _dict(self):
|
|
111
|
+
return {
|
|
112
|
+
"message_id": self.message_id,
|
|
113
|
+
"time": self.time,
|
|
114
|
+
"is_edited": self.is_edited,
|
|
115
|
+
"sender_type": self.sender_type,
|
|
116
|
+
"sender_id": self.sender_id,
|
|
117
|
+
"text": self.text,
|
|
118
|
+
"forwarded_from": self.forwarded_from._dict() if self.forwarded_from else None,
|
|
119
|
+
"file": self.file._dict() if self.file else None,
|
|
120
|
+
"location": self.location._dict() if self.location else None,
|
|
121
|
+
"aux_data": self.aux_data._dict() if self.aux_data else None
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
def __str__(self):
|
|
125
|
+
return dumps(self._dict(), indent=4, ensure_ascii=False)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
class InlineMessage:
|
|
129
|
+
def __init__(self, data: dict):
|
|
130
|
+
self.message_id: str = data["message_id"]
|
|
131
|
+
self.chat_id: str = data["chat_id"]
|
|
132
|
+
self.sender_id: str = data["sender_id"]
|
|
133
|
+
self.text: str = data["text"]
|
|
134
|
+
self.aux_data: AuxData = AuxData(data["aux_data"])
|
|
135
|
+
self.location: Location = Location(data["location"]) if data.get("location") else None
|
|
136
|
+
|
|
137
|
+
def _dict(self):
|
|
138
|
+
return {
|
|
139
|
+
"message_id": self.message_id,
|
|
140
|
+
"chat_id": self.chat_id,
|
|
141
|
+
"sender_id": self.sender_id,
|
|
142
|
+
"text": self.text,
|
|
143
|
+
"aux_data": self.aux_data._dict() if self.aux_data else None,
|
|
144
|
+
"location":self.location._dict() if self.location else None
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
def __str__(self):
|
|
148
|
+
return dumps(self._dict(), indent=4, ensure_ascii=False)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
class Bot:
|
|
152
|
+
def __init__(self, data: dict):
|
|
153
|
+
self.bot_id: str = data["bot_id"]
|
|
154
|
+
self.bot_title: str = data["bot_title"]
|
|
155
|
+
self.username: str = data["username"]
|
|
156
|
+
self.start_message: str = data["start_message"]
|
|
157
|
+
self.share_url: str = data["share_url"]
|
|
158
|
+
self.description: str = data["description"]
|
|
159
|
+
self.avatar: File = File(data["avatar"]) if data.get("avatar") else None
|
|
160
|
+
|
|
161
|
+
def _dict(self):
|
|
162
|
+
return {
|
|
163
|
+
"bot_id": self.bot_id,
|
|
164
|
+
"bot_title": self.bot_title,
|
|
165
|
+
"username": self.username,
|
|
166
|
+
"start_message": self.start_message,
|
|
167
|
+
"share_url": self.share_url,
|
|
168
|
+
"description": self.description,
|
|
169
|
+
"avatar": self.avatar._dict() if self.avatar else None
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
def __str__(self):
|
|
173
|
+
return dumps(self._dict(), indent=4, ensure_ascii=False)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
class Chat:
|
|
177
|
+
def __init__(self, data: dict):
|
|
178
|
+
self.chat_id: str = data["chat_id"]
|
|
179
|
+
self.chat_type: str = data["chat_type"]
|
|
180
|
+
self.user_id: str = data.get("user_id")
|
|
181
|
+
self.first_name: str = data.get("first_name")
|
|
182
|
+
self.last_name: str = data.get("last_name")
|
|
183
|
+
self.title: str = data.get("title")
|
|
184
|
+
self.username: str = data.get("username")
|
|
185
|
+
|
|
186
|
+
def _dict(self):
|
|
187
|
+
return {
|
|
188
|
+
"chat_id": self.chat_id,
|
|
189
|
+
"chat_type": self.chat_type,
|
|
190
|
+
"user_id": self.user_id,
|
|
191
|
+
"first_name": self.first_name,
|
|
192
|
+
"last_name": self.last_name,
|
|
193
|
+
"title" : self.title,
|
|
194
|
+
"username": self.username
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
def __str__(self):
|
|
198
|
+
return dumps(self._dict(), indent=4, ensure_ascii=False)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
class Message:
|
|
202
|
+
def __init__(self, client: "rubigram.Client", data: dict):
|
|
203
|
+
# Message Update Type : ["NewMessage", "UpdatedMessage", "RemovedMessage", "StartedBot", "StoppedBot"و "UpdatedPayment"]
|
|
204
|
+
self.client = client
|
|
205
|
+
self.type: str = data["type"]
|
|
206
|
+
self.chat_id: str = data["chat_id"]
|
|
207
|
+
self.new_message: NewMessage = NewMessage(data.get("new_message")) if data.get("new_message") else None
|
|
208
|
+
self.removed_message_id: int = data.get("removed_message_id")
|
|
209
|
+
self.updated_message: UpdateMessage = UpdateMessage(data.get("updated_message")) if data.get("updated_message") else None
|
|
210
|
+
|
|
211
|
+
def _dict(self):
|
|
212
|
+
return {
|
|
213
|
+
"type": self.type,
|
|
214
|
+
"chat_id": self.chat_id,
|
|
215
|
+
"new_message": self.new_message._dict() if self.new_message else None,
|
|
216
|
+
"removed_message_id" : self.removed_message_id,
|
|
217
|
+
"updated_message": self.updated_message._dict() if self.updated_message else None
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
def __str__(self):
|
|
221
|
+
return dumps(self._dict(), indent=4, ensure_ascii=False)
|
|
222
|
+
|
|
223
|
+
async def reply_text(self, text: str):
|
|
224
|
+
return await self.client.send_message(self.chat_id, text, reply_to_message_id=self.new_message.message_id)
|
|
225
|
+
|
|
226
|
+
async def reply_file(
|
|
227
|
+
self,
|
|
228
|
+
path: str,
|
|
229
|
+
file_name: str,
|
|
230
|
+
type: Literal["File", "Image", "Voice", "Music", "Gif", "Video"] = "File"
|
|
231
|
+
):
|
|
232
|
+
return await self.client.send_file(self.chat_id, path, file_name, type)
|
|
233
|
+
|
|
234
|
+
async def download(self, file_name: str):
|
|
235
|
+
return await self.client.download_file(self.new_message.file.file_id, file_name)
|