Skip to content

Commit 2caeda3

Browse files
committed
♻️ simplify paper information formatting and update allowed render types
1 parent 7a0081e commit 2caeda3

File tree

3 files changed

+17
-27
lines changed

3 files changed

+17
-27
lines changed

nonebot_plugin_paper/command.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
from pathlib import Path
2-
31
from aioarxiv.client.arxiv_client import ArxivClient
42
from arclet.alconna import Alconna, Args, Subcommand
53
from nonebot.log import logger
64
from nonebot.typing import T_State
7-
from nonebot_plugin_alconna import Image, UniMsg, on_alconna
8-
from nonebot_plugin_htmlrender import template_to_pic
5+
from nonebot_plugin_alconna import UniMsg, on_alconna
96
from nonebot_plugin_uninfo import Uninfo
107

8+
from nonebot_plugin_paper.utils import text_paper_info
9+
1110
paper_cmd = on_alconna(
1211
Alconna(
1312
"paper",
@@ -37,15 +36,4 @@ async def handle_search(keyword: str, state: T_State, uninfo: Uninfo, unimsg: Un
3736
f"Search result for {keyword} and get {result.total_result} papers"
3837
)
3938
for paper in result.papers:
40-
# await paper_cmd.send(text_paper_info(paper))
41-
await paper_cmd.send(
42-
Image(
43-
raw=(
44-
await template_to_pic(
45-
template_path=str(Path(__file__).parent / "jinja_temple"),
46-
template_name="paper.jinja2",
47-
templates={"paper": paper.model_dump()},
48-
)
49-
)
50-
)
51-
)
39+
await paper_cmd.send(text_paper_info(paper))

nonebot_plugin_paper/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
@custom_validation
1313
class RenderType(str):
14-
ALLOWED_VALUES: ClassVar = ["playwright", "pillow", "plaintext"]
14+
ALLOWED_VALUES: ClassVar = ["playwright", "pillow", "plaintext", "skia"]
1515

1616
@classmethod
1717
def __get_validators__(cls) -> Generator[Callable[..., Any], None, None]:
@@ -21,6 +21,8 @@ def __get_validators__(cls) -> Generator[Callable[..., Any], None, None]:
2121
def validate(cls, value: str) -> str:
2222
if value.lower() == "pillow":
2323
raise NotImplementedError("Pillow render is not implemented yet")
24+
if value.lower() == "skia":
25+
raise NotImplementedError("Skia render is not implemented yet")
2426
if value.lower() not in cls.ALLOWED_VALUES:
2527
raise ValueError(
2628
f"Invalid type: {value!r}, must be one of {cls.ALLOWED_VALUES}"

nonebot_plugin_paper/utils.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@ def text_paper_info(paper: Paper) -> str:
2626
)
2727

2828
template = (
29-
f"📄 **Title:** {paper.info.title}\n"
30-
f"👥 **Authors:** {authors}\n"
31-
f"🏷️ **Categories:** {paper.info.categories.primary.term}\n"
32-
f"📅 **Published Date:** {published_date}\n"
33-
f"🔄 **Updated Date:** {updated_date}\n"
34-
f"📝 **Summary:** {summary}\n"
29+
f"📄 Title: {paper.info.title}\n"
30+
f"👥 Authors: {authors}\n"
31+
f"🏷️ Categories: {paper.info.categories.primary.term}\n"
32+
f"📅 Published Date: {published_date}\n"
33+
f"🔄 Updated Date: {updated_date}\n"
34+
f"📝 Summary: {summary}\n"
3535
)
3636

3737
if paper.doi:
38-
template += f"🔗 **DOI:** {paper.doi}\n"
38+
template += f"🔗 DOI: {paper.doi}\n"
3939
if paper.journal_ref:
40-
template += f"📚 **Journal Reference:** {paper.journal_ref}\n"
40+
template += f"📚 Journal Reference: {paper.journal_ref}\n"
4141
if paper.pdf_url:
42-
template += f"📥 **PDF Download Link:** {paper.pdf_url}\n"
42+
template += f"📥 PDF Download Link: {paper.pdf_url}\n"
4343
if paper.comment:
44-
template += f"💬 **Comment:** {paper.comment}\n"
44+
template += f"💬 Comment: {paper.comment}\n"
4545

4646
return template
4747

0 commit comments

Comments
 (0)