Rubka 7.1.10__py3-none-any.whl → 7.1.11__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.
- rubka/api.py +2 -1
- rubka/asynco.py +183 -39
- rubka/context.py +2 -1
- rubka/metadata.py +92 -0
- rubka/update.py +3 -1
- {rubka-7.1.10.dist-info → rubka-7.1.11.dist-info}/METADATA +1 -1
- {rubka-7.1.10.dist-info → rubka-7.1.11.dist-info}/RECORD +10 -9
- {rubka-7.1.10.dist-info → rubka-7.1.11.dist-info}/WHEEL +0 -0
- {rubka-7.1.10.dist-info → rubka-7.1.11.dist-info}/entry_points.txt +0 -0
- {rubka-7.1.10.dist-info → rubka-7.1.11.dist-info}/top_level.txt +0 -0
rubka/api.py
CHANGED
|
@@ -1011,7 +1011,8 @@ class Robot:
|
|
|
1011
1011
|
disable_notification: bool = False,
|
|
1012
1012
|
reply_to_message_id: Optional[str] = None,
|
|
1013
1013
|
chat_keypad_type: Optional[Literal["New", "Removed"]] = None,
|
|
1014
|
-
delete_after = None
|
|
1014
|
+
delete_after = None,
|
|
1015
|
+
parse_mode = None
|
|
1015
1016
|
) -> Dict[str, Any]:
|
|
1016
1017
|
"""
|
|
1017
1018
|
Send a text message to a chat.
|
rubka/asynco.py
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import asyncio,aiohttp,aiofiles,time,datetime,json,tempfile,os,sys,subprocess,mimetypes,time, hashlib,sqlite3
|
|
1
|
+
import asyncio,aiohttp,aiofiles,time,datetime,json,tempfile,os,sys,subprocess,mimetypes,time, hashlib,sqlite3,re
|
|
2
2
|
from typing import List, Optional, Dict, Any, Literal, Callable, Union,Set
|
|
3
3
|
from collections import OrderedDict
|
|
4
4
|
from .exceptions import APIRequestError,raise_for_status,InvalidAccessError,InvalidInputError,TooRequestError,InvalidTokenError
|
|
5
5
|
from .adaptorrubka import Client as Client_get
|
|
6
6
|
from .logger import logger
|
|
7
|
+
from .metadata import Track_parsed as GlyphWeaver
|
|
7
8
|
from .rubino import Bot as Rubino
|
|
8
9
|
from . import filters
|
|
9
10
|
try:from .context import Message, InlineMessage
|
|
@@ -27,6 +28,127 @@ def install_package(package_name: str) -> bool:
|
|
|
27
28
|
except Exception:
|
|
28
29
|
return False
|
|
29
30
|
|
|
31
|
+
def metadata_CallBack(text: str, mode: str) -> Dict[str, Any]:
|
|
32
|
+
meta_data_parts = []
|
|
33
|
+
if mode == "Markdown":
|
|
34
|
+
for match in re.finditer(r"\*\*(.*?)\*\*", text):
|
|
35
|
+
meta_data_parts.append({
|
|
36
|
+
"type": "Bold",
|
|
37
|
+
"from_index": match.start(1),
|
|
38
|
+
"length": len(match.group(1))
|
|
39
|
+
})
|
|
40
|
+
for match in re.finditer(r"(?<!\*)\*(?!\*)(.*?)\*(?!\*)", text):
|
|
41
|
+
meta_data_parts.append({
|
|
42
|
+
"type": "Italic",
|
|
43
|
+
"from_index": match.start(1),
|
|
44
|
+
"length": len(match.group(1))
|
|
45
|
+
})
|
|
46
|
+
for match in re.finditer(r"~~(.*?)~~", text):
|
|
47
|
+
meta_data_parts.append({
|
|
48
|
+
"type": "Strike",
|
|
49
|
+
"from_index": match.start(1),
|
|
50
|
+
"length": len(match.group(1))
|
|
51
|
+
})
|
|
52
|
+
for match in re.finditer(r"__(.*?)__", text):
|
|
53
|
+
meta_data_parts.append({
|
|
54
|
+
"type": "Underline",
|
|
55
|
+
"from_index": match.start(1),
|
|
56
|
+
"length": len(match.group(1))
|
|
57
|
+
})
|
|
58
|
+
for match in re.finditer(r"^> (.*)$", text, re.MULTILINE):
|
|
59
|
+
meta_data_parts.append({
|
|
60
|
+
"type": "Quote",
|
|
61
|
+
"from_index": match.start(1),
|
|
62
|
+
"length": len(match.group(1))
|
|
63
|
+
})
|
|
64
|
+
for match in re.finditer(r"\|\|(.*?)\|\|", text):
|
|
65
|
+
meta_data_parts.append({
|
|
66
|
+
"type": "Spoiler",
|
|
67
|
+
"from_index": match.start(1),
|
|
68
|
+
"length": len(match.group(1))
|
|
69
|
+
})
|
|
70
|
+
for match in re.finditer(r"`(.*?)`", text):
|
|
71
|
+
meta_data_parts.append({
|
|
72
|
+
"type": "Mono",
|
|
73
|
+
"from_index": match.start(1),
|
|
74
|
+
"length": len(match.group(1))
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
for match in re.finditer(r"```(.*?)```", text, re.DOTALL):
|
|
78
|
+
meta_data_parts.append({
|
|
79
|
+
"type": "Pre",
|
|
80
|
+
"from_index": match.start(1),
|
|
81
|
+
"length": len(match.group(1))
|
|
82
|
+
})
|
|
83
|
+
for match in re.finditer(r"\[(.*?)\]\((.*?)\)", text):
|
|
84
|
+
meta_data_parts.append({
|
|
85
|
+
"type": "Link",
|
|
86
|
+
"from_index": match.start(1),
|
|
87
|
+
"length": len(match.group(1)),
|
|
88
|
+
"link_url": match.group(2)
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
elif mode == "HTML":
|
|
92
|
+
for match in re.finditer(r"<b>(.*?)</b>", text):
|
|
93
|
+
meta_data_parts.append({
|
|
94
|
+
"type": "Bold",
|
|
95
|
+
"from_index": match.start(1),
|
|
96
|
+
"length": len(match.group(1))
|
|
97
|
+
})
|
|
98
|
+
for match in re.finditer(r"<i>(.*?)</i>", text):
|
|
99
|
+
meta_data_parts.append({
|
|
100
|
+
"type": "Italic",
|
|
101
|
+
"from_index": match.start(1),
|
|
102
|
+
"length": len(match.group(1))
|
|
103
|
+
})
|
|
104
|
+
for match in re.finditer(r"<u>(.*?)</u>", text):
|
|
105
|
+
meta_data_parts.append({
|
|
106
|
+
"type": "Underline",
|
|
107
|
+
"from_index": match.start(1),
|
|
108
|
+
"length": len(match.group(1))
|
|
109
|
+
})
|
|
110
|
+
for match in re.finditer(r"<s>(.*?)</s>|<strike>(.*?)</strike>", text):
|
|
111
|
+
inner = match.group(1) or match.group(2)
|
|
112
|
+
meta_data_parts.append({
|
|
113
|
+
"type": "Strike",
|
|
114
|
+
"from_index": match.start(),
|
|
115
|
+
"length": len(inner)
|
|
116
|
+
})
|
|
117
|
+
for match in re.finditer(r"<blockquote>(.*?)</blockquote>", text, re.DOTALL):
|
|
118
|
+
meta_data_parts.append({
|
|
119
|
+
"type": "Quote",
|
|
120
|
+
"from_index": match.start(1),
|
|
121
|
+
"length": len(match.group(1))
|
|
122
|
+
})
|
|
123
|
+
for match in re.finditer(r'<span class="spoiler">(.*?)</span>', text):
|
|
124
|
+
meta_data_parts.append({
|
|
125
|
+
"type": "Spoiler",
|
|
126
|
+
"from_index": match.start(1),
|
|
127
|
+
"length": len(match.group(1))
|
|
128
|
+
})
|
|
129
|
+
for match in re.finditer(r"<code>(.*?)</code>", text):
|
|
130
|
+
meta_data_parts.append({
|
|
131
|
+
"type": "Pre",
|
|
132
|
+
"from_index": match.start(1),
|
|
133
|
+
"length": len(match.group(1))
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
for match in re.finditer(r"<pre>(.*?)</pre>", text, re.DOTALL):
|
|
137
|
+
meta_data_parts.append({
|
|
138
|
+
"type": "Pre",
|
|
139
|
+
"from_index": match.start(1),
|
|
140
|
+
"length": len(match.group(1))
|
|
141
|
+
})
|
|
142
|
+
for match in re.finditer(r'<a href="(.*?)">(.*?)</a>', text):
|
|
143
|
+
meta_data_parts.append({
|
|
144
|
+
"type": "Link",
|
|
145
|
+
"from_index": match.start(2),
|
|
146
|
+
"length": len(match.group(2)),
|
|
147
|
+
"link_url": match.group(1)
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
return {"meta_data_parts": meta_data_parts} if meta_data_parts else {}
|
|
151
|
+
|
|
30
152
|
def get_importlib_metadata():
|
|
31
153
|
try:
|
|
32
154
|
from importlib.metadata import version, PackageNotFoundError
|
|
@@ -143,7 +265,7 @@ safeSendMode ensures reliable message sending even if replying by message_id fai
|
|
|
143
265
|
max_cache_size and max_msg_age help manage duplicate message processing efficiently.
|
|
144
266
|
"""
|
|
145
267
|
|
|
146
|
-
def __init__(self, token: str, session_name: str = None, auth: str = None, Key: str = None, platform: str = "web", web_hook: str = None, timeout: int = 10, show_progress: bool = False, raise_errors: bool = True,proxy: str = None,retries: int = 2,retry_delay: float = 0.5,user_agent: str = None,safeSendMode = False,max_cache_size: int = 2000,max_msg_age : int = 60,chunk_size : int = 64 * 1024):
|
|
268
|
+
def __init__(self, token: str, session_name: str = None, auth: str = None, Key: str = None, platform: str = "web", web_hook: str = None, timeout: int = 10, show_progress: bool = False, raise_errors: bool = True,proxy: str = None,retries: int = 2,retry_delay: float = 0.5,user_agent: str = None,safeSendMode = False,max_cache_size: int = 2000,max_msg_age : int = 60,chunk_size : int = 64 * 1024,parse_mode: Optional[Literal["HTML", "Markdown"]] = "Markdown"):
|
|
147
269
|
self.token = token
|
|
148
270
|
self._inline_query_handlers: List[dict] = []
|
|
149
271
|
self.timeout = timeout
|
|
@@ -161,6 +283,7 @@ max_cache_size and max_msg_age help manage duplicate message processing efficien
|
|
|
161
283
|
self.Key = Key
|
|
162
284
|
self.platform = platform
|
|
163
285
|
self.web_hook = web_hook
|
|
286
|
+
self.parse_mode = parse_mode
|
|
164
287
|
self._offset_id: Optional[str] = None
|
|
165
288
|
self._aiohttp_session: aiohttp.ClientSession = None
|
|
166
289
|
self.sessions: Dict[str, Dict[str, Any]] = {}
|
|
@@ -1692,23 +1815,35 @@ max_cache_size and max_msg_age help manage duplicate message processing efficien
|
|
|
1692
1815
|
|
|
1693
1816
|
task = loop.create_task(_task())
|
|
1694
1817
|
return task
|
|
1818
|
+
def _parse_text_metadata(self, text: str, parse_mode: str):
|
|
1819
|
+
formatter = GlyphWeaver()
|
|
1820
|
+
parsed = formatter.parse(text, parse_mode)
|
|
1821
|
+
return parsed.get("text"), parsed.get("metadata")
|
|
1695
1822
|
|
|
1696
1823
|
async def send_message(
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1824
|
+
self,
|
|
1825
|
+
chat_id: str,
|
|
1826
|
+
text: str,
|
|
1827
|
+
chat_keypad: Optional[Dict[str, Any]] = None,
|
|
1828
|
+
inline_keypad: Optional[Dict[str, Any]] = None,
|
|
1829
|
+
disable_notification: bool = False,
|
|
1830
|
+
reply_to_message_id: Optional[str] = None,
|
|
1831
|
+
chat_keypad_type: Optional[Literal["New", "Remove"]] = None,
|
|
1832
|
+
delete_after: Optional[int] = None,
|
|
1833
|
+
parse_mode: Optional[Literal["HTML", "Markdown"]] = None
|
|
1834
|
+
) -> Dict[str, Any]:
|
|
1835
|
+
|
|
1707
1836
|
payload = {
|
|
1708
1837
|
"chat_id": chat_id,
|
|
1709
1838
|
"text": text,
|
|
1710
1839
|
"disable_notification": disable_notification,
|
|
1711
1840
|
}
|
|
1841
|
+
parse_mode_to_use = parse_mode or self.parse_mode
|
|
1842
|
+
if text:
|
|
1843
|
+
text, metadata = self._parse_text_metadata(text, parse_mode_to_use)
|
|
1844
|
+
payload["text"] = text
|
|
1845
|
+
if metadata:
|
|
1846
|
+
payload["metadata"] = metadata
|
|
1712
1847
|
if chat_keypad:
|
|
1713
1848
|
payload["chat_keypad"] = chat_keypad
|
|
1714
1849
|
payload["chat_keypad_type"] = chat_keypad_type or "New"
|
|
@@ -1716,19 +1851,18 @@ max_cache_size and max_msg_age help manage duplicate message processing efficien
|
|
|
1716
1851
|
payload["inline_keypad"] = inline_keypad
|
|
1717
1852
|
if reply_to_message_id:
|
|
1718
1853
|
payload["reply_to_message_id"] = reply_to_message_id
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1854
|
+
try:
|
|
1855
|
+
state = await self._post("sendMessage", payload)
|
|
1856
|
+
except Exception:
|
|
1857
|
+
if self.safeSendMode and reply_to_message_id:
|
|
1723
1858
|
payload.pop("reply_to_message_id", None)
|
|
1724
1859
|
state = await self._post("sendMessage", payload)
|
|
1725
|
-
|
|
1726
|
-
|
|
1860
|
+
else:
|
|
1861
|
+
raise
|
|
1727
1862
|
if delete_after:
|
|
1728
1863
|
await self.delete_after(chat_id, state.message_id, delete_after)
|
|
1729
|
-
return state
|
|
1730
1864
|
return state
|
|
1731
|
-
|
|
1865
|
+
|
|
1732
1866
|
|
|
1733
1867
|
async def send_sticker(
|
|
1734
1868
|
self,
|
|
@@ -1996,11 +2130,16 @@ max_cache_size and max_msg_age help manage duplicate message processing efficien
|
|
|
1996
2130
|
raise ValueError(f"Invalid media type. Must be one of {allowed}")
|
|
1997
2131
|
result = await self._post("requestSendFile", {"type": media_type})
|
|
1998
2132
|
return result.get("data", {}).get("upload_url")
|
|
1999
|
-
async def _send_uploaded_file(self, chat_id: str, file_id: str,type_file : str = "file",text: Optional[str] = None, chat_keypad: Optional[Dict[str, Any]] = None, inline_keypad: Optional[Dict[str, Any]] = None, disable_notification: bool = False, reply_to_message_id: Optional[str] = None, chat_keypad_type: Optional[Literal["New", "Remove", "None"]] = "None") -> Dict[str, Any]:
|
|
2133
|
+
async def _send_uploaded_file(self, chat_id: str, file_id: str,type_file : str = "file",text: Optional[str] = None, chat_keypad: Optional[Dict[str, Any]] = None, inline_keypad: Optional[Dict[str, Any]] = None, disable_notification: bool = False, reply_to_message_id: Optional[str] = None, chat_keypad_type: Optional[Literal["New", "Remove", "None"]] = "None",parse_mode: Optional[Literal["HTML", "Markdown"]] = None) -> Dict[str, Any]:
|
|
2000
2134
|
payload = {"chat_id": chat_id, "file_id": file_id, "text": text, "disable_notification": disable_notification, "chat_keypad_type": chat_keypad_type}
|
|
2001
2135
|
if chat_keypad: payload["chat_keypad"] = chat_keypad
|
|
2002
2136
|
if inline_keypad: payload["inline_keypad"] = inline_keypad
|
|
2003
2137
|
if reply_to_message_id: payload["reply_to_message_id"] = str(reply_to_message_id)
|
|
2138
|
+
parse_mode_to_use = parse_mode or self.parse_mode
|
|
2139
|
+
if text:
|
|
2140
|
+
text, metadata = self._parse_text_metadata(text, parse_mode_to_use)
|
|
2141
|
+
payload["text"] = text
|
|
2142
|
+
if metadata:payload["metadata"] = metadata
|
|
2004
2143
|
payload["time"] = "10"
|
|
2005
2144
|
resp = await self._post("sendFile", payload)
|
|
2006
2145
|
message_id_put = resp["data"]["message_id"]
|
|
@@ -2020,20 +2159,26 @@ max_cache_size and max_msg_age help manage duplicate message processing efficien
|
|
|
2020
2159
|
"chat_keypad_type":chat_keypad_type
|
|
2021
2160
|
}
|
|
2022
2161
|
return AttrDict(result)
|
|
2023
|
-
async def _send_file_generic(self, media_type, chat_id, path, file_id, text, file_name, inline_keypad, chat_keypad, reply_to_message_id, disable_notification, chat_keypad_type):
|
|
2162
|
+
async def _send_file_generic(self, media_type, chat_id, path, file_id, text, file_name, inline_keypad, chat_keypad, reply_to_message_id, disable_notification, chat_keypad_type,parse_mode: Optional[Literal["HTML", "Markdown"]] = None):
|
|
2024
2163
|
if path:
|
|
2025
2164
|
file_name = file_name or Path(path).name
|
|
2026
2165
|
upload_url = await self.get_upload_url(media_type)
|
|
2027
2166
|
file_id = await self.upload_media_file(upload_url, file_name, path)
|
|
2028
2167
|
if not file_id:
|
|
2029
2168
|
raise ValueError("Either path or file_id must be provided.")
|
|
2030
|
-
return await self._send_uploaded_file(chat_id=chat_id, file_id=file_id, text=text, inline_keypad=inline_keypad, chat_keypad=chat_keypad, reply_to_message_id=reply_to_message_id, disable_notification=disable_notification, chat_keypad_type=chat_keypad_type,type_file=media_type)
|
|
2031
|
-
async def send_document(self, chat_id: str, path: Optional[Union[str, Path]] = None, file_id: Optional[str] = None, text: Optional[str] = None, file_name: Optional[str] = None, inline_keypad: Optional[Dict[str, Any]] = None, chat_keypad: Optional[Dict[str, Any]] = None, reply_to_message_id: Optional[str] = None, disable_notification: bool = False, chat_keypad_type: Optional[Literal["New", "Remove", "None"]] = "None") -> Dict[str, Any]:
|
|
2032
|
-
return await self._send_file_generic("File", chat_id, path, file_id, text, file_name, inline_keypad, chat_keypad, reply_to_message_id, disable_notification, chat_keypad_type)
|
|
2033
|
-
async def send_file(self, chat_id: str, path: Optional[Union[str, Path]] = None, file_id: Optional[str] = None, caption: Optional[str] = None, file_name: Optional[str] = None, inline_keypad: Optional[Dict[str, Any]] = None, chat_keypad: Optional[Dict[str, Any]] = None, reply_to_message_id: Optional[str] = None, disable_notification: bool = False, chat_keypad_type: Optional[Literal["New", "Remove", "None"]] = "None") -> Dict[str, Any]:
|
|
2034
|
-
return await self._send_file_generic("File", chat_id, path, file_id, caption, file_name, inline_keypad, chat_keypad, reply_to_message_id, disable_notification, chat_keypad_type)
|
|
2035
|
-
async def re_send(self, chat_id: str, path: Optional[Union[str, Path]] = None, file_id: Optional[str] = None, caption: Optional[str] = None, file_name: Optional[str] = None, inline_keypad: Optional[Dict[str, Any]] = None, chat_keypad: Optional[Dict[str, Any]] = None, reply_to_message_id: Optional[str] = None, disable_notification: bool = False, chat_keypad_type: Optional[Literal["New", "Remove", "None"]] = "None") -> Dict[str, Any]:
|
|
2036
|
-
return await self._send_file_generic("File", chat_id, path, file_id, caption, file_name, inline_keypad, chat_keypad, reply_to_message_id, disable_notification, chat_keypad_type)
|
|
2169
|
+
return await self._send_uploaded_file(chat_id=chat_id, file_id=file_id, text=text, inline_keypad=inline_keypad, chat_keypad=chat_keypad, reply_to_message_id=reply_to_message_id, disable_notification=disable_notification, chat_keypad_type=chat_keypad_type,type_file=media_type,parse_mode=parse_mode)
|
|
2170
|
+
async def send_document(self, chat_id: str, path: Optional[Union[str, Path]] = None, file_id: Optional[str] = None, text: Optional[str] = None, file_name: Optional[str] = None, inline_keypad: Optional[Dict[str, Any]] = None, chat_keypad: Optional[Dict[str, Any]] = None, reply_to_message_id: Optional[str] = None, disable_notification: bool = False, chat_keypad_type: Optional[Literal["New", "Remove", "None"]] = "None",parse_mode: Optional[Literal["HTML", "Markdown"]] = None) -> Dict[str, Any]:
|
|
2171
|
+
return await self._send_file_generic("File", chat_id, path, file_id, text, file_name, inline_keypad, chat_keypad, reply_to_message_id, disable_notification, chat_keypad_type,parse_mode=parse_mode)
|
|
2172
|
+
async def send_file(self, chat_id: str, path: Optional[Union[str, Path]] = None, file_id: Optional[str] = None, caption: Optional[str] = None, file_name: Optional[str] = None, inline_keypad: Optional[Dict[str, Any]] = None, chat_keypad: Optional[Dict[str, Any]] = None, reply_to_message_id: Optional[str] = None, disable_notification: bool = False, chat_keypad_type: Optional[Literal["New", "Remove", "None"]] = "None",parse_mode: Optional[Literal["HTML", "Markdown"]] = None) -> Dict[str, Any]:
|
|
2173
|
+
return await self._send_file_generic("File", chat_id, path, file_id, caption, file_name, inline_keypad, chat_keypad, reply_to_message_id, disable_notification, chat_keypad_type,parse_mode=parse_mode)
|
|
2174
|
+
async def re_send(self, chat_id: str, path: Optional[Union[str, Path]] = None, file_id: Optional[str] = None, caption: Optional[str] = None, file_name: Optional[str] = None, inline_keypad: Optional[Dict[str, Any]] = None, chat_keypad: Optional[Dict[str, Any]] = None, reply_to_message_id: Optional[str] = None, disable_notification: bool = False, chat_keypad_type: Optional[Literal["New", "Remove", "None"]] = "None",parse_mode: Optional[Literal["HTML", "Markdown"]] = None) -> Dict[str, Any]:
|
|
2175
|
+
return await self._send_file_generic("File", chat_id, path, file_id, caption, file_name, inline_keypad, chat_keypad, reply_to_message_id, disable_notification, chat_keypad_type,parse_mode=parse_mode)
|
|
2176
|
+
async def send_video(self, chat_id: str, path: Optional[Union[str, Path]] = None, file_id: Optional[str] = None, text: Optional[str] = None, file_name: Optional[str] = None, inline_keypad: Optional[Dict[str, Any]] = None, chat_keypad: Optional[Dict[str, Any]] = None, reply_to_message_id: Optional[str] = None, disable_notification: bool = False, chat_keypad_type: Optional[Literal["New", "Remove", "None"]] = "None",parse_mode: Optional[Literal["HTML", "Markdown"]] = None) -> Dict[str, Any]:
|
|
2177
|
+
return await self._send_file_generic("Video", chat_id, path, file_id, text, file_name, inline_keypad, chat_keypad, reply_to_message_id, disable_notification, chat_keypad_type,parse_mode=parse_mode)
|
|
2178
|
+
async def send_voice(self, chat_id: str, path: Optional[Union[str, Path]] = None, file_id: Optional[str] = None, text: Optional[str] = None, file_name: Optional[str] = None, inline_keypad: Optional[Dict[str, Any]] = None, chat_keypad: Optional[Dict[str, Any]] = None, reply_to_message_id: Optional[str] = None, disable_notification: bool = False, chat_keypad_type: Optional[Literal["New", "Remove", "None"]] = "None",parse_mode: Optional[Literal["HTML", "Markdown"]] = None) -> Dict[str, Any]:
|
|
2179
|
+
return await self._send_file_generic("voice", chat_id, path, file_id, text, file_name, inline_keypad, chat_keypad, reply_to_message_id, disable_notification, chat_keypad_type,parse_mode=parse_mode)
|
|
2180
|
+
async def send_image(self, chat_id: str, path: Optional[Union[str, Path]] = None, file_id: Optional[str] = None, text: Optional[str] = None, file_name: Optional[str] = None, inline_keypad: Optional[Dict[str, Any]] = None, chat_keypad: Optional[Dict[str, Any]] = None, reply_to_message_id: Optional[str] = None, disable_notification: bool = False, chat_keypad_type: Optional[Literal["New", "Remove", "None"]] = "None",parse_mode: Optional[Literal["HTML", "Markdown"]] = None) -> Dict[str, Any]:
|
|
2181
|
+
return await self._send_file_generic("Image", chat_id, path, file_id, text, file_name, inline_keypad, chat_keypad, reply_to_message_id, disable_notification, chat_keypad_type,parse_mode=parse_mode)
|
|
2037
2182
|
async def send_music(
|
|
2038
2183
|
self,
|
|
2039
2184
|
chat_id: str,
|
|
@@ -2045,7 +2190,8 @@ max_cache_size and max_msg_age help manage duplicate message processing efficien
|
|
|
2045
2190
|
chat_keypad: Optional[Dict[str, Any]] = None,
|
|
2046
2191
|
reply_to_message_id: Optional[str] = None,
|
|
2047
2192
|
disable_notification: bool = False,
|
|
2048
|
-
chat_keypad_type: Optional[Literal["New", "Remove", "None"]] = "None"
|
|
2193
|
+
chat_keypad_type: Optional[Literal["New", "Remove", "None"]] = "None",
|
|
2194
|
+
parse_mode: Optional[Literal["HTML", "Markdown"]] = None
|
|
2049
2195
|
) -> Dict[str, Any]:
|
|
2050
2196
|
valid_extensions = {"ogg", "oga", "opus", "flac"}
|
|
2051
2197
|
extension = "flac"
|
|
@@ -2077,7 +2223,8 @@ max_cache_size and max_msg_age help manage duplicate message processing efficien
|
|
|
2077
2223
|
chat_keypad,
|
|
2078
2224
|
reply_to_message_id,
|
|
2079
2225
|
disable_notification,
|
|
2080
|
-
chat_keypad_type
|
|
2226
|
+
chat_keypad_type,
|
|
2227
|
+
parse_mode=parse_mode
|
|
2081
2228
|
)
|
|
2082
2229
|
async def send_gif(
|
|
2083
2230
|
self,
|
|
@@ -2090,7 +2237,8 @@ max_cache_size and max_msg_age help manage duplicate message processing efficien
|
|
|
2090
2237
|
chat_keypad: Optional[Dict[str, Any]] = None,
|
|
2091
2238
|
reply_to_message_id: Optional[str] = None,
|
|
2092
2239
|
disable_notification: bool = False,
|
|
2093
|
-
chat_keypad_type: Optional[Literal["New", "Remove", "None"]] = "None"
|
|
2240
|
+
chat_keypad_type: Optional[Literal["New", "Remove", "None"]] = "None",
|
|
2241
|
+
parse_mode: Optional[Literal["HTML", "Markdown"]] = None
|
|
2094
2242
|
) -> Dict[str, Any]:
|
|
2095
2243
|
valid_extensions = {"gif"}
|
|
2096
2244
|
extension = "gif"
|
|
@@ -2122,7 +2270,8 @@ max_cache_size and max_msg_age help manage duplicate message processing efficien
|
|
|
2122
2270
|
chat_keypad,
|
|
2123
2271
|
reply_to_message_id,
|
|
2124
2272
|
disable_notification,
|
|
2125
|
-
chat_keypad_type
|
|
2273
|
+
chat_keypad_type,
|
|
2274
|
+
parse_mode=parse_mode
|
|
2126
2275
|
)
|
|
2127
2276
|
|
|
2128
2277
|
async def get_avatar_me(self, save_as: str = None) -> str:
|
|
@@ -2285,12 +2434,7 @@ max_cache_size and max_msg_age help manage duplicate message processing efficien
|
|
|
2285
2434
|
return await self._post("sendContact", {"chat_id": chat_id, "first_name": first_name, "last_name": last_name, "phone_number": phone_number,"inline_keypad": inline_keypad,"chat_keypad": chat_keypad,"chat_keypad_type": chat_keypad_type})
|
|
2286
2435
|
async def get_chat(self, chat_id: str) -> Dict[str, Any]:
|
|
2287
2436
|
return await self._post("getChat", {"chat_id": chat_id})
|
|
2288
|
-
|
|
2289
|
-
return await self._send_file_generic("Video", chat_id, path, file_id, text, file_name, inline_keypad, chat_keypad, reply_to_message_id, disable_notification, chat_keypad_type)
|
|
2290
|
-
async def send_voice(self, chat_id: str, path: Optional[Union[str, Path]] = None, file_id: Optional[str] = None, text: Optional[str] = None, file_name: Optional[str] = None, inline_keypad: Optional[Dict[str, Any]] = None, chat_keypad: Optional[Dict[str, Any]] = None, reply_to_message_id: Optional[str] = None, disable_notification: bool = False, chat_keypad_type: Optional[Literal["New", "Remove", "None"]] = "None") -> Dict[str, Any]:
|
|
2291
|
-
return await self._send_file_generic("voice", chat_id, path, file_id, text, file_name, inline_keypad, chat_keypad, reply_to_message_id, disable_notification, chat_keypad_type)
|
|
2292
|
-
async def send_image(self, chat_id: str, path: Optional[Union[str, Path]] = None, file_id: Optional[str] = None, text: Optional[str] = None, file_name: Optional[str] = None, inline_keypad: Optional[Dict[str, Any]] = None, chat_keypad: Optional[Dict[str, Any]] = None, reply_to_message_id: Optional[str] = None, disable_notification: bool = False, chat_keypad_type: Optional[Literal["New", "Remove", "None"]] = "None") -> Dict[str, Any]:
|
|
2293
|
-
return await self._send_file_generic("Image", chat_id, path, file_id, text, file_name, inline_keypad, chat_keypad, reply_to_message_id, disable_notification, chat_keypad_type)
|
|
2437
|
+
|
|
2294
2438
|
def get_all_member(self, channel_guid: str, search_text: str = None, start_id: str = None, just_get_guids: bool = False):
|
|
2295
2439
|
client = self._get_client()
|
|
2296
2440
|
return client.get_all_members(channel_guid, search_text, start_id, just_get_guids)
|
rubka/context.py
CHANGED
|
@@ -367,7 +367,7 @@ class Message:
|
|
|
367
367
|
self.bot.sessions[self.chat_id] = {}
|
|
368
368
|
return self.bot.sessions[self.chat_id]
|
|
369
369
|
|
|
370
|
-
def reply(self, text: str, delete_after: int = None, **kwargs):
|
|
370
|
+
def reply(self, text: str, delete_after: int = None,parse_mode : Optional[Literal["HTML", "Markdown"]] = None , **kwargs):
|
|
371
371
|
async def _reply_async():
|
|
372
372
|
send_func = self.bot.send_message
|
|
373
373
|
if inspect.iscoroutinefunction(send_func):
|
|
@@ -376,6 +376,7 @@ class Message:
|
|
|
376
376
|
text,
|
|
377
377
|
reply_to_message_id=self.message_id,
|
|
378
378
|
delete_after=delete_after,
|
|
379
|
+
parse_mode=parse_mode,
|
|
379
380
|
**kwargs
|
|
380
381
|
)
|
|
381
382
|
else:
|
rubka/metadata.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from typing import Any, Dict, List
|
|
3
|
+
import markdownify
|
|
4
|
+
class Track_parsed:
|
|
5
|
+
_PATT = re.compile(
|
|
6
|
+
r"(?P<pre>```(?P<pre_c>[\s\S]*?)```)"
|
|
7
|
+
r"|(?P<bold>\*\*(?P<bold_c>.*?)\*\*)"
|
|
8
|
+
r"|(?P<mono>`(?P<mono_c>.*?)`)"
|
|
9
|
+
r"|(?P<italic>__(?P<italic_c>.*?)__)"
|
|
10
|
+
r"|(?P<underline>--(?P<underline_c>.*?)--)"
|
|
11
|
+
r"|(?P<strike>~~(?P<strike_c>.*?)~~)"
|
|
12
|
+
r"|(?P<spoiler>\|\|(?P<spoiler_c>.*?)\|\|)"
|
|
13
|
+
r"|(?P<link>\[(?P<link_text>.*?)\]\((?P<link_url>\S+?)\))",
|
|
14
|
+
flags=re.DOTALL,
|
|
15
|
+
)
|
|
16
|
+
_TYPE_MAP = {
|
|
17
|
+
"pre": "Pre",
|
|
18
|
+
"bold": "Bold",
|
|
19
|
+
"mono": "Mono",
|
|
20
|
+
"italic": "Italic",
|
|
21
|
+
"underline": "Underline",
|
|
22
|
+
"strike": "Strike",
|
|
23
|
+
"spoiler": "Spoiler",
|
|
24
|
+
"link": "Link",
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@staticmethod
|
|
28
|
+
def _utf16_len_java_style(s: str) -> int:
|
|
29
|
+
return len(s.encode("utf-16-be")) // 2
|
|
30
|
+
|
|
31
|
+
@staticmethod
|
|
32
|
+
def _html2md(src: str) -> str:
|
|
33
|
+
src = re.sub(r'<i>(.*?)</i>', r'||\1||', src, flags=re.DOTALL)
|
|
34
|
+
src = re.sub(r'<span class="spoiler">(.*?)</span>', r'||\1||', src, flags=re.DOTALL)
|
|
35
|
+
src = markdownify.markdownify(html=src).strip()
|
|
36
|
+
src = src.replace("@@SPOILER@@", "||")
|
|
37
|
+
return src
|
|
38
|
+
|
|
39
|
+
def transcribe(self, src: str, mode: str = "MARKDOWN") -> Dict[str, Any]:
|
|
40
|
+
if mode and mode.upper() == "HTML":src = self._html2md(src)
|
|
41
|
+
|
|
42
|
+
payload_parts: List[Dict[str, Any]] = []
|
|
43
|
+
|
|
44
|
+
normalized_text = src
|
|
45
|
+
byte_offset = 0
|
|
46
|
+
char_offset = 0
|
|
47
|
+
|
|
48
|
+
matches = list(self._PATT.finditer(src))
|
|
49
|
+
for m in matches:
|
|
50
|
+
whole = m.group(0)
|
|
51
|
+
start, end = m.span()
|
|
52
|
+
adj_from = self._utf16_len_java_style(src[:start]) - byte_offset
|
|
53
|
+
adj_char_from = start - char_offset
|
|
54
|
+
|
|
55
|
+
gname = m.lastgroup
|
|
56
|
+
if not gname:
|
|
57
|
+
continue
|
|
58
|
+
if gname == "link":
|
|
59
|
+
inner = m.group("link_text") or ""
|
|
60
|
+
link_href = m.group("link_url")
|
|
61
|
+
else:
|
|
62
|
+
inner = m.group(f"{gname}_c") or ""
|
|
63
|
+
link_href = None
|
|
64
|
+
|
|
65
|
+
if inner == "":
|
|
66
|
+
continue
|
|
67
|
+
|
|
68
|
+
content_utf16_len = self._utf16_len_java_style(inner)
|
|
69
|
+
|
|
70
|
+
part: Dict[str, Any] = {
|
|
71
|
+
"type": self._TYPE_MAP.get(gname, "Unknown"),
|
|
72
|
+
"from_index": adj_from,
|
|
73
|
+
"length": content_utf16_len,
|
|
74
|
+
}
|
|
75
|
+
if link_href:
|
|
76
|
+
part["link_url"] = link_href
|
|
77
|
+
payload_parts.append(part)
|
|
78
|
+
normalized_text = (
|
|
79
|
+
normalized_text[:adj_char_from] + inner + normalized_text[end - char_offset :]
|
|
80
|
+
)
|
|
81
|
+
byte_offset += self._utf16_len_java_style(whole) - content_utf16_len
|
|
82
|
+
char_offset += (end - start) - len(inner)
|
|
83
|
+
|
|
84
|
+
result: Dict[str, Any] = {"text": normalized_text.strip()}
|
|
85
|
+
if payload_parts:
|
|
86
|
+
result["metadata"] = {"meta_data_parts": payload_parts}
|
|
87
|
+
|
|
88
|
+
return result
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def parse(self, text: str, parse_mode: str = "MARKDOWN") -> Dict[str, Any]:
|
|
92
|
+
return self.transcribe(text, mode=parse_mode)
|
rubka/update.py
CHANGED
|
@@ -292,6 +292,7 @@ class Message:
|
|
|
292
292
|
self.is_executable = None
|
|
293
293
|
self.is_font = None
|
|
294
294
|
self.metadata = self.raw_data.get("metadata", {})
|
|
295
|
+
self.is_metadata = self.metadata
|
|
295
296
|
self.meta_parts = self.metadata.get("meta_data_parts", [])
|
|
296
297
|
self.has_metadata = bool(self.meta_parts)
|
|
297
298
|
self.meta_types = [part.get("type") for part in self.meta_parts] if self.has_metadata else []
|
|
@@ -366,7 +367,7 @@ class Message:
|
|
|
366
367
|
self.bot.sessions[self.chat_id] = {}
|
|
367
368
|
return self.bot.sessions[self.chat_id]
|
|
368
369
|
|
|
369
|
-
def reply(self, text: str, delete_after: int = None, **kwargs):
|
|
370
|
+
def reply(self, text: str, delete_after: int = None,parse_mode : Optional[Literal["HTML", "Markdown"]] = None , **kwargs):
|
|
370
371
|
async def _reply_async():
|
|
371
372
|
send_func = self.bot.send_message
|
|
372
373
|
if inspect.iscoroutinefunction(send_func):
|
|
@@ -375,6 +376,7 @@ class Message:
|
|
|
375
376
|
text,
|
|
376
377
|
reply_to_message_id=self.message_id,
|
|
377
378
|
delete_after=delete_after,
|
|
379
|
+
parse_mode=parse_mode,
|
|
378
380
|
**kwargs
|
|
379
381
|
)
|
|
380
382
|
else:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: Rubka
|
|
3
|
-
Version: 7.1.
|
|
3
|
+
Version: 7.1.11
|
|
4
4
|
Summary: Rubika: A Python library for interacting with the Rubika Bot API. This library provides an easy-to-use interface to send messages, polls, stickers, media files, manage groups and channels, handle inline keyboards, and implement advanced bot features like subscription management, user authentication, and message handling. Ideal for developers looking to automate and extend their Rubika bots with Python.
|
|
5
5
|
Home-page: https://github.com/Mahdy-Ahmadi/Rubka
|
|
6
6
|
Download-URL: https://github.com/Mahdy-Ahmadi/rubka/archive/refs/tags/v6.6.4.zip
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
rubka/__init__.py,sha256=P6IBiORfp-GqKHe5LZ-5lldWyG7tnrUYUcAQDUgwXmY,1973
|
|
2
|
-
rubka/api.py,sha256=
|
|
3
|
-
rubka/asynco.py,sha256=
|
|
2
|
+
rubka/api.py,sha256=b33Rbbfz5LdWBuRHdG-sxThDCHaIimJAJDQGWcMsF1Q,68477
|
|
3
|
+
rubka/asynco.py,sha256=7bolbIoMqv3IQtQ07-DzNHgE027TYRETfV9GvJL9UhM,119357
|
|
4
4
|
rubka/button.py,sha256=woSzZVd5MtTqOrP-YgkH5b0GS9y4DuKBsFSc9-KuLnk,13320
|
|
5
5
|
rubka/config.py,sha256=Bck59xkOiqioLv0GkQ1qPGnBXVctz1hKk6LT4h2EPx0,78
|
|
6
|
-
rubka/context.py,sha256=
|
|
6
|
+
rubka/context.py,sha256=brl7WXe4nzpLpcaMiOLVMfOs8BFTU5z5Sw6AIecCtOA,42492
|
|
7
7
|
rubka/decorators.py,sha256=hGwUoE4q2ImrunJIGJ_kzGYYxQf1ueE0isadqraKEts,1157
|
|
8
8
|
rubka/exceptions.py,sha256=DDOGIHEMoliHNW5E7C_s38WZgqqMBv9812fcJGvj7TY,1173
|
|
9
9
|
rubka/filters.py,sha256=DY1bdkpRKIiLtVcy6X3hOnlGPcVOK4HFb3QgmaPx6Oo,12116
|
|
@@ -12,9 +12,10 @@ rubka/jobs.py,sha256=GvLMLsVhcSEzRTgkvnPISPEBN71suW2xXI0hUaUZPTo,378
|
|
|
12
12
|
rubka/keyboards.py,sha256=7nr-dT2bQJVQnQ6RMWPTSjML6EEk6dsBx-4d8pab8xk,488
|
|
13
13
|
rubka/keypad.py,sha256=yGsNt8W5HtUFBzVF1m_p7GySlu1hwIcSvXZ4BTdrlvg,9558
|
|
14
14
|
rubka/logger.py,sha256=J2I6NiK1z32lrAzC4H1Et6WPMBXxXGCVUsW4jgcAofs,289
|
|
15
|
+
rubka/metadata.py,sha256=xZwJ962vBlTUTDqsrbztjNlGiGPZ7LdtuWB8S6iEeew,3202
|
|
15
16
|
rubka/rubino.py,sha256=HOILsm2zOIRe9EW1hxhLinhjwE_TvFrOAxBsg9T_L5E,61701
|
|
16
17
|
rubka/tv.py,sha256=rBoyCadCH3I3YqQGrQYv_dLtTg1I63AzVf1orn-hbko,5724
|
|
17
|
-
rubka/update.py,sha256=
|
|
18
|
+
rubka/update.py,sha256=brl7WXe4nzpLpcaMiOLVMfOs8BFTU5z5Sw6AIecCtOA,42492
|
|
18
19
|
rubka/utils.py,sha256=XUQUZxQt9J2f0X5hmAH_MH1kibTAfdT1T4AaBkBhBBs,148
|
|
19
20
|
rubka/adaptorrubka/__init__.py,sha256=6o2tCXnVeES7nx-LjnzsuMqjKcWIm9qwKficLE54s-U,83
|
|
20
21
|
rubka/adaptorrubka/enums.py,sha256=cyiakExmZi-QQpYuf_A93HQvfZVmyG_0uVuvTTNT5To,1053
|
|
@@ -37,8 +38,8 @@ rubka/adaptorrubka/types/socket/message.py,sha256=0WgLMZh4eow8Zn7AiSX4C3GZjQTkIg
|
|
|
37
38
|
rubka/adaptorrubka/utils/__init__.py,sha256=OgCFkXdNFh379quNwIVOAWY2NP5cIOxU5gDRRALTk4o,54
|
|
38
39
|
rubka/adaptorrubka/utils/configs.py,sha256=nMUEOJh1NqDJsf9W9PurkN_DLYjO6kKPMm923i4Jj_A,492
|
|
39
40
|
rubka/adaptorrubka/utils/utils.py,sha256=5-LioLNYX_TIbQGDeT50j7Sg9nAWH2LJUUs-iEXpsUY,8816
|
|
40
|
-
rubka-7.1.
|
|
41
|
-
rubka-7.1.
|
|
42
|
-
rubka-7.1.
|
|
43
|
-
rubka-7.1.
|
|
44
|
-
rubka-7.1.
|
|
41
|
+
rubka-7.1.11.dist-info/METADATA,sha256=mHqoY8NM5mtJkKEVtvmHotPgea4eW45KaztqFGrQClg,34645
|
|
42
|
+
rubka-7.1.11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
43
|
+
rubka-7.1.11.dist-info/entry_points.txt,sha256=4aESuUmuUOALMUy7Kucv_Gb5YlqhsJmTmdXLlZU9sJ0,46
|
|
44
|
+
rubka-7.1.11.dist-info/top_level.txt,sha256=vy2A4lot11cRMdQS-F4HDCIXL3JK8RKfu7HMDkezJW4,6
|
|
45
|
+
rubka-7.1.11.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|