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/client.py +37 -1
- rubigram/enums.py +1 -3
- rubigram/filters.py +9 -7
- rubigram/method.py +51 -6
- rubigram/network.py +1 -2
- rubigram/rubino/client.py +435 -37
- rubigram/types.py +128 -569
- {rubigramclient-1.6.8.dist-info → rubigramclient-1.7.0.dist-info}/METADATA +53 -3
- rubigramclient-1.7.0.dist-info/RECORD +15 -0
- rubigramclient-1.7.0.dist-info/licenses/LICENSE +21 -0
- rubigramclient-1.6.8.dist-info/RECORD +0 -15
- rubigramclient-1.6.8.dist-info/licenses/LICENSE +0 -0
- {rubigramclient-1.6.8.dist-info → rubigramclient-1.7.0.dist-info}/WHEEL +0 -0
- {rubigramclient-1.6.8.dist-info → rubigramclient-1.7.0.dist-info}/top_level.txt +0 -0
rubigram/client.py
CHANGED
|
@@ -36,6 +36,8 @@ class Client(Method):
|
|
|
36
36
|
self.ROUTES = []
|
|
37
37
|
self.MESSAGE_HANDLER = []
|
|
38
38
|
self.INLINE_HANDLER = []
|
|
39
|
+
self.EDIT_HANDLER = []
|
|
40
|
+
self.DELETE_HANDLER = []
|
|
39
41
|
self.state = StateManager()
|
|
40
42
|
super().__init__(token)
|
|
41
43
|
|
|
@@ -61,6 +63,28 @@ class Client(Method):
|
|
|
61
63
|
self.INLINE_HANDLER.append(wrapper)
|
|
62
64
|
return func
|
|
63
65
|
return decorator
|
|
66
|
+
|
|
67
|
+
def on_edit_message(self, filters: Optional[Filter] = None):
|
|
68
|
+
def decorator(func: Callable) -> Callable:
|
|
69
|
+
async def wrapper(client: Client, update: Update):
|
|
70
|
+
if filters is None or await filters(update):
|
|
71
|
+
await func(client, update)
|
|
72
|
+
return True
|
|
73
|
+
return False
|
|
74
|
+
self.EDIT_HANDLER.append(wrapper)
|
|
75
|
+
return func
|
|
76
|
+
return decorator
|
|
77
|
+
|
|
78
|
+
def on_delete_message(self, filters: Optional[Filter] = None):
|
|
79
|
+
def decorator(func: Callable) -> Callable:
|
|
80
|
+
async def wrapper(client: Client, update: Update):
|
|
81
|
+
if filters is None or await filters(update):
|
|
82
|
+
await func(client, update)
|
|
83
|
+
return True
|
|
84
|
+
return False
|
|
85
|
+
self.DELETE_HANDLER.append(wrapper)
|
|
86
|
+
return func
|
|
87
|
+
return decorator
|
|
64
88
|
|
|
65
89
|
def on_create_app(self, path: str, method: str = "GET"):
|
|
66
90
|
def decorator(func):
|
|
@@ -69,7 +93,19 @@ class Client(Method):
|
|
|
69
93
|
return decorator
|
|
70
94
|
|
|
71
95
|
async def dispatch(self, update: Union[Update, InlineMessage]):
|
|
72
|
-
|
|
96
|
+
if isinstance(update, InlineMessage):
|
|
97
|
+
handlers = self.INLINE_HANDLER
|
|
98
|
+
else:
|
|
99
|
+
type = update.type
|
|
100
|
+
if type == "NewMessage":
|
|
101
|
+
handlers = self.MESSAGE_HANDLER
|
|
102
|
+
elif type == "UpdatedMessage":
|
|
103
|
+
handlers = self.EDIT_HANDLER
|
|
104
|
+
elif type == "RemovedMessage":
|
|
105
|
+
handlers = self.DELETE_HANDLER
|
|
106
|
+
else:
|
|
107
|
+
logging.warning("Update type invalid : {}".format(type))
|
|
108
|
+
|
|
73
109
|
for handler in handlers:
|
|
74
110
|
matched = await handler(self, update)
|
|
75
111
|
if matched:
|
rubigram/enums.py
CHANGED
rubigram/filters.py
CHANGED
|
@@ -25,7 +25,7 @@ class Filter:
|
|
|
25
25
|
|
|
26
26
|
async def TEXT(message: Update):
|
|
27
27
|
if isinstance(message, Update):
|
|
28
|
-
return True if message.new_message and message.new_message.text else False
|
|
28
|
+
return True if message.new_message and message.new_message.text or message.updated_message.text else False
|
|
29
29
|
return False
|
|
30
30
|
|
|
31
31
|
async def FILE(message: Update):
|
|
@@ -126,8 +126,12 @@ class command(Filter):
|
|
|
126
126
|
super().__init__(self.filter)
|
|
127
127
|
|
|
128
128
|
async def filter(self, update: Update):
|
|
129
|
-
if isinstance(update, Update)
|
|
130
|
-
|
|
129
|
+
if isinstance(update, Update):
|
|
130
|
+
if update.new_message:
|
|
131
|
+
text = update.new_message.text
|
|
132
|
+
elif update.updated_message:
|
|
133
|
+
text = update.updated_message.text
|
|
134
|
+
else: return False
|
|
131
135
|
text = text if self.case_sensitive else text.lower()
|
|
132
136
|
return any(text.startswith(cmd) for cmd in self.cmds)
|
|
133
137
|
return False
|
|
@@ -143,7 +147,7 @@ class button(Filter):
|
|
|
143
147
|
|
|
144
148
|
async def filter(self, update: InlineMessage):
|
|
145
149
|
if isinstance(update, InlineMessage):
|
|
146
|
-
text = update.
|
|
150
|
+
text = update.aux_data.button_id or ""
|
|
147
151
|
text = text if self.case_sensitive else text.lower()
|
|
148
152
|
return any(text.startswith(btn) for btn in self.btn_ids)
|
|
149
153
|
return False
|
|
@@ -163,9 +167,7 @@ class regex(Filter):
|
|
|
163
167
|
elif isinstance(update, InlineMessage):
|
|
164
168
|
text = getattr(update, "text", "")
|
|
165
169
|
|
|
166
|
-
if text
|
|
167
|
-
return bool(re.search(self.pattern, text))
|
|
168
|
-
return False
|
|
170
|
+
return bool(re.search(self.pattern, text)) if text else False
|
|
169
171
|
|
|
170
172
|
|
|
171
173
|
class chat(Filter):
|
rubigram/method.py
CHANGED
|
@@ -36,19 +36,19 @@ class Method(Network):
|
|
|
36
36
|
return response
|
|
37
37
|
|
|
38
38
|
async def delete_message(self, chat_id: str, message_id: str):
|
|
39
|
-
await self.request("deleteMessage", {"chat_id": chat_id, "message_id": message_id})
|
|
39
|
+
return await self.request("deleteMessage", {"chat_id": chat_id, "message_id": message_id})
|
|
40
40
|
|
|
41
41
|
async def remove_chat_keypad(self, chat_id: str):
|
|
42
|
-
await self.request("editChatKeypad", {"chat_id": chat_id, "chat_keypad_type": "Remove"})
|
|
42
|
+
return await self.request("editChatKeypad", {"chat_id": chat_id, "chat_keypad_type": "Remove"})
|
|
43
43
|
|
|
44
44
|
async def edit_chat_keypad(self, chat_id: str, chat_keypad: Keypad):
|
|
45
|
-
await self.request("editChatKeypad", {"chat_id": chat_id, "chat_keypad_type": "New", "chat_keypad": chat_keypad.asdict()})
|
|
45
|
+
return await self.request("editChatKeypad", {"chat_id": chat_id, "chat_keypad_type": "New", "chat_keypad": chat_keypad.asdict()})
|
|
46
46
|
|
|
47
47
|
async def edit_message_keypad(self, chat_id: str, message_id: str, inline_keypad: Keypad):
|
|
48
|
-
await self.request("editMessageKeypad", {"chat_id": chat_id, "message_id": message_id, "inline_keypad": inline_keypad.asdict()})
|
|
48
|
+
return await self.request("editMessageKeypad", {"chat_id": chat_id, "message_id": message_id, "inline_keypad": inline_keypad.asdict()})
|
|
49
49
|
|
|
50
50
|
async def edit_message_text(self, chat_id: str, message_id: str, text: str):
|
|
51
|
-
await self.request("editMessageText", {"chat_id": chat_id, "message_id": message_id, "text": text})
|
|
51
|
+
return await self.request("editMessageText", {"chat_id": chat_id, "message_id": message_id, "text": text})
|
|
52
52
|
|
|
53
53
|
async def edit_message(
|
|
54
54
|
self,
|
|
@@ -306,4 +306,49 @@ class Method(Network):
|
|
|
306
306
|
|
|
307
307
|
async def get_bot_start_messagel(self):
|
|
308
308
|
bot = await self.get_me()
|
|
309
|
-
return bot.start_message
|
|
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
CHANGED
|
@@ -2,7 +2,6 @@ from aiohttp import ClientSession, FormData
|
|
|
2
2
|
from typing import Any, Optional, Union
|
|
3
3
|
from pathlib import Path
|
|
4
4
|
from urllib.parse import urlparse
|
|
5
|
-
from random import randint
|
|
6
5
|
import aiofiles
|
|
7
6
|
import os
|
|
8
7
|
|
|
@@ -34,7 +33,7 @@ class Network:
|
|
|
34
33
|
async with self.session.post(self.api + method, json=json) as response:
|
|
35
34
|
response.raise_for_status()
|
|
36
35
|
data: dict = await response.json()
|
|
37
|
-
return data.get("data")
|
|
36
|
+
return data.get("data", {})
|
|
38
37
|
|
|
39
38
|
async def getBytes(self, url: str) -> bytes:
|
|
40
39
|
await self.start()
|