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.
- {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/PKG-INFO +1 -1
- {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/adapter.py +32 -11
- {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/api/client.pyi +2 -2
- {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/api/handle.py +18 -26
- {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/pyproject.toml +1 -1
- {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/README.md +0 -0
- {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/__init__.py +0 -0
- {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/api/__init__.py +0 -0
- {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/api/client.py +0 -0
- {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/api/model.py +0 -0
- {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/api/types.py +0 -0
- {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/api/utils.py +0 -0
- {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/api/validation.py +0 -0
- {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/bot.py +0 -0
- {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/config.py +0 -0
- {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/event.py +0 -0
- {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/exception.py +0 -0
- {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/message.py +0 -0
- {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/oauth.py +0 -0
- {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/serialization.py +0 -0
- {nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/utils.py +0 -0
{nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/adapter.py
RENAMED
|
@@ -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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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)
|
{nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/api/client.pyi
RENAMED
|
@@ -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-
|
|
3
|
+
# Generated at: 2026-06-03T11:02:43Z
|
|
4
4
|
# Source file: nonebot/adapters/matrix/api/handle.py
|
|
5
|
-
# Source SHA256:
|
|
5
|
+
# Source SHA256: caabfb23da26fc722d6c007607d765f6ba7cdee5b7d40d6dd607fdb55886b838
|
|
6
6
|
# Script SHA256: 23fb4be2063fea658668d0f02a4efd3a61f3e7bbff87ede267ad72504e012201
|
|
7
7
|
|
|
8
8
|
from typing import Any
|
{nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/api/handle.py
RENAMED
|
@@ -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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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]:
|
|
File without changes
|
{nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/api/client.py
RENAMED
|
File without changes
|
{nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/api/model.py
RENAMED
|
File without changes
|
{nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/api/types.py
RENAMED
|
File without changes
|
{nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/api/utils.py
RENAMED
|
File without changes
|
|
File without changes
|
{nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/bot.py
RENAMED
|
File without changes
|
{nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/config.py
RENAMED
|
File without changes
|
{nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/event.py
RENAMED
|
File without changes
|
{nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/exception.py
RENAMED
|
File without changes
|
{nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/message.py
RENAMED
|
File without changes
|
{nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/oauth.py
RENAMED
|
File without changes
|
|
File without changes
|
{nonebot_adapter_matrix-0.2.2 → nonebot_adapter_matrix-0.2.3}/nonebot/adapters/matrix/utils.py
RENAMED
|
File without changes
|