-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatContent.py
More file actions
31 lines (27 loc) · 1.09 KB
/
Copy pathchatContent.py
File metadata and controls
31 lines (27 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os
from typing import List
class ChatContent:
username='' # 用户名
imagePaths=[] # 图片路径
text='' #聊天内容
time='' #时间
ownByMyself=False #是否为AI发送
def __init__(self, username: str, imagePaths: List[str], text: str, time: str,ownByMyself: bool):
self.username = username
self.imagePaths = imagePaths
self.text = text
self.time = time
self.ownByMyself = ownByMyself
self.empty=True if self.text else False
def report(self) -> str:
prefix = '[你]' if self.ownByMyself else ''
content = self.text if self.text else ""
images = [image for image in self.imagePaths if os.path.exists(image)]
images_str = str(images) if images else "无"
return f'{prefix}{self.username}: {content}\n{self.time}\n 图片:{images_str}'
#
def __str__(self) -> str:
if self.ownByMyself:
return f"[time]\n{self.time} \n\n [username] \n {self.username} \n\n [content] \n {self.text}\n"
else:
return f'{self.text if self.text else ""}'