mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2026-02-04 21:54:08 +08:00
add cache for gen msg
This commit is contained in:
parent
ad1bd7f6e0
commit
129269c193
@ -19,9 +19,10 @@ class Post:
|
|||||||
target_name: Optional[str] = None
|
target_name: Optional[str] = None
|
||||||
compress: bool = False
|
compress: bool = False
|
||||||
override_use_pic: Optional[bool] = None
|
override_use_pic: Optional[bool] = None
|
||||||
|
|
||||||
pics: list[str] = field(default_factory=list)
|
pics: list[str] = field(default_factory=list)
|
||||||
|
|
||||||
|
_message: Optional[list] = None
|
||||||
|
|
||||||
def _use_pic(self):
|
def _use_pic(self):
|
||||||
if not self.override_use_pic is None:
|
if not self.override_use_pic is None:
|
||||||
return self.override_use_pic
|
return self.override_use_pic
|
||||||
@ -97,27 +98,29 @@ class Post:
|
|||||||
self.pics.insert(0, b64image)
|
self.pics.insert(0, b64image)
|
||||||
|
|
||||||
async def generate_messages(self):
|
async def generate_messages(self):
|
||||||
await self._pic_merge()
|
if self._message is None:
|
||||||
msgs = []
|
await self._pic_merge()
|
||||||
text = ''
|
msgs = []
|
||||||
if self.text:
|
text = ''
|
||||||
text += '{}'.format(self.text if len(self.text) < 500 else self.text[:500] + '...')
|
if self.text:
|
||||||
text += '\n来源: {}'.format(self.target_type)
|
text += '{}'.format(self.text if len(self.text) < 500 else self.text[:500] + '...')
|
||||||
if self.target_name:
|
text += '\n来源: {}'.format(self.target_type)
|
||||||
text += ' {}'.format(self.target_name)
|
if self.target_name:
|
||||||
if self._use_pic():
|
text += ' {}'.format(self.target_name)
|
||||||
msgs.append(await parse_text(text))
|
if self._use_pic():
|
||||||
if not self.target_type == 'rss' and self.url:
|
msgs.append(await parse_text(text))
|
||||||
msgs.append(self.url)
|
if not self.target_type == 'rss' and self.url:
|
||||||
else:
|
msgs.append(self.url)
|
||||||
if self.url:
|
else:
|
||||||
text += ' \n详情: {}'.format(self.url)
|
if self.url:
|
||||||
msgs.append(text)
|
text += ' \n详情: {}'.format(self.url)
|
||||||
for pic in self.pics:
|
msgs.append(text)
|
||||||
msgs.append("[CQ:image,file={url}]".format(url=pic))
|
for pic in self.pics:
|
||||||
if self.compress:
|
msgs.append("[CQ:image,file={url}]".format(url=pic))
|
||||||
msgs = [''.join(msgs)]
|
if self.compress:
|
||||||
return msgs
|
msgs = [''.join(msgs)]
|
||||||
|
self._message = msgs
|
||||||
|
return self._message
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return 'type: {}\nfrom: {}\ntext: {}\nurl: {}\npic: {}'.format(
|
return 'type: {}\nfrom: {}\ntext: {}\nurl: {}\npic: {}'.format(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user