Rubka 1.6.0__py3-none-any.whl → 1.7.2__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
@@ -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,
@@ -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,5 +1,5 @@
1
1
  rubka/__init__.py,sha256=3f4H6Uj1ylrfBYlTHmTvzZSvaPJsdNhCocyX3Bbvuv0,254
2
- rubka/api.py,sha256=-68MTjIHuQ--1LBHW1-mnGVdz6XUOhHsR7F4J2jGo2k,9216
2
+ rubka/api.py,sha256=993Dj325opTfsWnhEd0mFyAbDyxkA9UR9BT2mxmJ4GY,9457
3
3
  rubka/config.py,sha256=Bck59xkOiqioLv0GkQ1qPGnBXVctz1hKk6LT4h2EPx0,78
4
4
  rubka/context.py,sha256=dv7EJz3xu6N9ktbZnzMlmtgxAB6oCwkGKbs57hTWx64,11526
5
5
  rubka/decorators.py,sha256=hGwUoE4q2ImrunJIGJ_kzGYYxQf1ueE0isadqraKEts,1157
@@ -9,7 +9,7 @@ rubka/keyboards.py,sha256=7nr-dT2bQJVQnQ6RMWPTSjML6EEk6dsBx-4d8pab8xk,488
9
9
  rubka/keypad.py,sha256=uJ9ocsTR2lPPJDER48h0p-9dU1Cv9FD4Qcm_--u6H1M,428
10
10
  rubka/logger.py,sha256=VhxaryxN_SqUmCX39nym2A6JiEPI-jEG22htPBP88Y4,289
11
11
  rubka/utils.py,sha256=XUQUZxQt9J2f0X5hmAH_MH1kibTAfdT1T4AaBkBhBBs,148
12
- rubka-1.6.0.dist-info/METADATA,sha256=C0N9aXmICglQiazwyq9PgvxETjCbemeLvSBBW7VtkJk,8168
13
- rubka-1.6.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
- rubka-1.6.0.dist-info/top_level.txt,sha256=vy2A4lot11cRMdQS-F4HDCIXL3JK8RKfu7HMDkezJW4,6
15
- rubka-1.6.0.dist-info/RECORD,,
12
+ rubka-1.7.2.dist-info/METADATA,sha256=hsTcLNuC4_5wiqt-kuUIPPri14dVvtm_PErXqMv6Amg,8168
13
+ rubka-1.7.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
+ rubka-1.7.2.dist-info/top_level.txt,sha256=vy2A4lot11cRMdQS-F4HDCIXL3JK8RKfu7HMDkezJW4,6
15
+ rubka-1.7.2.dist-info/RECORD,,
File without changes