gitea_push2qq/model.py

69 lines
1.7 KiB
Python
Raw Normal View History

2023-12-18 19:37:29 +08:00
from dataclasses import dataclass
from typing import Optional, List, Union, Literal
from lib_not_dr.types import Options
2023-12-19 01:39:43 +08:00
from pydantic import BaseModel, Field
2023-12-18 19:37:29 +08:00
from socketio import AsyncClient
class AtElement(Options):
text: str
id: Union[int, Literal['all']] = 'all'
class ReplyMessage(Options):
id: str
username: str = ''
content: str = ''
files: list = []
def to_json(self) -> dict:
return {
'_id': self.id,
'username': self.username,
'content': self.content,
'files': self.files
}
class Message(Options):
content: str
room_id: Optional[int] = None
room: Optional[int] = None # room id 和 room 二选一 ( 实际上直接填 room id 就行了 )
file: None = None # 上传文件
reply_to: Optional[ReplyMessage] = None # 源码 给了一个 any 回复消息
b64_img: Optional[str] = None # 发送图片
at: Optional[List[AtElement]] = [] # @某人
sticker: Optional[None] = None # 发送表情
message_type: Optional[str] = None # 消息类型
def to_json(self) -> dict:
return {
'content': self.content,
'roomId': self.room_id,
'room': self.room,
'file': self.file,
'replyMessage': self.reply_to.to_json() if self.reply_to else None,
'b64img': self.b64_img,
'at': self.at,
'sticker': self.sticker,
'messageType': self.message_type
}
2023-12-19 01:05:14 +08:00
class SioConfig(BaseModel):
2023-12-19 01:41:28 +08:00
host: str
key: str = Field(alias='private_key')
2023-12-19 01:39:43 +08:00
self_id: int
2023-12-19 01:05:14 +08:00
admin: List[int]
2023-12-19 01:23:50 +08:00
validate_host: str
2023-12-19 01:05:14 +08:00
client_id: str
client_secret: str
2023-12-18 19:37:29 +08:00
@dataclass
class Ctx:
sio: AsyncClient
sio_config: SioConfig