nonebot-adapter-matrix 0.2.2__tar.gz → 0.2.3__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.
Files changed (21) hide show
  1. {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/PKG-INFO +1 -1
  2. {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/adapter.py +32 -11
  3. {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/api/client.pyi +2 -2
  4. {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/api/handle.py +18 -26
  5. {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/pyproject.toml +1 -1
  6. {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/README.md +0 -0
  7. {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/__init__.py +0 -0
  8. {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/api/__init__.py +0 -0
  9. {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/api/client.py +0 -0
  10. {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/api/model.py +0 -0
  11. {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/api/types.py +0 -0
  12. {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/api/utils.py +0 -0
  13. {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/api/validation.py +0 -0
  14. {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/bot.py +0 -0
  15. {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/config.py +0 -0
  16. {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/event.py +0 -0
  17. {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/exception.py +0 -0
  18. {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/message.py +0 -0
  19. {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/oauth.py +0 -0
  20. {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/serialization.py +0 -0
  21. {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nonebot-adapter-matrix
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: Matrix adapter for nonebot2
5
5
  Keywords: nonebot,matrix,bot
6
6
  Author: elysia-best
@@ -158,7 +158,10 @@ class Adapter(BaseAdapter, HandleMixin):
158
158
  try:
159
159
  raw = json.loads(path.read_text(encoding="utf-8"))
160
160
  except (OSError, json.JSONDecodeError) as e:
161
- log("ERROR", f"Failed to read Matrix token store {path}", e)
161
+ log(
162
+ "ERROR",
163
+ f"Failed to read Matrix token store {path}: {type(e).__name__}: {e}",
164
+ )
162
165
  return {}
163
166
  if isinstance(raw, dict):
164
167
  return raw
@@ -225,7 +228,10 @@ class Adapter(BaseAdapter, HandleMixin):
225
228
  temp_path.write_text(payload + "\n", encoding="utf-8")
226
229
  temp_path.replace(path)
227
230
  except OSError as e:
228
- log("ERROR", f"Failed to write Matrix token store {path}", e)
231
+ log(
232
+ "ERROR",
233
+ f"Failed to write Matrix token store {path}: {type(e).__name__}: {e}",
234
+ )
229
235
  with contextlib.suppress(OSError):
230
236
  temp_path.unlink(missing_ok=True)
231
237
 
@@ -580,8 +586,8 @@ class Adapter(BaseAdapter, HandleMixin):
580
586
  except UnauthorizedException as refresh_error:
581
587
  log(
582
588
  "ERROR",
583
- f"Token refresh rejected (4xx) for {bot.self_id}",
584
- refresh_error,
589
+ f"Token refresh rejected (4xx) for {bot.self_id}: "
590
+ f"{type(refresh_error).__name__}: {refresh_error}",
585
591
  )
586
592
  if refresh_error.soft_logout:
587
593
  self_info = await self._relogin_if_soft_logout(bot)
@@ -596,8 +602,8 @@ class Adapter(BaseAdapter, HandleMixin):
596
602
  except Exception as refresh_error:
597
603
  log(
598
604
  "ERROR",
599
- f"Failed to refresh Matrix access token for {bot.self_id}",
600
- refresh_error,
605
+ f"Failed to refresh Matrix access token for {bot.self_id}: "
606
+ f"{type(refresh_error).__name__}: {refresh_error}",
601
607
  )
602
608
  else:
603
609
  log(
@@ -688,7 +694,10 @@ class Adapter(BaseAdapter, HandleMixin):
688
694
  try:
689
695
  token_resp = await self._run_oauth2_login(bot_info)
690
696
  except OAuth2Error as oauth_err:
691
- log("ERROR", "OAuth2 login failed", oauth_err)
697
+ log(
698
+ "ERROR",
699
+ f"OAuth2 login failed: {type(oauth_err).__name__}: {oauth_err}",
700
+ )
692
701
  raise
693
702
  self._apply_token_update(
694
703
  bot_info,
@@ -734,7 +743,10 @@ class Adapter(BaseAdapter, HandleMixin):
734
743
  except asyncio.CancelledError:
735
744
  raise
736
745
  except Exception as e:
737
- log("ERROR", "Matrix bot loop failed; retrying...", e)
746
+ log(
747
+ "ERROR",
748
+ f"Matrix bot loop failed; retrying... {type(e).__name__}: {e}",
749
+ )
738
750
  await asyncio.sleep(self.matrix_config.matrix_retry_interval)
739
751
  finally:
740
752
  if bot and bot.self_id in self.bots:
@@ -787,12 +799,18 @@ class Adapter(BaseAdapter, HandleMixin):
787
799
  except UnauthorizedException as e:
788
800
  if await self._handle_sync_unauthorized(bot, e):
789
801
  continue
790
- log("ERROR", f"Error while syncing Matrix bot {bot.self_id}", e)
802
+ log(
803
+ "ERROR",
804
+ f"Error while syncing Matrix bot {bot.self_id}: {type(e).__name__}: {e}",
805
+ )
791
806
  await asyncio.sleep(self.matrix_config.matrix_retry_interval)
792
807
  except asyncio.CancelledError:
793
808
  raise
794
809
  except Exception as e:
795
- log("ERROR", f"Error while syncing Matrix bot {bot.self_id}", e)
810
+ log(
811
+ "ERROR",
812
+ f"Error while syncing Matrix bot {bot.self_id}: {type(e).__name__}: {e}",
813
+ )
796
814
  await asyncio.sleep(self.matrix_config.matrix_retry_interval)
797
815
 
798
816
  async def _handle_sync(self, bot: Bot, sync: SyncResponse) -> None:
@@ -817,7 +835,10 @@ class Adapter(BaseAdapter, HandleMixin):
817
835
  try:
818
836
  await self._api_join_room(bot, room_id=room_id)
819
837
  except Exception as e:
820
- log("ERROR", f"Failed to auto-join room {room_id}", e)
838
+ log(
839
+ "ERROR",
840
+ f"Failed to auto-join room {room_id}: {type(e).__name__}: {e}",
841
+ )
821
842
  for room_id, room in sync.rooms.leave.items():
822
843
  event = LeaveEvent(type="m.room.leave", room_id=room_id, content={})
823
844
  await bot.handle_event(event)
@@ -1,8 +1,8 @@
1
1
  # This file is auto-generated by scripts/generate_client_pyi.py.
2
2
  # Do not edit this file directly.
3
- # Generated at: 2026-06-03T01:26:54Z
3
+ # Generated at: 2026-06-03T11:02:43Z
4
4
  # Source file: nonebot/adapters/matrix/api/handle.py
5
- # Source SHA256: ff69364f5ac8613550202c7feadeb6e2016c0ce634cb47ab8294b976eeb4734a
5
+ # Source SHA256: caabfb23da26fc722d6c007607d765f6ba7cdee5b7d40d6dd607fdb55886b838
6
6
  # Script SHA256: 23fb4be2063fea658668d0f02a4efd3a61f3e7bbff87ede267ad72504e012201
7
7
 
8
8
  from typing import Any
@@ -32,8 +32,6 @@ from .utils import filter_unset_query
32
32
  from ..config import BotInfo, Config
33
33
  from ..exception import (
34
34
  ActionFailed,
35
- MatrixAdapterException,
36
- NetworkError,
37
35
  RateLimitException,
38
36
  UnauthorizedException,
39
37
  )
@@ -69,30 +67,24 @@ async def _request(
69
67
  parse_json: bool = True,
70
68
  ) -> Any: # noqa: ANN401
71
69
  del bot_info
72
- try:
73
- request.timeout = adapter.matrix_config.matrix_api_timeout
74
- request.proxy = adapter.matrix_config.matrix_proxy
75
- data = await adapter.request(request)
76
- log(
77
- "TRACE",
78
- f"API code: {data.status_code} response: {escape_tag(str(data.content))}",
79
- )
80
- if HTTPStatus.OK <= data.status_code < HTTPStatus.MULTIPLE_CHOICES:
81
- if not data.content:
82
- return None
83
- if not parse_json:
84
- return data.content
85
- return json.loads(data.content)
86
- if data.status_code in (HTTPStatus.UNAUTHORIZED, HTTPStatus.FORBIDDEN):
87
- raise UnauthorizedException(data) # noqa: TRY301
88
- if data.status_code == HTTPStatus.TOO_MANY_REQUESTS:
89
- raise RateLimitException(data) # noqa: TRY301
90
- raise ActionFailed(data) # noqa: TRY301
91
- except MatrixAdapterException:
92
- raise
93
- except Exception as e:
94
- msg = "API request failed"
95
- raise NetworkError(msg) from e
70
+ request.timeout = adapter.matrix_config.matrix_api_timeout
71
+ request.proxy = adapter.matrix_config.matrix_proxy
72
+ data = await adapter.request(request)
73
+ log(
74
+ "TRACE",
75
+ f"API code: {data.status_code} response: {escape_tag(str(data.content))}",
76
+ )
77
+ if HTTPStatus.OK <= data.status_code < HTTPStatus.MULTIPLE_CHOICES:
78
+ if not data.content:
79
+ raise ActionFailed(data)
80
+ if not parse_json:
81
+ return data.content
82
+ return json.loads(data.content)
83
+ if data.status_code in (HTTPStatus.UNAUTHORIZED, HTTPStatus.FORBIDDEN):
84
+ raise UnauthorizedException(data)
85
+ if data.status_code == HTTPStatus.TOO_MANY_REQUESTS:
86
+ raise RateLimitException(data)
87
+ raise ActionFailed(data)
96
88
 
97
89
 
98
90
  def _headers(adapter: AdapterProtocol, bot_info: BotInfo) -> dict[str, str]:
@@ -2,7 +2,7 @@
2
2
 
3
3
  [project]
4
4
  name = "nonebot-adapter-matrix"
5
- version = "0.2.2"
5
+ version = "0.2.3"
6
6
  description = "Matrix adapter for nonebot2"
7
7
  authors = [
8
8
  { name = "elysia-best", email = "a.elysia@proton.me" }