Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: 更新平台消息段参数 #75

Merged
merged 2 commits into from
Sep 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions nonebot/adapters/feishu/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,22 @@ def segment_text(self) -> dict:
return {
"image": "[图片]",
"file": "[文件]",
"folder": "[文件夹]",
"audio": "[音频]",
"media": "[视频]",
"sticker": "[表情包]",
"interactive": "[消息卡片]",
"hongbao": "[红包]",
"share_calendar_event": "[日程卡片]",
"share_calendar_event": "[日程分享卡片]",
"calendar": "[日程邀请卡片]",
"general_calendar": "[日程转让卡片]",
"share_chat": "[群名片]",
"share_user": "[个人名片]",
"system": "[系统消息]",
"location": "[位置]",
"video_chat": "[视频通话]",
"todo": "[任务]",
"vote": "[投票]",
}

def __str__(self) -> str:
Expand Down Expand Up @@ -65,28 +70,28 @@ def __radd__(
def is_text(self) -> bool:
return self.type == "text"

# 接收消息
@staticmethod
def at(user_id: str) -> "MessageSegment":
return MessageSegment("at", {"user_id": user_id})

# 发送消息
@staticmethod
def text(text: str) -> "MessageSegment":
return MessageSegment("text", {"text": text})

@staticmethod
def post(title: str, content: list) -> "MessageSegment":
def post(title: str, content: List[Any]) -> "MessageSegment":
return MessageSegment("post", {"title": title, "content": content})

@staticmethod
def image(image_key: str) -> "MessageSegment":
return MessageSegment("image", {"image_key": image_key})

@staticmethod
def interactive(data: dict) -> "MessageSegment":
def interactive(data: Dict[str, Any]) -> "MessageSegment":
return MessageSegment("interactive", data)

# 接收消息
@staticmethod
def at(user_id: str) -> "MessageSegment":
return MessageSegment("at", {"user_id": user_id})

@staticmethod
def share_chat(chat_id: str) -> "MessageSegment":
return MessageSegment("share_chat", {"chat_id": chat_id})
Expand All @@ -96,26 +101,22 @@ def share_user(user_id: str) -> "MessageSegment":
return MessageSegment("share_user", {"user_id": user_id})

@staticmethod
def audio(file_key: str, duration: int) -> "MessageSegment":
return MessageSegment("audio", {"file_key": file_key, "duration": duration})
def audio(file_key: str) -> "MessageSegment":
return MessageSegment("audio", {"file_key": file_key})

@staticmethod
def media(
file_key: str, image_key: str, file_name: str, duration: int
) -> "MessageSegment":
def media(file_key: str, image_key: Optional[str]) -> "MessageSegment":
return MessageSegment(
"media",
{
"file_key": file_key,
"image_key": image_key,
"file_name": file_name,
"duration": duration,
},
)

@staticmethod
def file(file_key: str, file_name: str) -> "MessageSegment":
return MessageSegment("file", {"file_key": file_key, "file_name": file_name})
def file(file_key: str) -> "MessageSegment":
return MessageSegment("file", {"file_key": file_key})

@staticmethod
def sticker(file_key: str) -> "MessageSegment":
Expand Down