satori-python-client 0.13.1__tar.gz → 0.13.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: satori-python-client
3
- Version: 0.13.1
3
+ Version: 0.13.3
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.1"
27
+ version = "0.13.3"
28
28
 
29
29
  [project.license]
30
30
  text = "MIT"
@@ -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,5 @@
1
1
  import asyncio
2
- from typing import Any, Iterable, Protocol, TypeVar, overload
2
+ from typing import Any, Generic, Iterable, Protocol, TypeVar, overload
3
3
 
4
4
  from yarl import URL
5
5
 
@@ -23,6 +23,7 @@ from satori.model import (
23
23
  from .protocol import ApiProtocol
24
24
 
25
25
  TP = TypeVar("TP", bound="ApiProtocol")
26
+ TP1 = TypeVar("TP1", bound="ApiProtocol")
26
27
 
27
28
  class Api(Protocol):
28
29
  token: str | None = None
@@ -35,12 +36,12 @@ class ApiInfo(Api):
35
36
  self, host: str = "localhost", port: int = 5140, path: str = "", token: str | None = None
36
37
  ): ...
37
38
 
38
- class Account:
39
+ class Account(Generic[TP]):
39
40
  platform: str
40
41
  self_id: str
41
42
  self_info: Login
42
43
  config: Api
43
- protocol: ApiProtocol
44
+ protocol: TP
44
45
  connected: asyncio.Event
45
46
 
46
47
  def __init__(
@@ -49,16 +50,18 @@ class Account:
49
50
  self_id: str,
50
51
  self_info: Login,
51
52
  config: Api,
52
- protocol_cls: type[ApiProtocol] = ApiProtocol,
53
+ protocol_cls: type[TP] = ApiProtocol,
53
54
  ): ...
54
55
  @property
55
56
  def identity(self) -> str: ...
56
57
  @overload
57
- def custom(self, config: Api, protocol_cls: type[TP] = ApiProtocol) -> TP: ...
58
+ def custom(self, config: Api, protocol_cls: type[TP1] = ApiProtocol) -> Account[TP1]: ...
59
+ @overload
60
+ def custom(self, *, protocol_cls: type[TP1]) -> Account[TP1]: ...
58
61
  @overload
59
62
  def custom(
60
- self, *, protocol_cls: type[TP] = ApiProtocol, host: str, port: int, token: str | None = None
61
- ) -> TP: ...
63
+ self, *, protocol_cls: type[TP1] = ApiProtocol, host: str, port: int, token: str | None = None
64
+ ) -> Account[TP1]: ...
62
65
  async def send(self, event: Event, message: str | Iterable[str | Element]) -> list[MessageObject]:
63
66
  """发送消息。返回一个 `MessageObject` 对象构成的数组。
64
67
 
@@ -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: