1- from aioarxiv .client .arxiv_client import ArxivClient
1+ from aioarxiv .client .arxiv_client import ArxivClient , SortCriterion , SortOrder
22from arclet .alconna import Alconna , Args , Subcommand
33from nonebot .log import logger
44from nonebot .typing import T_State
5- from nonebot_plugin_alconna import Image , UniMessage , UniMsg , on_alconna
5+ from nonebot_plugin_alconna import (
6+ AlconnaQuery ,
7+ Image ,
8+ Option ,
9+ Query ,
10+ UniMessage ,
11+ UniMsg ,
12+ on_alconna ,
13+ )
614from nonebot_plugin_htmlrender import capture_element
715from nonebot_plugin_uninfo import Uninfo
816
1422 Subcommand (
1523 "-s|--search" ,
1624 Args ["keyword" , str ],
25+ Option ("--number" , Args ["number" , int ]),
26+ Option (
27+ "--sort" ,
28+ Args ["sort" , ["relevance" , "lastUpdatedDate" , "submittedDate" ]],
29+ ),
30+ Option ("--order" , Args ["order" , ["ascending" , "descending" ]]),
31+ Option ("--start" , Args ["start" , int ]),
1732 ),
1833 Subcommand (
1934 "-id" ,
2641
2742
2843@paper_cmd .assign ("search" )
29- async def handle_search (keyword : str , state : T_State , uninfo : Uninfo , unimsg : UniMsg ):
44+ async def handle_search (
45+ keyword : str ,
46+ state : T_State ,
47+ uninfo : Uninfo ,
48+ unimsg : UniMsg ,
49+ number : Query [int ] = AlconnaQuery ("number" , 1 ),
50+ sort : Query [SortCriterion | None ] = AlconnaQuery ("sort" , None ),
51+ order : Query [SortOrder | None ] = AlconnaQuery ("order" , None ),
52+ start : Query [int | None ] = AlconnaQuery ("start" , None ),
53+ ):
3054 logger .debug (f"Searching for { keyword } by { uninfo .user .id } " )
3155 async with ArxivClient () as client :
3256 result = await client .search (
3357 keyword ,
34- max_results = 1 ,
58+ max_results = number .result ,
59+ sort_by = sort .result ,
60+ sort_order = order .result ,
61+ start = start .result ,
3562 )
3663 await paper_cmd .send (
3764 f"Search result for { keyword } and get { result .total_result } papers"
@@ -41,10 +68,10 @@ async def handle_search(keyword: str, state: T_State, uninfo: Uninfo, unimsg: Un
4168
4269
4370@paper_cmd .assign ("id" )
44- async def handle_id (paper_id : str , state : T_State , uninfo : Uninfo , unimsg : UniMsg ):
45- logger .debug (f"Searching for { paper_id } by { uninfo .user .id } " )
71+ async def handle_id (id : str , state : T_State , uninfo : Uninfo , unimsg : UniMsg ):
72+ logger .debug (f"Searching for { id } by { uninfo .user .id } " )
4673 img = await capture_element (
47- f"https://arxiv.org/abs/{ paper_id } " ,
74+ f"https://arxiv.org/abs/{ id } " ,
4875 element = "#abs-outer > div.leftcolumn" ,
4976 )
5077 await UniMessage (Image (raw = img )).finish (reply_to = True )
0 commit comments