Rubka 6.6.4__py3-none-any.whl → 6.6.8__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/__init__.py CHANGED
@@ -1,6 +1,75 @@
1
+ """
2
+ 🔹 Synchronous Example
3
+ ```python
4
+ from rubka import Robot, Message
5
+
6
+ bot = Robot(token="YOUR_BOT_TOKEN")
7
+
8
+ @bot.on_message(commands=["start", "help"])
9
+ def handle_start(bot: Robot, message: Message):
10
+ message.reply("👋 Hello! Welcome to the Rubka bot (sync example).")
11
+
12
+ bot.run()
13
+ ```
14
+
15
+ Explanation
16
+
17
+ Robot is created with your bot token.
18
+ @bot.on_message registers a handler for incoming messages.
19
+
20
+ The function handle_start runs synchronously (step by step, blocking).
21
+
22
+ message.reply sends a message back to the user immediately.
23
+
24
+ Finally, bot.run() starts the event loop and keeps the bot running.
25
+
26
+ This approach is simpler and best for small bots or basic logic where you don’t need concurrency.
27
+
28
+ 🔹 Asynchronous Example
29
+ ```python
30
+ import asyncio
31
+ from rubka.asynco import Robot, Message
32
+
33
+ bot = Robot(token="YOUR_BOT_TOKEN")
34
+
35
+ @bot.on_message(commands=["start", "help"])
36
+ async def handle_start(bot: Robot, message: Message):
37
+ await message.reply("⚡ Hello! This is the async version of Rubka.")
38
+
39
+ async def main():
40
+ await bot.run()
41
+
42
+ asyncio.run(main())
43
+ ```
44
+ Explanation
45
+
46
+ Uses rubka.asynco.Robot for asynchronous operation.
47
+
48
+ The handler handle_start is defined with async def.
49
+
50
+ await message.reply(...) is non-blocking: the bot can process other tasks while waiting for Rubika’s response.
51
+
52
+ asyncio.run(main()) starts the async event loop.
53
+
54
+ This approach is more powerful and recommended for larger bots or when you:
55
+
56
+ Need to call external APIs.
57
+
58
+ Handle multiple long-running tasks.
59
+
60
+ Want better performance and scalability.
61
+
62
+ 👉 In short:
63
+
64
+ Sync = simple, step-by-step, blocking.
65
+
66
+ Async = scalable, concurrent, non-blocking.
67
+ """
68
+
1
69
  from .api import Robot
2
70
  from .rubino import Bot
3
71
  from .exceptions import APIRequestError
72
+ from .rubino import Bot as rubino
4
73
 
5
74
  __all__ = [
6
75
  "Robot",
rubka/api.py CHANGED
@@ -4,6 +4,7 @@ from .exceptions import APIRequestError
4
4
  from .adaptorrubka import Client as Client_get
5
5
  from .logger import logger
6
6
  from . import filters
7
+ from . import helpers
7
8
  from typing import Callable
8
9
  from .context import Message,InlineMessage
9
10
  from typing import Optional, Union, Literal, Dict, Any
rubka/asynco.py CHANGED
@@ -1666,16 +1666,103 @@ class Robot:
1666
1666
  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)
1667
1667
  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]:
1668
1668
  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)
1669
- 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]:
1670
- 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)
1669
+
1670
+ async def send_music(
1671
+ self,
1672
+ chat_id: str,
1673
+ path: Optional[Union[str, Path]] = None,
1674
+ file_id: Optional[str] = None,
1675
+ text: Optional[str] = None,
1676
+ file_name: Optional[str] = None,
1677
+ inline_keypad: Optional[Dict[str, Any]] = None,
1678
+ chat_keypad: Optional[Dict[str, Any]] = None,
1679
+ reply_to_message_id: Optional[str] = None,
1680
+ disable_notification: bool = False,
1681
+ chat_keypad_type: Optional[Literal["New", "Removed", "None"]] = "None"
1682
+ ) -> Dict[str, Any]:
1683
+ valid_extensions = {"ogg", "oga", "opus", "flac"}
1684
+ extension = "flac"
1685
+ if path:
1686
+ path_str = str(path)
1687
+ if path_str.startswith("http://") or path_str.startswith("https://"):
1688
+ parsed = urlparse(path_str)
1689
+ base_name = os.path.basename(parsed.path)
1690
+ else:
1691
+ base_name = os.path.basename(path_str)
1692
+ name, ext = os.path.splitext(base_name)
1693
+
1694
+ if file_name is None or not file_name.strip():
1695
+ file_name = name or "music"
1696
+ ext = ext.lower().replace(".", "")
1697
+ if ext in valid_extensions:
1698
+ extension = ext
1699
+ else:
1700
+ if file_name is None:
1701
+ file_name = "music"
1702
+ return await self._send_file_generic(
1703
+ "File",
1704
+ chat_id,
1705
+ path,
1706
+ file_id,
1707
+ text,
1708
+ f"{file_name}.{extension}",
1709
+ inline_keypad,
1710
+ chat_keypad,
1711
+ reply_to_message_id,
1712
+ disable_notification,
1713
+ chat_keypad_type
1714
+ )
1671
1715
  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]:
1672
1716
  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)
1673
1717
  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]:
1674
1718
  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)
1675
1719
  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]:
1676
1720
  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)
1677
- async def send_gif(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]:
1678
- return await self._send_file_generic("Gif", chat_id, path, file_id, text, file_name, inline_keypad, chat_keypad, reply_to_message_id, disable_notification, chat_keypad_type)
1721
+ async def send_gif(
1722
+ self,
1723
+ chat_id: str,
1724
+ path: Optional[Union[str, Path]] = None,
1725
+ file_id: Optional[str] = None,
1726
+ text: Optional[str] = None,
1727
+ file_name: Optional[str] = None,
1728
+ inline_keypad: Optional[Dict[str, Any]] = None,
1729
+ chat_keypad: Optional[Dict[str, Any]] = None,
1730
+ reply_to_message_id: Optional[str] = None,
1731
+ disable_notification: bool = False,
1732
+ chat_keypad_type: Optional[Literal["New", "Removed", "None"]] = "None"
1733
+ ) -> Dict[str, Any]:
1734
+ valid_extensions = {"gif"}
1735
+ extension = "gif"
1736
+ if path:
1737
+ path_str = str(path)
1738
+ if path_str.startswith("http://") or path_str.startswith("https://"):
1739
+ parsed = urlparse(path_str)
1740
+ base_name = os.path.basename(parsed.path)
1741
+ else:
1742
+ base_name = os.path.basename(path_str)
1743
+ name, ext = os.path.splitext(base_name)
1744
+
1745
+ if file_name is None or not file_name.strip():
1746
+ file_name = name or "gif"
1747
+ ext = ext.lower().replace(".", "")
1748
+ if ext in valid_extensions:
1749
+ extension = ext
1750
+ else:
1751
+ if file_name is None:
1752
+ file_name = "gif"
1753
+ return await self._send_file_generic(
1754
+ "File",
1755
+ chat_id,
1756
+ path,
1757
+ file_id,
1758
+ text,
1759
+ f"{file_name}.{extension}",
1760
+ inline_keypad,
1761
+ chat_keypad,
1762
+ reply_to_message_id,
1763
+ disable_notification,
1764
+ chat_keypad_type
1765
+ )
1679
1766
  async def forward_message(self, from_chat_id: str, message_id: str, to_chat_id: str, disable_notification: bool = False) -> Dict[str, Any]:
1680
1767
  return await self._post("forwardMessage", {"from_chat_id": from_chat_id, "message_id": message_id, "to_chat_id": to_chat_id, "disable_notification": disable_notification})
1681
1768
  async def edit_message_text(self, chat_id: str, message_id: str, text: str) -> Dict[str, Any]: