satori-python-client 0.13.2__tar.gz → 0.14.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.1
2
2
  Name: satori-python-client
3
- Version: 0.13.2
3
+ Version: 0.14.0
4
4
  Summary: Satori Protocol SDK for python, specify client part
5
5
  Home-page: https://github.com/RF-Tar-Railt/satori-python
6
6
  Author-Email: RF-Tar-Railt <rf_tar_railt@qq.com>
@@ -24,7 +24,7 @@ classifiers = [
24
24
  "Programming Language :: Python :: 3.12",
25
25
  "Operating System :: OS Independent",
26
26
  ]
27
- version = "0.13.2"
27
+ version = "0.14.0"
28
28
 
29
29
  [project.license]
30
30
  text = "MIT"
@@ -82,7 +82,7 @@ extra_standard_library = [
82
82
 
83
83
  [tool.ruff]
84
84
  line-length = 110
85
- target-version = "py38"
85
+ target-version = "py39"
86
86
  exclude = [
87
87
  "exam.py",
88
88
  ]
@@ -107,7 +107,7 @@ ignore = [
107
107
 
108
108
  [tool.pyright]
109
109
  pythonPlatform = "All"
110
- pythonVersion = "3.8"
110
+ pythonVersion = "3.9"
111
111
  typeCheckingMode = "basic"
112
112
  reportShadowedImports = false
113
113
  disableBytesTypePromotions = true
@@ -4,8 +4,9 @@ import asyncio
4
4
  import functools
5
5
  import signal
6
6
  import threading
7
+ from collections.abc import Awaitable, Iterable
7
8
  from functools import wraps
8
- from typing import TYPE_CHECKING, Any, Awaitable, Callable, Iterable, Literal, TypeVar, overload
9
+ from typing import TYPE_CHECKING, Any, Callable, Literal, TypeVar, overload
9
10
 
10
11
  from creart import it
11
12
  from graia.amnesia.builtins.aiohttp import AiohttpClientService
@@ -2,7 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  import asyncio
4
4
  from dataclasses import dataclass
5
- from typing import TypeVar
5
+ from typing import Generic, TypeVar
6
6
 
7
7
  from yarl import URL
8
8
 
@@ -11,6 +11,7 @@ from satori.model import Login
11
11
  from .protocol import ApiProtocol
12
12
 
13
13
  TP = TypeVar("TP", bound="ApiProtocol")
14
+ TP1 = TypeVar("TP1", bound="ApiProtocol")
14
15
 
15
16
 
16
17
  @dataclass
@@ -29,14 +30,14 @@ class ApiInfo:
29
30
  return URL(f"http://{self.host}:{self.port}{self.path}") / "v1"
30
31
 
31
32
 
32
- class Account:
33
+ class Account(Generic[TP]):
33
34
  def __init__(
34
35
  self,
35
36
  platform: str,
36
37
  self_id: str,
37
38
  self_info: Login,
38
39
  config: ApiInfo,
39
- protocol_cls: type[ApiProtocol] = ApiProtocol,
40
+ protocol_cls: type[TP] = ApiProtocol,
40
41
  ):
41
42
  self.platform = platform
42
43
  self.self_id = self_id
@@ -45,14 +46,16 @@ class Account:
45
46
  self.protocol = protocol_cls(self) # type: ignore
46
47
  self.connected = asyncio.Event()
47
48
 
48
- def custom(self, config: ApiInfo | None = None, protocol_cls: type[TP] = ApiProtocol, **kwargs) -> TP:
49
+ def custom(
50
+ self, config: ApiInfo | None = None, protocol_cls: type[TP1] = ApiProtocol, **kwargs
51
+ ) -> "Account[TP1]":
49
52
  return Account(
50
53
  self.platform,
51
54
  self.self_id,
52
55
  self.self_info,
53
- config or ApiInfo(**kwargs),
56
+ config or (ApiInfo(**kwargs) if kwargs else self.config),
54
57
  protocol_cls, # type: ignore
55
- ).protocol
58
+ )
56
59
 
57
60
  @property
58
61
  def identity(self):
@@ -1,5 +1,6 @@
1
1
  import asyncio
2
- from typing import Any, Iterable, Protocol, TypeVar, overload
2
+ from collections.abc import Iterable
3
+ from typing import Any, Generic, Protocol, TypeVar, overload
3
4
 
4
5
  from yarl import URL
5
6
 
@@ -23,6 +24,7 @@ from satori.model import (
23
24
  from .protocol import ApiProtocol
24
25
 
25
26
  TP = TypeVar("TP", bound="ApiProtocol")
27
+ TP1 = TypeVar("TP1", bound="ApiProtocol")
26
28
 
27
29
  class Api(Protocol):
28
30
  token: str | None = None
@@ -35,12 +37,12 @@ class ApiInfo(Api):
35
37
  self, host: str = "localhost", port: int = 5140, path: str = "", token: str | None = None
36
38
  ): ...
37
39
 
38
- class Account:
40
+ class Account(Generic[TP]):
39
41
  platform: str
40
42
  self_id: str
41
43
  self_info: Login
42
44
  config: Api
43
- protocol: ApiProtocol
45
+ protocol: TP
44
46
  connected: asyncio.Event
45
47
 
46
48
  def __init__(
@@ -49,16 +51,18 @@ class Account:
49
51
  self_id: str,
50
52
  self_info: Login,
51
53
  config: Api,
52
- protocol_cls: type[ApiProtocol] = ApiProtocol,
54
+ protocol_cls: type[TP] = ApiProtocol,
53
55
  ): ...
54
56
  @property
55
57
  def identity(self) -> str: ...
56
58
  @overload
57
- def custom(self, config: Api, protocol_cls: type[TP] = ApiProtocol) -> TP: ...
59
+ def custom(self, config: Api, protocol_cls: type[TP1] = ApiProtocol) -> Account[TP1]: ...
60
+ @overload
61
+ def custom(self, *, protocol_cls: type[TP1]) -> Account[TP1]: ...
58
62
  @overload
59
63
  def custom(
60
- self, *, protocol_cls: type[TP] = ApiProtocol, host: str, port: int, token: str | None = None
61
- ) -> TP: ...
64
+ self, *, protocol_cls: type[TP1] = ApiProtocol, host: str, port: int, token: str | None = None
65
+ ) -> Account[TP1]: ...
62
66
  async def send(self, event: Event, message: str | Iterable[str | Element]) -> list[MessageObject]:
63
67
  """发送消息。返回一个 `MessageObject` 对象构成的数组。
64
68
 
@@ -61,7 +61,7 @@ class WebhookNetwork(BaseNetwork[WebhookInfo]):
61
61
  op = data["op"]
62
62
  if op != Opcode.EVENT:
63
63
  return web.Response(status=202)
64
- logger.debug(f"Received payload: {data}")
64
+ logger.trace(f"Received payload: {data}")
65
65
  self.post_event(data["body"])
66
66
  return web.Response()
67
67
 
@@ -37,6 +37,7 @@ class WsNetwork(BaseNetwork[WebsocketsInfo]):
37
37
  return
38
38
  elif msg.type == aiohttp.WSMsgType.TEXT:
39
39
  data: dict = json.loads(cast(str, msg.data))
40
+ logger.trace(f"Received payload: {data}")
40
41
  if data["op"] == Opcode.EVENT:
41
42
  self.post_event(data["body"])
42
43
  elif data["op"] > 4:
@@ -118,9 +119,8 @@ class WsNetwork(BaseNetwork[WebsocketsInfo]):
118
119
  async def _heartbeat(self):
119
120
  """心跳"""
120
121
  while True:
121
- if self.sequence:
122
- with suppress(Exception):
123
- await self.send({"op": 1})
122
+ with suppress(Exception):
123
+ await self.send({"op": 1})
124
124
  await asyncio.sleep(9)
125
125
 
126
126
  async def daemon(self, manager: Launart, session: aiohttp.ClientSession):
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
- from typing import TYPE_CHECKING, Any, Iterable, cast, overload
3
+ from collections.abc import Iterable
4
+ from typing import TYPE_CHECKING, Any, cast, overload
4
5
 
5
6
  from aiohttp import FormData
6
7
  from graia.amnesia.builtins.aiohttp import AiohttpClientService