Rubka 1.3.0__tar.gz → 1.4.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Rubka
3
- Version: 1.3.0
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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Rubka
3
- Version: 1.3.0
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
@@ -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,
@@ -8,7 +8,7 @@ except FileNotFoundError:
8
8
 
9
9
  setup(
10
10
  name='Rubka',
11
- version='1.3.0',
11
+ version='1.4.0',
12
12
  description='A Python library for interacting with Rubika Bot API.',
13
13
  long_description=long_description,
14
14
  long_description_content_type='text/markdown',
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes