Skip to content

Commit

Permalink
✨ fix escape and add seg constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
StarHeartHunt committed Oct 23, 2023
1 parent 374f58c commit 1f8a4d0
Showing 1 changed file with 70 additions and 20 deletions.
90 changes: 70 additions & 20 deletions nonebot/adapters/feishu/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,37 @@ def interactive_template(
},
)

@staticmethod
def todo(task_id: str, summary: "_PostData", due_time: str):
return Todo(
"todo", {"task_id": task_id, "summary": summary, "due_time": due_time}
)

@staticmethod
def hongbao(text: str) -> "Hongbao":
return Hongbao("hongbao", {"text": text})

@staticmethod
def system(template: str, from_user: List[str], to_chatters: List[str]) -> "System":
return System(
"system",
{"template": template, "from_user": from_user, "to_chatters": to_chatters},
)

@staticmethod
def location(name: str, longitude: str, latitude: str) -> "Location":
return Location(
"location",
{"name": name, "longitude": longitude, "latitude": latitude},
)

@staticmethod
def video_chat(topic: str, start_time: str):
return VideoChat(
"video_chat",
{"topic": topic, "start_time": start_time},
)

@staticmethod
def share_chat(chat_id: str) -> "MessageSegment":
return ShareChat("share_chat", {"chat_id": chat_id})
Expand All @@ -119,7 +150,7 @@ def audio(file_key: str, duration: Optional[int] = None) -> "MessageSegment":
@staticmethod
def media(
file_key: str,
image_key: Optional[str],
image_key: Optional[str] = None,
file_name: Optional[str] = None,
duration: Optional[int] = None,
) -> "MessageSegment":
Expand All @@ -137,6 +168,10 @@ def media(
def file(file_key: str, file_name: Optional[str] = None) -> "MessageSegment":
return File("file", {"file_key": file_key, "file_name": file_name})

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

@staticmethod
def sticker(file_key: str) -> "MessageSegment":
return Sticker("sticker", {"file_key": file_key})
Expand Down Expand Up @@ -199,7 +234,7 @@ class Image(MessageSegment):

@override
def __str__(self) -> str:
return f"<image:{self.data['image_key']!r}>"
return f"[image:{self.data['image_key']!r}]"


class InteractiveHeaderTitle(TypedDict):
Expand Down Expand Up @@ -231,7 +266,7 @@ class Interactive(MessageSegment):

@override
def __str__(self) -> str:
return f"<interactive:{self.data!r}>"
return f"[interactive:{self.data!r}]"


class _InteractiveTemplateData(TypedDict):
Expand All @@ -246,7 +281,7 @@ class InteractiveTemplate(MessageSegment):

@override
def __str__(self) -> str:
return f"<interactive_template:{self.data!r}>"
return f"[interactive_template:{self.data!r}]"


class _ShareChatData(TypedDict):
Expand All @@ -260,7 +295,7 @@ class ShareChat(MessageSegment):

@override
def __str__(self) -> str:
return f"<share_chat:{self.data['chat_id']!r}>"
return f"[share_chat:{self.data['chat_id']!r}]"


class _ShareUserData(TypedDict):
Expand All @@ -274,7 +309,7 @@ class ShareUser(MessageSegment):

@override
def __str__(self) -> str:
return f"<share_user:{self.data['user_id']!r}>"
return f"[share_user:{self.data['user_id']!r}]"


class _AudioData(TypedDict):
Expand All @@ -289,7 +324,7 @@ class Audio(MessageSegment):

@override
def __str__(self) -> str:
return f"<audio:{self.data!r}>"
return f"[audio:{self.data!r}]"


class _MediaData(TypedDict):
Expand All @@ -306,7 +341,7 @@ class Media(MessageSegment):

@override
def __str__(self) -> str:
return f"<media:{self.data['file_key']!r}>"
return f"[media:{self.data['file_key']!r}]"


class _FileData(TypedDict):
Expand All @@ -321,7 +356,22 @@ class File(MessageSegment):

@override
def __str__(self) -> str:
return f"<file:{self.data!r}>"
return f"[file:{self.data!r}]"


class _FolderData(TypedDict):
file_key: str
file_name: Optional[str]


@dataclass
class Folder(MessageSegment):
if TYPE_CHECKING:
data: _FolderData

@override
def __str__(self) -> str:
return f"[folder:{self.data!r}]"


class _StickerData(TypedDict):
Expand All @@ -335,7 +385,7 @@ class Sticker(MessageSegment):

@override
def __str__(self) -> str:
return f"<sticker:{self.data['file_key']!r}>"
return f"[sticker:{self.data['file_key']!r}]"


class PostMessageNode(TypedDict):
Expand Down Expand Up @@ -386,7 +436,7 @@ class Post(MessageSegment):

@override
def __str__(self) -> str:
return f"<post:{self.data!r}>"
return f"[post:{self.data!r}]"


class _SystemData(TypedDict):
Expand All @@ -402,7 +452,7 @@ class System(MessageSegment):

@override
def __str__(self) -> str:
return f"<system:{self.data!r}>"
return f"[system:{self.data!r}]"


class _LocationData(TypedDict):
Expand All @@ -418,7 +468,7 @@ class Location(MessageSegment):

@override
def __str__(self) -> str:
return f"<location:{self.data!r}>"
return f"[location:{self.data!r}]"


class _VideoChatData(TypedDict):
Expand All @@ -433,7 +483,7 @@ class VideoChat(MessageSegment):

@override
def __str__(self) -> str:
return f"<video_chat:{self.data!r}>"
return f"[video_chat:{self.data!r}]"


class _TodoData(TypedDict):
Expand All @@ -449,7 +499,7 @@ class Todo(MessageSegment):

@override
def __str__(self) -> str:
return f"<todo:{self.data!r}>"
return f"[todo:{self.data!r}]"


class _VoteData(TypedDict):
Expand All @@ -464,7 +514,7 @@ class Vote(MessageSegment):

@override
def __str__(self) -> str:
return f"<vote:{self.data!r}>"
return f"[vote:{self.data!r}]"


class _HongbaoData(TypedDict):
Expand All @@ -478,7 +528,7 @@ class Hongbao(MessageSegment):

@override
def __str__(self) -> str:
return f"<hongbao:{self.data['text']!r}>"
return f"[hongbao:{self.data['text']!r}]"


class _CalendarData(TypedDict):
Expand All @@ -494,7 +544,7 @@ class ShareCalendarEvent(MessageSegment):

@override
def __str__(self) -> str:
return f"<share_calendar_event:{self.data!r}>"
return f"[share_calendar_event:{self.data!r}]"


class Calendar:
Expand All @@ -503,7 +553,7 @@ class Calendar:

@override
def __str__(self) -> str:
return f"<calendar:{self.data!r}>"
return f"[calendar:{self.data!r}]"


class GeneralCalendar:
Expand All @@ -512,7 +562,7 @@ class GeneralCalendar:

@override
def __str__(self) -> str:
return f"<general_calendar:{self.data!r}>"
return f"[general_calendar:{self.data!r}]"


class Message(BaseMessage[MessageSegment]):
Expand Down

0 comments on commit 1f8a4d0

Please sign in to comment.