Rubka 1.6.0__tar.gz → 1.7.2__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.6.0
3
+ Version: 1.7.2
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.6.0
3
+ Version: 1.7.2
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
@@ -24,13 +24,19 @@ class Robot:
24
24
  try:
25
25
  response = self.session.post(url, json=data, timeout=10)
26
26
  response.raise_for_status()
27
- json_resp = response.json()
28
- logger.debug(f"API Response from {method}: {json_resp}")
27
+ try:
28
+ json_resp = response.json()
29
+ except ValueError:
30
+ logger.error(f"Invalid JSON response from {method}: {response.text}")
31
+ raise APIRequestError(f"Invalid JSON response: {response.text}")
32
+ if method != "getUpdates":logger.debug(f"API Response from {method}: {json_resp}")
33
+
29
34
  return json_resp
30
35
  except requests.RequestException as e:
31
36
  logger.error(f"API request failed: {e}")
32
37
  raise APIRequestError(f"API request failed: {e}") from e
33
38
 
39
+
34
40
  def get_me(self) -> Dict[str, Any]:
35
41
  """Get info about the bot itself."""
36
42
  return self._post("getMe", {})
@@ -47,19 +53,16 @@ class Robot:
47
53
 
48
54
 
49
55
  def _process_update(self, update: Dict[str, Any]):
50
- update_data = update.get('update', {})
51
- if update_data.get('type') == 'NewMessage':
52
- msg = update_data.get('new_message', {})
53
- chat_id = update_data.get('chat_id')
56
+ if update.get('type') == 'NewMessage':
57
+ msg = update.get('new_message', {})
58
+ chat_id = update.get('chat_id')
54
59
  message_id = msg.get('message_id')
55
60
  sender_id = msg.get('sender_id')
56
61
  text = msg.get('text')
57
62
 
58
63
  if self._message_handler:
59
64
  handler = self._message_handler
60
- context = Message(bot=self,chat_id=chat_id,message_id=message_id,sender_id=sender_id,text=text,raw_data=msg)
61
-
62
-
65
+ context = Message(bot=self, chat_id=chat_id, message_id=message_id, sender_id=sender_id, text=text, raw_data=msg)
63
66
 
64
67
  if handler["commands"]:
65
68
  if not context.text or not context.text.startswith("/"):
@@ -79,19 +82,21 @@ class Robot:
79
82
 
80
83
 
81
84
 
85
+
82
86
  def run(self):
83
87
  print("Bot started running...")
84
88
  while True:
85
89
  try:
86
90
  updates = self.get_updates(offset_id=self._offset_id, limit=10)
87
91
  if updates and updates.get('data'):
88
- for update in updates['data']:
92
+ for update in updates['data'].get('updates', []):
89
93
  self._process_update(update)
90
- self._offset_id = update.get('update_id', self._offset_id)
94
+ self._offset_id = updates['data'].get('next_offset_id', self._offset_id)
91
95
  except Exception as e:
92
96
  print(f"Error in run loop: {e}")
93
- logger.error(f"API request failed: {e}")
97
+ #logger.error(f"API request failed: {e}")
94
98
  raise APIRequestError(f"API request failed: {e}") from e
99
+
95
100
  def send_message(
96
101
  self,
97
102
  chat_id: str,
@@ -8,7 +8,7 @@ except FileNotFoundError:
8
8
 
9
9
  setup(
10
10
  name='Rubka',
11
- version='1.6.0',
11
+ version='1.7.2',
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
File without changes
File without changes
File without changes