Archived
1
0
Fork 0

support screenshot for template doc

This commit is contained in:
yzhh 2023-01-17 00:18:15 +08:00
parent 5e21623638
commit 94e879ba87
3 changed files with 18 additions and 9 deletions

View file

@ -10,13 +10,16 @@ from core.utils import download_to_cache
web_render = Config('web_render_local')
async def generate_screenshot(page_link, section=None, allow_special_page=False) -> Union[str, bool]:
elements = ['.notaninfobox', '.portable-infobox', '.infobox', '.tpl-infobox', '.infoboxtable',
'.infotemplatebox', '.skin-infobox', '.arcaeabox', '.moe-infobox']
async def generate_screenshot(page_link, section=None, allow_special_page=False, doc_mode=False) -> Union[str, bool]:
elements = ['.notaninfobox', '.portable-infobox', '.infobox', '.tpl-infobox', '.infoboxtable', '.infotemplatebox',
'.skin-infobox', '.arcaeabox', '.moe-infobox']
if not web_render:
return False
if section is None:
if allow_special_page:
if allow_special_page and doc_mode:
page_link += '/doc'
elements.insert(0, '.mw-parser-output')
if allow_special_page and not doc_mode:
elements.insert(0, '.diff')
Logger.info('[Webrender] Generating element screenshot...')
try:

View file

@ -103,6 +103,7 @@ class PageInfo:
status: bool = True,
before_page_property: str = 'page',
page_property: str = 'page',
has_template_doc: bool = False,
invalid_namespace: Union[str, bool] = False,
possible_research_title: List[str] = None
):
@ -119,6 +120,7 @@ class PageInfo:
self.status = status
self.before_page_property = before_page_property
self.page_property = page_property
self.has_template_doc = has_template_doc
self.invalid_namespace = invalid_namespace
self.possible_research_title = possible_research_title
@ -625,6 +627,8 @@ class WikiLib:
get_desc = False
get_doc_desc = await self.parse_page_info(get_doc, _doc=True)
page_desc = get_doc_desc.desc
if page_desc is not None:
page_info.has_template_doc = True
page_info.before_page_property = page_info.page_property = 'template'
if get_desc:
if use_textextracts and section is None:

View file

@ -195,7 +195,8 @@ async def query_pages(session: Union[MessageSession, QueryInfo], title: Union[st
else:
if r.link is not None and r.section is None:
render_infobox_list.append(
{r.link: {'url': r.info.realurl, 'in_allowlist': r.info.in_allowlist}})
{r.link: {'url': r.info.realurl, 'in_allowlist': r.info.in_allowlist,
'has_doc': r.has_template_doc}})
elif r.link is not None and r.section is not None and r.info.in_allowlist:
render_section_list.append(
{r.link: {'url': r.info.realurl, 'section': r.section,
@ -257,8 +258,8 @@ async def query_pages(session: Union[MessageSession, QueryInfo], title: Union[st
msg_list.append(Plain(f'发生错误:' + str(e)))
if isinstance(session, MessageSession):
if msg_list:
if all(
[not render_infobox_list, not render_section_list, not dl_list, not wait_list, not wait_possible_list]):
if all([not render_infobox_list, not render_section_list,
not dl_list, not wait_list, not wait_possible_list]):
await session.finish(msg_list)
else:
await session.sendMessage(msg_list)
@ -268,7 +269,8 @@ async def query_pages(session: Union[MessageSession, QueryInfo], title: Union[st
infobox_msg_list = []
for i in render_infobox_list:
for ii in i:
get_infobox = await generate_screenshot(ii, allow_special_page=i[ii]['in_allowlist'])
get_infobox = await generate_screenshot(ii, allow_special_page=i[ii]['in_allowlist'],
doc_mode=i[ii]['has_doc'])
if get_infobox:
infobox_msg_list.append(Image(get_infobox))
infobox_msg_list.append(Plain('*我们正在测试新的窗口截图方式,如您遇到机器人发送的图片发生错位等情况,请及时报告。报告地址:'
@ -286,7 +288,7 @@ async def query_pages(session: Union[MessageSession, QueryInfo], title: Union[st
if get_section:
section_msg_list.append(Image(get_section))
section_msg_list.append(Plain('*我们正在测试新的窗口截图方式,如您遇到机器人发送的图片发生错位等情况,请及时报告。报告地址:'
'https://s.wd-ljt.com/botreportbug'))
'https://s.wd-ljt.com/botreportbug'))
if section_msg_list:
await session.sendMessage(section_msg_list, quote=False)