mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-04 02:26:11 +08:00
update post
This commit is contained in:
parent
e43c4edea4
commit
30447f1299
@ -66,6 +66,7 @@ class Bilibili(Platform):
|
||||
async def parse(self, raw_post: RawPost) -> Post:
|
||||
card_content = json.loads(raw_post['card'])
|
||||
post_type = self.get_category(raw_post)
|
||||
target_name = raw_post['desc']['user_profile']['info']['uname']
|
||||
if post_type == 1:
|
||||
# 一般动态
|
||||
text = card_content['item']['description']
|
||||
@ -88,5 +89,5 @@ class Bilibili(Platform):
|
||||
pic = []
|
||||
else:
|
||||
raise CategoryNotSupport(post_type)
|
||||
return Post('bilibili', text, url, pic)
|
||||
return Post('bilibili', text=text, url=url, pics=pic, target_name=target_name)
|
||||
|
||||
|
@ -38,4 +38,4 @@ class Rss(Platform):
|
||||
soup = bs(raw_post.description, 'html.parser')
|
||||
text = soup.text
|
||||
pics = list(map(lambda x: x.attrs['src'], soup('img')))
|
||||
return Post('rss', text, raw_post.link, pics)
|
||||
return Post('rss', text=text, url=raw_post.link, pics=pics)
|
||||
|
@ -69,7 +69,7 @@ class Weibo(Platform):
|
||||
def _get_text(self, raw_text: str) -> str:
|
||||
text = raw_text.replace('<br />', '\n')
|
||||
return bs(text).text
|
||||
|
||||
|
||||
async def parse(self, raw_post: RawPost) -> Post:
|
||||
info = raw_post['mblog']
|
||||
if info['isLongText'] or info['pic_num'] > 9:
|
||||
@ -81,4 +81,4 @@ class Weibo(Platform):
|
||||
pic_urls = [img['large']['url'] for img in info.get('pics', [])]
|
||||
detail_url = 'https://weibo.com/{}/{}'.format(info['user']['id'], info['bid'])
|
||||
# return parsed_text, detail_url, pic_urls
|
||||
return Post('weibo', parsed_text, detail_url, pic_urls)
|
||||
return Post('weibo', text=parsed_text, url=detail_url, pics=pic_urls, target_name=info['user']['screen_name'])
|
||||
|
@ -1,4 +1,5 @@
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Optional
|
||||
from .plugin_config import plugin_config
|
||||
from .utils import parse_text
|
||||
|
||||
@ -8,21 +9,33 @@ class Post:
|
||||
target_type: str
|
||||
text: str
|
||||
url: str
|
||||
target_name: Optional[str] = None
|
||||
show_text: bool = True
|
||||
pics: list[str] = field(default_factory=list)
|
||||
|
||||
async def generate_messages(self):
|
||||
if plugin_config.hk_reporter_use_pic:
|
||||
text_msg = '来源: {}\n{}'.format(self.target_type, self.text)
|
||||
if self.target_type == 'rss':
|
||||
res = [await parse_text(text_msg)]
|
||||
msgs = []
|
||||
if self.show_text:
|
||||
text = '来源: {}'.format(self.target_type)
|
||||
if self.target_name:
|
||||
text += '\n{}'.format(self.target_name)
|
||||
if self.text:
|
||||
text += '\n{}'.format(self.text)
|
||||
if plugin_config.hk_reporter_use_pic:
|
||||
msgs.append(await parse_text(text))
|
||||
if not self.target_type == 'rss':
|
||||
msgs.append(self.url)
|
||||
else:
|
||||
res = [await parse_text(text_msg), self.url]
|
||||
else:
|
||||
first_msg = '来源: {}\n{}\n详情:{}'.format(self.target_type, self.text, self.url)
|
||||
res = [first_msg]
|
||||
text += '详情: {}'.format(self.url)
|
||||
msgs.append(text)
|
||||
for pic in self.pics:
|
||||
res.append("[CQ:image,file={url}]".format(url=pic))
|
||||
return res
|
||||
msgs.append("[CQ:image,file={url}]".format(url=pic))
|
||||
return msgs
|
||||
|
||||
def __str__(self):
|
||||
return 'type: {}\ntext: {}\nurl: {}\npic: {}'.format(self.target_type, self.text, self.url, ','.join(map(lambda x: 'b64img' if x.startswith('base64') else x, self.pics)))
|
||||
return 'type: {}\ntext: {}\nurl: {}\npic: {}'.format(
|
||||
self.target_type,
|
||||
self.text,
|
||||
self.url,
|
||||
', '.join(map(lambda x: 'b64img' if x.startswith('base64') else x, self.pics))
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user