Skip to content

Commit

Permalink
✨ support upload voice
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Sep 15, 2023
1 parent 4618c25 commit 0d04196
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 165 deletions.
151 changes: 97 additions & 54 deletions nonebot/adapters/red/api/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,52 +135,101 @@ class PicElement(BaseModel):
emojiZplan: Optional[EmojiZplan]


class FaceElement(BaseModel):
faceIndex: int
faceText: Optional[str]
"""{None: normal, '/xxx': sticker, '': poke}"""
faceType: int
"""{1: normal, 2: normal-extended, 3: sticker, 5: poke}"""
packId: Optional[Any]
stickerId: Optional[Any]
sourceType: Optional[Any]
stickerType: Optional[Any]
resultId: Optional[Any]
surpriseId: Optional[Any]
randomType: Optional[Any]
imageType: Optional[Any]
pokeType: Optional[Any]
spokeSummary: Optional[Any]
doubleHit: Optional[Any]
vaspokeId: Optional[Any]
vaspokeName: Optional[Any]
vaspokeMinver: Optional[Any]
pokeStrength: Optional[Any]
msgType: Optional[Any]
faceBubbleCount: Optional[Any]
pokeFlag: Optional[Any]


class FileElement(BaseModel):
fileMd5: str
fileName: str
filePath: str
fileSize: str
fileUuid: str
picHeight: Optional[int]
picWidth: Optional[int]
picThumbPath: Optional[Any]
expireTime: Optional[str]
file10MMd5: Optional[str]
fileSha: Optional[str]
fileSha3: Optional[str]
videoDuration: Optional[int]
transferStatus: Optional[int]
progress: Optional[int]
invalidState: Optional[int]
fileUuid: Optional[str]
fileSubId: Optional[str]
thumbFileSize: Optional[int]
fileBizId: Optional[Any]
thumbMd5: Optional[Any]
folderId: Optional[Any]
fileGroupIndex: Optional[int]
fileTransType: Optional[Any]


class PttElement(BaseModel):
fileName: str
filePath: str
md5HexStr: str
fileSize: str
duration: int
formatType: int
voiceType: int
voiceChangeType: int
"""{0: normal, 1: magic}"""
canConvert2Text: bool
text: Optional[str]
"""原文中这里的`text`比其它属性多缩进了一格,请根据`canConvert2Text`来判断`text`的存在与否"""
waveAmplitudes: Any
fileId: int
fileUuid: str
text: Optional[str]
translateStatus: Optional[int]
transferStatus: Optional[int]
progress: Optional[int]
playState: Optional[int]
waveAmplitudes: Optional[List[int]]
invalidState: Optional[int]
fileSubId: Optional[str]
fileBizId: Optional[Any]


class FaceElement(BaseModel):
faceIndex: str
faceText: Optional[str]
"""{None: normal, '/xxx': sticker, '': poke}"""
faceType: int
"""{1: normal, 2: normal-extended, 3: sticker, 5: poke}"""
packId: Optional[str]
"""{None: other, '1': sticker}"""
stickerId: Optional[str]
"""{None: other, 'xxx': sticker}"""
sourceType: Optional[int]
"""{None: other, 1: sticker}"""
stickerType: Optional[int]
"""{None: other, 1: sticker}"""
randomType: Optional[int]
"""{None: other, 1: sticker}"""
pokeType: Optional[int]
"""{None: other, xxx: poke}"""
spokeSummary: Optional[str]
"""{None: other, '': poke}"""
doubleHit: Optional[int]
"""{None: other, xxx: poke}"""
vaspokeId: Optional[int]
"""{None: other, xxx: poke}"""
vaspokeName: Optional[str]
"""{None: other, 'xxx': poke}"""
class VideoElement(BaseModel):
filePath: str
fileName: str
videoMd5: str
thumbMd5: str
fileTime: int
thumbSize: int
fileFormat: int
fileSize: str
thumbWidth: int
thumbHeight: int
busiType: int
subBusiType: int
thumbPath: Optional[Any]
transferStatus: Optional[int]
progress: Optional[int]
invalidState: Optional[int]
fileUuid: Optional[str]
fileSubId: Optional[str]
fileBizId: Optional[Any]


class ReplyElement(BaseModel):
Expand Down Expand Up @@ -217,29 +266,6 @@ class MultiForwardMsgElement(BaseModel):
fileName: str


class VideoElement(BaseModel):
filePath: str
fileName: str
videoMd5: str
thumbMd5: str
fileTime: int
thumbSize: int
fileFormat: int
fileSize: str
thumbWidth: int
thumbHeight: int
busiType: int
subBusiType: int
thumbPath: dict
"""不清楚为什么是dict,这是收到的数据: {}"""
transferStatus: int
progress: int
invalidState: int
fileUuid: str
fileSubId: str
fileBizId: Optional[str]


class GrayTipElement(BaseModel):
subElementType: Optional[int]
revokeElement: Optional[dict]
Expand Down Expand Up @@ -416,3 +442,20 @@ class Group(BaseModel):
discussToGroupUin: str
discussToGroupMaxMsgSeq: int
discussToGroupTime: int


class ImageInfo(BaseModel):
width: int
height: int
type: str
mime: str
wUnits: str
hUnits: str


class UploadResponse(BaseModel):
md5: str
imageInfo: Optional[ImageInfo]
fileSize: int
filePath: str
ntFilePath: str
6 changes: 3 additions & 3 deletions nonebot/adapters/red/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from .config import BotInfo
from .api.model import Group, Member
from .event import Event, MessageEvent
from .api.model import Profile, ChatType
from .api.model import Message as MessageModel
from .api.model import Profile, ChatType, UploadResponse
from .message import Message, ForwardNode, MessageSegment, MediaMessageSegment


Expand Down Expand Up @@ -331,7 +331,7 @@ async def fetch_media(
download_type=download_type,
)

async def upload(self, file: bytes) -> str:
async def upload(self, file: bytes) -> UploadResponse:
"""上传资源
注意:此接口不推荐直接使用
Expand All @@ -340,7 +340,7 @@ async def upload(self, file: bytes) -> str:
file: 上传的资源数据
"""
log("WARING", "This API is not suggest for user usage")
return await self.call_api("upload", file=file)
return UploadResponse.parse_obj(await self.call_api("upload", file=file))

async def recall_message(
self,
Expand Down
Loading

0 comments on commit 0d04196

Please sign in to comment.