satori-python-core 0.12.0__tar.gz → 0.13.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-core
3
- Version: 0.12.0
3
+ Version: 0.13.0
4
4
  Summary: Satori Protocol SDK for python, specify common 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>
@@ -42,6 +42,10 @@ Description-Content-Type: text/markdown
42
42
  - [Chronocat](https://chronocat.vercel.app)
43
43
  - Koishi (搭配 `@koishijs/plugin-server`)
44
44
 
45
+ ### 使用该 SDK 的框架
46
+
47
+ - [`Entari`](https://github.com/ArcletProject/Entari)
48
+
45
49
  ## 安装
46
50
 
47
51
  安装完整体:
@@ -69,14 +73,15 @@ pip install satori-python-server
69
73
  客户端:
70
74
 
71
75
  ```python
72
- from satori import Event, WebsocketsInfo
76
+ from satori import EventType, WebsocketsInfo
77
+ from satori.event import MessageEvent
73
78
  from satori.client import Account, App
74
79
 
75
80
  app = App(WebsocketsInfo(port=5140))
76
81
 
77
- @app.register
78
- async def on_message(account: Account, event: Event):
79
- if event.user and event.user.id == "xxxxxxxxxxx":
82
+ @app.register_on(EventType.MESSAGE_CREATED)
83
+ async def on_message(account: Account, event: MessageEvent):
84
+ if event.user.id == "xxxxxxxxxxx":
80
85
  await account.send(event, "Hello, World!")
81
86
 
82
87
  app.run()
@@ -18,6 +18,10 @@
18
18
  - [Chronocat](https://chronocat.vercel.app)
19
19
  - Koishi (搭配 `@koishijs/plugin-server`)
20
20
 
21
+ ### 使用该 SDK 的框架
22
+
23
+ - [`Entari`](https://github.com/ArcletProject/Entari)
24
+
21
25
  ## 安装
22
26
 
23
27
  安装完整体:
@@ -45,14 +49,15 @@ pip install satori-python-server
45
49
  客户端:
46
50
 
47
51
  ```python
48
- from satori import Event, WebsocketsInfo
52
+ from satori import EventType, WebsocketsInfo
53
+ from satori.event import MessageEvent
49
54
  from satori.client import Account, App
50
55
 
51
56
  app = App(WebsocketsInfo(port=5140))
52
57
 
53
- @app.register
54
- async def on_message(account: Account, event: Event):
55
- if event.user and event.user.id == "xxxxxxxxxxx":
58
+ @app.register_on(EventType.MESSAGE_CREATED)
59
+ async def on_message(account: Account, event: MessageEvent):
60
+ if event.user.id == "xxxxxxxxxxx":
56
61
  await account.send(event, "Hello, World!")
57
62
 
58
63
  app.run()
@@ -23,7 +23,7 @@ classifiers = [
23
23
  "Programming Language :: Python :: 3.12",
24
24
  "Operating System :: OS Independent",
25
25
  ]
26
- version = "0.12.0"
26
+ version = "0.13.0"
27
27
 
28
28
  [project.license]
29
29
  text = "MIT"
@@ -36,7 +36,10 @@ from .model import Login as Login
36
36
  from .model import LoginStatus as LoginStatus
37
37
  from .model import Member as Member
38
38
  from .model import MessageObject as MessageObject
39
+ from .model import PageDequeResult as PageDequeResult
40
+ from .model import PageResult as PageResult
39
41
  from .model import Role as Role
42
+ from .model import Upload as Upload
40
43
  from .model import User as User
41
44
 
42
- __version__ = "0.12.0"
45
+ __version__ = "0.13.0"
@@ -44,6 +44,8 @@ class Api(str, Enum):
44
44
  FRIEND_LIST = "friend.list"
45
45
  FRIEND_APPROVE = "friend.approve"
46
46
 
47
+ UPLOAD_CREATE = "upload.create"
48
+
47
49
 
48
50
  class EventType(str, Enum):
49
51
  FRIEND_REQUEST = "friend-request"
@@ -192,7 +192,7 @@ class Resource(Element):
192
192
  data = {"src": Path(path).as_uri()}
193
193
  elif raw and mime:
194
194
  bd = raw.getvalue() if isinstance(raw, BytesIO) else raw
195
- data = {"src": f"data:{mime};base64,{b64encode(bd).decode()}"}
195
+ data = {"src": f"data:{mime};base64,{b64encode(bd).decode('utf-8')}"}
196
196
  else:
197
197
  raise ValueError(f"{cls} need at least one of url, path and raw")
198
198
  if name is not None:
@@ -1,7 +1,10 @@
1
+ import mimetypes
1
2
  from dataclasses import asdict, dataclass, field, fields
2
3
  from datetime import datetime
3
4
  from enum import IntEnum
4
- from typing import Any, Callable, ClassVar, Dict, Generic, List, Literal, Optional, TypeVar
5
+ from os import PathLike
6
+ from pathlib import Path
7
+ from typing import IO, Any, Callable, ClassVar, Dict, Generic, List, Literal, Optional, TypeVar, Union
5
8
  from typing_extensions import TypeAlias
6
9
 
7
10
  from .element import Element, transform
@@ -367,3 +370,23 @@ class PageDequeResult(PageResult[T]):
367
370
 
368
371
  Direction: TypeAlias = Literal["before", "after", "around"]
369
372
  Order: TypeAlias = Literal["asc", "desc"]
373
+
374
+
375
+ @dataclass
376
+ class Upload:
377
+ file: Union[bytes, IO[bytes], PathLike]
378
+ mimetype: str = "image/png"
379
+ name: Optional[str] = None
380
+
381
+ def __post_init__(self):
382
+ if isinstance(self.file, PathLike):
383
+ self.mimetype = mimetypes.guess_type(str(self.file))[0] or self.mimetype
384
+ self.name = Path(self.file).name
385
+
386
+ def dump(self):
387
+ file = self.file
388
+
389
+ if isinstance(file, PathLike):
390
+ file = open(file, "rb")
391
+
392
+ return {"value": file, "filename": self.name, "content_type": self.mimetype}