2024-08-15 18:22:24 +08:00
|
|
|
import traceback
|
|
|
|
|
2024-07-11 18:26:21 +08:00
|
|
|
from nonebot.typing import T_State
|
|
|
|
from typing import Optional
|
|
|
|
from .acgnapis import *
|
2024-07-11 20:27:23 +08:00
|
|
|
from nonebot_plugin_htmlrender import template_to_pic
|
2024-07-11 18:26:21 +08:00
|
|
|
from nonebot_plugin_alconna import on_alconna
|
2024-07-11 21:18:12 +08:00
|
|
|
from nonebot_plugin_alconna.uniseg import UniMessage
|
2024-07-11 18:26:21 +08:00
|
|
|
from arclet.alconna import Alconna, Args
|
|
|
|
from .config import RES_PATH, TEMPLATE_NAME, config
|
|
|
|
from .util import *
|
2024-07-11 19:00:25 +08:00
|
|
|
from .__init__ import __plugin_meta__
|
2024-08-15 18:22:24 +08:00
|
|
|
|
2024-07-11 18:26:21 +08:00
|
|
|
showcmd = on_alconna(
|
|
|
|
Alconna(
|
|
|
|
"展览",
|
|
|
|
Args["region?", str]["page?", int]["date?", str],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
showcmd.shortcut(
|
|
|
|
r"(?P<region>.+?)展览\s*(?P<page>\d+)?\s*(?P<date>.+)?",
|
|
|
|
{
|
2024-08-22 22:50:18 +08:00
|
|
|
"prefix": True,
|
|
|
|
"command": "展览",
|
|
|
|
"args": ["{region}", "{page}", "{date}"],
|
|
|
|
},
|
2024-07-11 18:26:21 +08:00
|
|
|
)
|
|
|
|
|
2024-08-15 18:22:24 +08:00
|
|
|
|
2024-07-11 18:26:21 +08:00
|
|
|
@showcmd.handle()
|
|
|
|
async def find_show(
|
2024-08-22 22:50:18 +08:00
|
|
|
region: Optional[str] = None,
|
|
|
|
page: Optional[int] = None,
|
|
|
|
date: Optional[str] = None,
|
2024-07-11 18:26:21 +08:00
|
|
|
):
|
2024-08-22 22:50:18 +08:00
|
|
|
if not region:
|
|
|
|
await UniMessage(__plugin_meta__.usage).send()
|
|
|
|
return
|
|
|
|
if not page:
|
|
|
|
page = 1
|
|
|
|
if not date:
|
|
|
|
date = ""
|
2024-08-15 18:22:24 +08:00
|
|
|
regions_dict = await get_regions_dict()
|
|
|
|
regionid = regions_dict.get(region, None)
|
2024-08-22 22:50:18 +08:00
|
|
|
if regionid == None:
|
|
|
|
await UniMessage("地区未寻得或输入格式错误").send()
|
|
|
|
return
|
2024-08-15 18:22:24 +08:00
|
|
|
# await showcmd.send("日期:"+ date)
|
|
|
|
shows = await get_shows_data(regionid, page=page, pagesize=config.acgnshow_pagesize)
|
2024-07-11 18:26:21 +08:00
|
|
|
# print(shows)
|
2024-07-11 21:35:28 +08:00
|
|
|
try:
|
2024-08-15 18:22:24 +08:00
|
|
|
shows_data = process_shows_data_to_template(shows)
|
2024-07-11 21:35:28 +08:00
|
|
|
template = {
|
2024-08-22 22:50:18 +08:00
|
|
|
"shows": shows_data[0],
|
|
|
|
"bgimage": choose_random_bgimage(),
|
|
|
|
"global_data": shows_data[1],
|
2024-08-15 18:22:24 +08:00
|
|
|
}
|
2024-08-22 22:50:18 +08:00
|
|
|
pic = await template_to_pic(str(RES_PATH), TEMPLATE_NAME, template)
|
2024-08-15 18:22:24 +08:00
|
|
|
except Exception as e:
|
2024-08-22 22:50:18 +08:00
|
|
|
await UniMessage("图片生成时产生未知错误").send()
|
2024-08-15 18:22:24 +08:00
|
|
|
traceback.print_exc()
|
2024-07-11 21:35:28 +08:00
|
|
|
return
|
2024-08-15 18:22:24 +08:00
|
|
|
|
|
|
|
await UniMessage.image(raw=pic).send()
|