初始化
This commit is contained in:
78
core/models.py
Normal file
78
core/models.py
Normal file
@@ -0,0 +1,78 @@
|
||||
"""数据模型定义"""
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Optional, Dict, Any
|
||||
|
||||
|
||||
class CallbackRequest(BaseModel):
|
||||
"""WPS Callback请求模型"""
|
||||
chatid: int = Field(..., description="会话ID")
|
||||
creator: int = Field(..., description="发送者ID")
|
||||
content: str = Field(..., description="消息内容")
|
||||
reply: Optional[Dict[str, Any]] = Field(None, description="回复内容")
|
||||
robot_key: str = Field(..., description="机器人key")
|
||||
url: str = Field(..., description="callback地址")
|
||||
ctime: int = Field(..., description="发送时间")
|
||||
|
||||
|
||||
class TextMessage(BaseModel):
|
||||
"""文本消息"""
|
||||
msgtype: str = "text"
|
||||
text: Dict[str, str]
|
||||
|
||||
@classmethod
|
||||
def create(cls, content: str):
|
||||
"""创建文本消息"""
|
||||
return cls(text={"content": content})
|
||||
|
||||
|
||||
class MarkdownMessage(BaseModel):
|
||||
"""Markdown消息"""
|
||||
msgtype: str = "markdown"
|
||||
markdown: Dict[str, str]
|
||||
|
||||
@classmethod
|
||||
def create(cls, text: str):
|
||||
"""创建Markdown消息"""
|
||||
return cls(markdown={"text": text})
|
||||
|
||||
|
||||
class LinkMessage(BaseModel):
|
||||
"""链接消息"""
|
||||
msgtype: str = "link"
|
||||
link: Dict[str, str]
|
||||
|
||||
@classmethod
|
||||
def create(cls, title: str, text: str, message_url: str = "", btn_title: str = "查看详情"):
|
||||
"""创建链接消息"""
|
||||
return cls(link={
|
||||
"title": title,
|
||||
"text": text,
|
||||
"messageUrl": message_url,
|
||||
"btnTitle": btn_title
|
||||
})
|
||||
|
||||
|
||||
class GameState(BaseModel):
|
||||
"""游戏状态基类"""
|
||||
game_type: str
|
||||
created_at: int
|
||||
updated_at: int
|
||||
|
||||
|
||||
class GuessGameState(GameState):
|
||||
"""猜数字游戏状态"""
|
||||
game_type: str = "guess"
|
||||
target: int = Field(..., description="目标数字")
|
||||
attempts: int = Field(0, description="尝试次数")
|
||||
guesses: list[int] = Field(default_factory=list, description="历史猜测")
|
||||
max_attempts: int = Field(10, description="最大尝试次数")
|
||||
|
||||
|
||||
class QuizGameState(GameState):
|
||||
"""问答游戏状态"""
|
||||
game_type: str = "quiz"
|
||||
question_id: int = Field(..., description="问题ID")
|
||||
question: str = Field(..., description="问题内容")
|
||||
attempts: int = Field(0, description="尝试次数")
|
||||
max_attempts: int = Field(3, description="最大尝试次数")
|
||||
|
||||
Reference in New Issue
Block a user