Rubka 0.1.2__py3-none-any.whl → 1.4.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.
rubka/api.py CHANGED
@@ -2,6 +2,7 @@ import requests
2
2
  from typing import List, Optional, Dict, Any, Literal
3
3
  from .exceptions import APIRequestError
4
4
  from .logger import logger
5
+ from typing import Callable
5
6
 
6
7
  API_URL = "https://botapi.rubika.ir/v3"
7
8
 
@@ -13,6 +14,7 @@ class Robot:
13
14
 
14
15
  def __init__(self, token: str):
15
16
  self.token = token
17
+ self._offset_id = None
16
18
  self.session = requests.Session()
17
19
  logger.info(f"Initialized RubikaBot with token: {token[:8]}***")
18
20
 
@@ -31,7 +33,42 @@ class Robot:
31
33
  def get_me(self) -> Dict[str, Any]:
32
34
  """Get info about the bot itself."""
33
35
  return self._post("getMe", {})
34
-
36
+ def on_message(self):
37
+ def decorator(func: Callable):
38
+ self._message_handler = func
39
+ return func
40
+ return decorator
41
+
42
+ def _process_update(self, update: Dict[str, Any]):
43
+ if 'update' in update and update['update'].get('type') == 'NewMessage':
44
+ msg = update['update']['new_message']
45
+ chat_id = update['update']['chat_id']
46
+ message_id = msg.get('message_id')
47
+ text = msg.get('text')
48
+ sender_id = msg.get('sender_id')
49
+
50
+ if self._message_handler:
51
+ self._message_handler(
52
+ bot=self,
53
+ chat_id=chat_id,
54
+ message_id=message_id,
55
+ text=text,
56
+ sender_id=sender_id
57
+ )
58
+
59
+ def run(self):
60
+ print("Bot started running...")
61
+ while True:
62
+ try:
63
+ updates = self.get_updates(offset_id=self._offset_id, limit=10)
64
+ if updates and updates.get('data'):
65
+ for update in updates['data']:
66
+ self._process_update(update)
67
+ self._offset_id = update.get('update_id', self._offset_id)
68
+ except Exception as e:
69
+ print(f"Error in run loop: {e}")
70
+ logger.error(f"API request failed: {e}")
71
+ raise APIRequestError(f"API request failed: {e}") from e
35
72
  def send_message(
36
73
  self,
37
74
  chat_id: str,
rubka/exceptions.py CHANGED
@@ -1,4 +1,3 @@
1
1
  class APIRequestError(Exception):
2
2
  """Raised when an API request fails."""
3
- raise Exception
4
3
  pass
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Rubka
3
- Version: 0.1.2
3
+ Version: 1.4.0
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/archive/refs/tags/v0.1.0.tar.gz
@@ -1,12 +1,12 @@
1
1
  rubka/__init__.py,sha256=3f4H6Uj1ylrfBYlTHmTvzZSvaPJsdNhCocyX3Bbvuv0,254
2
- rubka/api.py,sha256=SJnuOXZdrj5llnkRltPBPNFXvixzaQDufWU5Zm7B8jk,6858
2
+ rubka/api.py,sha256=MIdMZTzOxxjrGwsVoGtFPVSQL-w06Hsm1UkNiSvCX8k,8378
3
3
  rubka/config.py,sha256=Bck59xkOiqioLv0GkQ1qPGnBXVctz1hKk6LT4h2EPx0,78
4
4
  rubka/decorators.py,sha256=hGwUoE4q2ImrunJIGJ_kzGYYxQf1ueE0isadqraKEts,1157
5
- rubka/exceptions.py,sha256=aJSPOmBWKfMSSLBznUmT5h1ckPmvk8wXDZZzSzESFcQ,111
5
+ rubka/exceptions.py,sha256=tujZt1XrhWaw-lmdeVadVceUptpw4XzNgE44sAAY0gs,90
6
6
  rubka/keyboards.py,sha256=7nr-dT2bQJVQnQ6RMWPTSjML6EEk6dsBx-4d8pab8xk,488
7
7
  rubka/logger.py,sha256=VhxaryxN_SqUmCX39nym2A6JiEPI-jEG22htPBP88Y4,289
8
8
  rubka/utils.py,sha256=XUQUZxQt9J2f0X5hmAH_MH1kibTAfdT1T4AaBkBhBBs,148
9
- rubka-0.1.2.dist-info/METADATA,sha256=2nIkRcBZ4PL2-Iyht8pXqfRKeycPOYmzcz-QC0iyPuI,8168
10
- rubka-0.1.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
- rubka-0.1.2.dist-info/top_level.txt,sha256=vy2A4lot11cRMdQS-F4HDCIXL3JK8RKfu7HMDkezJW4,6
12
- rubka-0.1.2.dist-info/RECORD,,
9
+ rubka-1.4.0.dist-info/METADATA,sha256=bE_y3oJikxG6WP8HAjko3AkcKS98JR48jgPAkEEMrfo,8168
10
+ rubka-1.4.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
+ rubka-1.4.0.dist-info/top_level.txt,sha256=vy2A4lot11cRMdQS-F4HDCIXL3JK8RKfu7HMDkezJW4,6
12
+ rubka-1.4.0.dist-info/RECORD,,
File without changes