Rubka 6.4.2__py3-none-any.whl → 6.4.6__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 CHANGED
@@ -621,7 +621,7 @@ class Robot:
621
621
  continue
622
622
 
623
623
  threading.Thread(target=handler["func"], args=(self, context), daemon=True).start()
624
- return
624
+ continue
625
625
 
626
626
  def get_updates(
627
627
  self,
@@ -1191,17 +1191,7 @@ class Robot:
1191
1191
  raise ValueError(f"Invalid media type. Must be one of {allowed}")
1192
1192
  result = self._post("requestSendFile", {"type": media_type})
1193
1193
  return result.get("data", {}).get("upload_url")
1194
- def _send_uploaded_file(
1195
- self,
1196
- chat_id: str,
1197
- file_id: str,
1198
- text: Optional[str] = None,
1199
- chat_keypad: Optional[Dict[str, Any]] = None,
1200
- inline_keypad: Optional[Dict[str, Any]] = None,
1201
- disable_notification: bool = False,
1202
- reply_to_message_id: Optional[str] = None,
1203
- chat_keypad_type: Optional[Literal["New", "Removed", "None"]] = "None"
1204
- ) -> Dict[str, Any]:
1194
+ 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", "Removed", "None"]] = "None") -> Dict[str, Any]:
1205
1195
  payload = {
1206
1196
  "chat_id": chat_id,
1207
1197
  "file_id": file_id,
@@ -1216,7 +1206,25 @@ class Robot:
1216
1206
  if reply_to_message_id:
1217
1207
  payload["reply_to_message_id"] = str(reply_to_message_id)
1218
1208
 
1219
- return self._post("sendFile", payload)
1209
+ resp = self._post("sendFile", payload)
1210
+ message_id_put = resp["data"]["message_id"]
1211
+ result = {
1212
+ "status": resp.get("status"),
1213
+ "status_det": resp.get("status_det"),
1214
+ "file_id": file_id,
1215
+ "text":text,
1216
+ "message_id": message_id_put,
1217
+ "send_to_chat_id": chat_id,
1218
+ "reply_to_message_id": reply_to_message_id,
1219
+ "disable_notification": disable_notification,
1220
+ "type_file": type_file,
1221
+ "raw_response": resp,
1222
+ "chat_keypad":chat_keypad,
1223
+ "inline_keypad":inline_keypad,
1224
+ "chat_keypad_type":chat_keypad_type
1225
+ }
1226
+ import json
1227
+ return json.dumps(result, ensure_ascii=False, indent=4)
1220
1228
  def send_file(
1221
1229
  self,
1222
1230
  chat_id: str,
rubka/asynco.py CHANGED
@@ -9,6 +9,8 @@ try:
9
9
  from .context import Message, InlineMessage
10
10
  except (ImportError, ModuleNotFoundError):
11
11
  from context import Message, InlineMessage
12
+ class FeatureNotAvailableError(Exception):
13
+ pass
12
14
 
13
15
  from tqdm.asyncio import tqdm
14
16
  from urllib.parse import urlparse, parse_qs
@@ -16,7 +18,7 @@ class InvalidTokenError(Exception):pass
16
18
  import mimetypes
17
19
  from pathlib import Path
18
20
  import time
19
- import datetime
21
+ import datetime,json
20
22
  import tempfile
21
23
  from tqdm import tqdm
22
24
  import os
@@ -32,7 +34,31 @@ def install_package(package_name: str) -> bool:
32
34
  return True
33
35
  except Exception:
34
36
  return False
35
-
37
+ class MessageResponse:
38
+ def __init__(self, resp: dict, chat_id: str, file_id: str,
39
+ type_file: str, reply_to_message_id: str,
40
+ disable_notification: bool, text: str = None,
41
+ chat_keypad=None, inline_keypad=None, chat_keypad_type="None"):
42
+
43
+ self.status = resp.get("status")
44
+ self.status_det = resp.get("status_det")
45
+ self.file_id = file_id
46
+ self.message_id = resp["data"].get("message_id")
47
+ self.send_to_chat_id = chat_id
48
+ self.reply_to_message_id = reply_to_message_id
49
+ self.disable_notification = disable_notification
50
+ self.type_file = type_file
51
+ self.text = text
52
+ self.chat_keypad = chat_keypad
53
+ self.inline_keypad = inline_keypad
54
+ self.chat_keypad_type = chat_keypad_type
55
+ self.raw_response = resp
56
+
57
+ def to_dict(self):
58
+ return self.__dict__
59
+
60
+ def to_json(self):
61
+ return json.dumps(self.__dict__, ensure_ascii=False, indent=4)
36
62
  def get_importlib_metadata():
37
63
  """Dynamically imports and returns metadata functions from importlib."""
38
64
  try:
@@ -677,12 +703,12 @@ class Robot:
677
703
 
678
704
  if not handler_info["commands"] and not handler_info["filters"]:
679
705
  asyncio.create_task(handler_info["func"](self, context))
680
- return
706
+ continue
681
707
 
682
708
 
683
709
  if handler_info["commands"] or handler_info["filters"]:
684
- asyncio.create_task(handler_info["func"](self, context))
685
- return
710
+ asyncio.create_task(handler_info["func"](self, context))#jaq
711
+ continue
686
712
 
687
713
  async def get_updates(self, offset_id: Optional[str] = None, limit: Optional[int] = None) -> Dict[str, Any]:
688
714
  data = {}
@@ -1481,17 +1507,19 @@ class Robot:
1481
1507
 
1482
1508
  data = aiohttp.FormData()
1483
1509
  data.add_field('file', file_progress_generator(path), filename=name, content_type='application/octet-stream')
1484
-
1485
- async with session.post(upload_url, data=data) as response:
1486
- progress_bar.close()
1487
- if response.status != 200:
1488
- raise Exception(f"Upload failed ({response.status}): {await response.text()}")
1489
-
1490
- json_data = await response.json()
1491
- if is_temp_file:
1492
- os.remove(path)
1493
- print(json_data)
1494
- return json_data.get('data', {}).get('file_id')
1510
+ try:
1511
+ async with session.post(upload_url, data=data) as response:
1512
+ progress_bar.close()
1513
+ if response.status != 200:
1514
+ raise Exception(f"Upload failed ({response.status}): {await response.text()}")
1515
+
1516
+ json_data = await response.json()
1517
+ if is_temp_file:
1518
+ os.remove(path)
1519
+ print(json_data)
1520
+ return json_data.get('data', {}).get('file_id')
1521
+ except :
1522
+ raise FeatureNotAvailableError(f"files is not currently supported by the server.")
1495
1523
 
1496
1524
 
1497
1525
  def get_extension(content_type: str) -> str:
@@ -1584,19 +1612,37 @@ class Robot:
1584
1612
  except Exception as e:
1585
1613
  raise Exception(f"An error occurred while downloading the file: {e}")
1586
1614
 
1587
- async def get_upload_url(self, media_type: Literal['File', 'Image', 'Voice', 'Music', 'Gif', 'Video']) -> str:
1588
- allowed = ['File', 'Image', 'Voice', 'Music', 'Gif', 'Video']
1615
+ async def get_upload_url(self, media_type: Literal['File', 'Image', 'voice', 'Music', 'Gif', 'Video']) -> str:
1616
+ allowed = ['File', 'Image', 'voice', 'Music', 'Gif', 'Video']
1589
1617
  if media_type not in allowed:
1590
1618
  raise ValueError(f"Invalid media type. Must be one of {allowed}")
1591
1619
  result = await self._post("requestSendFile", {"type": media_type})
1592
1620
  return result.get("data", {}).get("upload_url")
1593
1621
 
1594
- async def _send_uploaded_file(self, chat_id: str, file_id: str, 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", "Removed", "None"]] = "None") -> Dict[str, Any]:
1622
+ 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", "Removed", "None"]] = "None") -> Dict[str, Any]:
1595
1623
  payload = {"chat_id": chat_id, "file_id": file_id, "text": text, "disable_notification": disable_notification, "chat_keypad_type": chat_keypad_type}
1596
1624
  if chat_keypad: payload["chat_keypad"] = chat_keypad
1597
1625
  if inline_keypad: payload["inline_keypad"] = inline_keypad
1598
1626
  if reply_to_message_id: payload["reply_to_message_id"] = str(reply_to_message_id)
1599
- return await self._post("sendFile", payload)
1627
+ payload["time"] = "10"
1628
+ resp = await self._post("sendFile", payload)
1629
+ message_id_put = resp["data"]["message_id"]
1630
+ result = {
1631
+ "status": resp.get("status"),
1632
+ "status_det": resp.get("status_det"),
1633
+ "file_id": file_id,
1634
+ "text":text,
1635
+ "message_id": message_id_put,
1636
+ "send_to_chat_id": chat_id,
1637
+ "reply_to_message_id": reply_to_message_id,
1638
+ "disable_notification": disable_notification,
1639
+ "type_file": type_file,
1640
+ "raw_response": resp,
1641
+ "chat_keypad":chat_keypad,
1642
+ "inline_keypad":inline_keypad,
1643
+ "chat_keypad_type":chat_keypad_type
1644
+ }
1645
+ return json.dumps(result, ensure_ascii=False, indent=4)
1600
1646
 
1601
1647
  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):
1602
1648
  if path:
@@ -1605,7 +1651,7 @@ class Robot:
1605
1651
  file_id = await self.upload_media_file(upload_url, file_name, path)
1606
1652
  if not file_id:
1607
1653
  raise ValueError("Either path or file_id must be provided.")
1608
- 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)
1654
+ 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)
1609
1655
 
1610
1656
  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", "Removed", "None"]] = "None") -> Dict[str, Any]:
1611
1657
  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)
@@ -1613,14 +1659,14 @@ class Robot:
1613
1659
  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)
1614
1660
  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", "Removed", "None"]] = "None") -> Dict[str, Any]:
1615
1661
  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)
1616
- async def send_music(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", "Removed", "None"]] = "None") -> Dict[str, Any]:
1617
- return await self._send_file_generic("Music", chat_id, path, file_id, text, file_name, inline_keypad, chat_keypad, reply_to_message_id, disable_notification, chat_keypad_type)
1662
+ async def send_music(self, chat_id: str, path: Optional[Union[str, Path]] = None, file_id: Optional[str] = None, text: Optional[str] = None, file_name: Optional[str] = "music", 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", "Removed", "None"]] = "None") -> Dict[str, Any]:
1663
+ return await self._send_file_generic("File", chat_id, path, file_id, text, f"{file_name}.ogg", inline_keypad, chat_keypad, reply_to_message_id, disable_notification, chat_keypad_type)
1618
1664
 
1619
1665
  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", "Removed", "None"]] = "None") -> Dict[str, Any]:
1620
1666
  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)
1621
1667
 
1622
1668
  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", "Removed", "None"]] = "None") -> Dict[str, Any]:
1623
- 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)
1669
+ 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)
1624
1670
 
1625
1671
  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", "Removed", "None"]] = "None") -> Dict[str, Any]:
1626
1672
  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)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Rubka
3
- Version: 6.4.2
3
+ Version: 6.4.6
4
4
  Summary: A Python library for interacting with Rubika Bot API.
5
5
  Home-page: https://github.com/Mahdy-Ahmadi/Rubka
6
6
  Download-URL: https://github.com/Mahdy-Ahmadi/rubka/blob/main/project_library.zip
@@ -1,6 +1,6 @@
1
1
  rubka/__init__.py,sha256=TR1DABU5Maz2eO62ZEFiwOqNU0dH6l6HZfqRUxeo4eY,194
2
- rubka/api.py,sha256=3Iahq3f6OzVf3op_d6RTFUtTvCfjB4NnqSVnC7dkgzo,61232
3
- rubka/asynco.py,sha256=WWB_-00KVEcAa1su3zj-9-NJfZhx45yCngF8bv4B6FA,75779
2
+ rubka/api.py,sha256=o5YM_KnDdoS0GRKYAXjy9d3xij2gdgmaDmn18ht9cok,61898
3
+ rubka/asynco.py,sha256=CcqSxKvfA1JSG1UDVn78GnImLS0LDdUic2xqCXK_9Cw,77829
4
4
  rubka/button.py,sha256=vU9OvWXCD4MRrTJ8Xmivd4L471-06zrD2qpZBTw5vjY,13305
5
5
  rubka/config.py,sha256=Bck59xkOiqioLv0GkQ1qPGnBXVctz1hKk6LT4h2EPx0,78
6
6
  rubka/context.py,sha256=2HWMy5yaPWE0lJFjRkVzG-8wUgPyugRHz25t4hpF0Ko,18341
@@ -34,7 +34,7 @@ rubka/adaptorrubka/types/socket/message.py,sha256=0WgLMZh4eow8Zn7AiSX4C3GZjQTkIg
34
34
  rubka/adaptorrubka/utils/__init__.py,sha256=OgCFkXdNFh379quNwIVOAWY2NP5cIOxU5gDRRALTk4o,54
35
35
  rubka/adaptorrubka/utils/configs.py,sha256=nMUEOJh1NqDJsf9W9PurkN_DLYjO6kKPMm923i4Jj_A,492
36
36
  rubka/adaptorrubka/utils/utils.py,sha256=5-LioLNYX_TIbQGDeT50j7Sg9nAWH2LJUUs-iEXpsUY,8816
37
- rubka-6.4.2.dist-info/METADATA,sha256=bUdDVVG9yIiuk65hUKPmfHvVo6_iTKbnIk8Pv3BnvIs,33335
38
- rubka-6.4.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
39
- rubka-6.4.2.dist-info/top_level.txt,sha256=vy2A4lot11cRMdQS-F4HDCIXL3JK8RKfu7HMDkezJW4,6
40
- rubka-6.4.2.dist-info/RECORD,,
37
+ rubka-6.4.6.dist-info/METADATA,sha256=tQy-9qciKVwDM4aLWdhR13Tkc-SLf1FxpsgLxRh0gKQ,33335
38
+ rubka-6.4.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
39
+ rubka-6.4.6.dist-info/top_level.txt,sha256=vy2A4lot11cRMdQS-F4HDCIXL3JK8RKfu7HMDkezJW4,6
40
+ rubka-6.4.6.dist-info/RECORD,,
File without changes