satori-python-client 0.16.4__tar.gz → 0.16.6__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.16.4
3
+ Version: 0.16.6
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>
@@ -72,10 +72,17 @@ pip install satori-python-server
72
72
 
73
73
  ### 官方适配器
74
74
 
75
- | 适配器 | 安装 |
76
- |------------|----------------------------------------------|
77
- | Satori | `pip install satori-python-adapter-satori` |
78
- | OneBot V11 | `pip install satori-python-adapter-onebot11` |
75
+ | 适配器 | 安装 | 路径 |
76
+ |------------|----------------------------------------------|--------------------------------------------------------------------|
77
+ | Satori | `pip install satori-python-adapter-satori` | satori.adapters.satori |
78
+ | OneBot V11 | `pip install satori-python-adapter-onebot11` | satori.adapters.onebot11.forward, satori.adapters.onebot11.reverse |
79
+ | Console | `pip install satori-python-adapter-console` | satori.adapters.console |
80
+
81
+ ### 社区适配器
82
+
83
+ | 适配器 | 安装 | 路径 |
84
+ |-------------------|-----------------------|--------------|
85
+ | nekobox(Lagrange) | `pip install nekobox` | nekobox.main |
79
86
 
80
87
  ## 使用
81
88
 
@@ -47,10 +47,17 @@ pip install satori-python-server
47
47
 
48
48
  ### 官方适配器
49
49
 
50
- | 适配器 | 安装 |
51
- |------------|----------------------------------------------|
52
- | Satori | `pip install satori-python-adapter-satori` |
53
- | OneBot V11 | `pip install satori-python-adapter-onebot11` |
50
+ | 适配器 | 安装 | 路径 |
51
+ |------------|----------------------------------------------|--------------------------------------------------------------------|
52
+ | Satori | `pip install satori-python-adapter-satori` | satori.adapters.satori |
53
+ | OneBot V11 | `pip install satori-python-adapter-onebot11` | satori.adapters.onebot11.forward, satori.adapters.onebot11.reverse |
54
+ | Console | `pip install satori-python-adapter-console` | satori.adapters.console |
55
+
56
+ ### 社区适配器
57
+
58
+ | 适配器 | 安装 | 路径 |
59
+ |-------------------|-----------------------|--------------|
60
+ | nekobox(Lagrange) | `pip install nekobox` | nekobox.main |
54
61
 
55
62
  ## 使用
56
63
 
@@ -24,7 +24,7 @@ classifiers = [
24
24
  "Programming Language :: Python :: 3.12",
25
25
  "Operating System :: OS Independent",
26
26
  ]
27
- version = "0.16.4"
27
+ version = "0.16.6"
28
28
 
29
29
  [project.license]
30
30
  text = "MIT"
@@ -49,6 +49,7 @@ dev = [
49
49
  "fix-future-annotations>=0.5.0",
50
50
  "mina-build<0.6,>=0.5.1",
51
51
  "pdm-mina>=0.3.2",
52
+ "nonechat<0.7.0,>=0.6.0",
52
53
  ]
53
54
 
54
55
  [tool.pdm.build]
@@ -35,6 +35,31 @@ MAPPING: dict[type[Config], type[BaseNetwork]] = {
35
35
  WebsocketsInfo: WsNetwork,
36
36
  }
37
37
 
38
+ _app: App | None = None
39
+
40
+
41
+ @overload
42
+ def get_accounts() -> dict[str, Account]: ...
43
+
44
+
45
+ @overload
46
+ def get_accounts(self_id: str) -> list[Account]: ...
47
+
48
+
49
+ def get_accounts(self_id: str | None = None):
50
+ if _app is None:
51
+ raise RuntimeError("App instance is not initialized.")
52
+ if not self_id:
53
+ return _app.accounts
54
+ return [acc for acc in _app.accounts.values() if acc.self_info.user.id == self_id]
55
+
56
+
57
+ def get_app() -> App:
58
+ """Get the current App instance."""
59
+ if _app is None:
60
+ raise RuntimeError("App instance is not initialized.")
61
+ return _app
62
+
38
63
 
39
64
  class App(Service):
40
65
  id = "satori-python.client"
@@ -51,6 +76,10 @@ class App(Service):
51
76
  MAPPING[tc] = tn
52
77
 
53
78
  def __init__(self, *configs: Config, default_api_cls: type[ApiProtocol] = ApiProtocol):
79
+ global _app
80
+
81
+ if _app is not None:
82
+ raise RuntimeError("App instance already exists. Only one App instance is allowed.")
54
83
  self.accounts = {}
55
84
  self.connections = []
56
85
  self.event_callbacks = []
@@ -59,6 +88,7 @@ class App(Service):
59
88
  for config in configs:
60
89
  self.apply(config)
61
90
  self.default_api_cls = default_api_cls
91
+ _app = self
62
92
 
63
93
  def apply(self, config: Config):
64
94
  try:
@@ -67,9 +97,6 @@ class App(Service):
67
97
  raise TypeError(f"Unknown config type: {config}")
68
98
  self.connections.append(connection)
69
99
 
70
- def get_account(self, self_id: str) -> Account:
71
- return self.accounts[self_id]
72
-
73
100
  def register(self, callback: Callable[[Account, Event], Awaitable[Any]]):
74
101
  self.event_callbacks.append(callback)
75
102
 
@@ -8,7 +8,7 @@ from launart import Service
8
8
  from ..config import Config as Config
9
9
 
10
10
  if TYPE_CHECKING:
11
- from .. import Account, App
11
+ from satori.client import Account, App
12
12
 
13
13
  TConfig = TypeVar("TConfig", bound=Config)
14
14