mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-05 19:36:43 +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:
|
async def parse(self, raw_post: RawPost) -> Post:
|
||||||
card_content = json.loads(raw_post['card'])
|
card_content = json.loads(raw_post['card'])
|
||||||
post_type = self.get_category(raw_post)
|
post_type = self.get_category(raw_post)
|
||||||
|
target_name = raw_post['desc']['user_profile']['info']['uname']
|
||||||
if post_type == 1:
|
if post_type == 1:
|
||||||
# 一般动态
|
# 一般动态
|
||||||
text = card_content['item']['description']
|
text = card_content['item']['description']
|
||||||
@ -88,5 +89,5 @@ class Bilibili(Platform):
|
|||||||
pic = []
|
pic = []
|
||||||
else:
|
else:
|
||||||
raise CategoryNotSupport(post_type)
|
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')
|
soup = bs(raw_post.description, 'html.parser')
|
||||||
text = soup.text
|
text = soup.text
|
||||||
pics = list(map(lambda x: x.attrs['src'], soup('img')))
|
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:
|
def _get_text(self, raw_text: str) -> str:
|
||||||
text = raw_text.replace('<br />', '\n')
|
text = raw_text.replace('<br />', '\n')
|
||||||
return bs(text).text
|
return bs(text).text
|
||||||
|
|
||||||
async def parse(self, raw_post: RawPost) -> Post:
|
async def parse(self, raw_post: RawPost) -> Post:
|
||||||
info = raw_post['mblog']
|
info = raw_post['mblog']
|
||||||
if info['isLongText'] or info['pic_num'] > 9:
|
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', [])]
|
pic_urls = [img['large']['url'] for img in info.get('pics', [])]
|
||||||
detail_url = 'https://weibo.com/{}/{}'.format(info['user']['id'], info['bid'])
|
detail_url = 'https://weibo.com/{}/{}'.format(info['user']['id'], info['bid'])
|
||||||
# return parsed_text, detail_url, pic_urls
|
# 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 dataclasses import dataclass, field
|
||||||
|
from typing import Optional
|
||||||
from .plugin_config import plugin_config
|
from .plugin_config import plugin_config
|
||||||
from .utils import parse_text
|
from .utils import parse_text
|
||||||
|
|
||||||
@ -8,21 +9,33 @@ class Post:
|
|||||||
target_type: str
|
target_type: str
|
||||||
text: str
|
text: str
|
||||||
url: str
|
url: str
|
||||||
|
target_name: Optional[str] = None
|
||||||
|
show_text: bool = True
|
||||||
pics: list[str] = field(default_factory=list)
|
pics: list[str] = field(default_factory=list)
|
||||||
|
|
||||||
async def generate_messages(self):
|
async def generate_messages(self):
|
||||||
if plugin_config.hk_reporter_use_pic:
|
msgs = []
|
||||||
text_msg = '来源: {}\n{}'.format(self.target_type, self.text)
|
if self.show_text:
|
||||||
if self.target_type == 'rss':
|
text = '来源: {}'.format(self.target_type)
|
||||||
res = [await parse_text(text_msg)]
|
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:
|
else:
|
||||||
res = [await parse_text(text_msg), self.url]
|
text += '详情: {}'.format(self.url)
|
||||||
else:
|
msgs.append(text)
|
||||||
first_msg = '来源: {}\n{}\n详情:{}'.format(self.target_type, self.text, self.url)
|
|
||||||
res = [first_msg]
|
|
||||||
for pic in self.pics:
|
for pic in self.pics:
|
||||||
res.append("[CQ:image,file={url}]".format(url=pic))
|
msgs.append("[CQ:image,file={url}]".format(url=pic))
|
||||||
return res
|
return msgs
|
||||||
|
|
||||||
def __str__(self):
|
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