This commit is contained in:
HibiKier
2022-05-21 13:15:53 +08:00
parent 86a8fe7096
commit 188ae38525
25 changed files with 153 additions and 124 deletions
+40 -33
View File
@@ -52,8 +52,8 @@ headers = {
async def _g(event: MessageEvent, state: T_State, pid: str = Arg("pid")):
if pid in ["取消", "算了"]:
await pid_search.finish("已取消操作...")
# if is_number(pid):
# await pid_search.reject_arg("pid", "笨蛋,重新输入数!字!")
if not is_number(pid):
await pid_search.reject_arg("pid", "笨蛋,重新输入数!字!")
for _ in range(3):
try:
data = (
@@ -68,39 +68,46 @@ async def _g(event: MessageEvent, state: T_State, pid: str = Arg("pid")):
except Exception as e:
await pid_search.finish(f"发生了一些错误..{type(e)}:{e}")
else:
if not data["illust"]["width"] and not data["illust"]["height"]:
data = data["illust"]
if not data["width"] and not data["height"]:
await pid_search.finish(f"没有搜索到 PID:{pid} 的图片", at_sender=True)
pid = data["illust"]["id"]
title = data["illust"]["title"]
author = data["illust"]["user"]["name"]
author_id = data["illust"]["user"]["id"]
img_url = data["illust"]["meta_single_page"]["original_image_url"]
if not await AsyncHttpx.download_file(
img_url,
IMAGE_PATH / "temp" / f"pid_search_{event.user_id}.png",
headers=headers,
):
await pid_search.finish("图片下载失败了....", at_sender=True)
tmp = ""
if isinstance(event, GroupMessageEvent):
tmp = "\n【注】将在30后撤回......"
msg_id = await pid_search.send(
Message(
f"title:{title}\n"
f"pid:{pid}\n"
f"author:{author}\n"
f"author_id:{author_id}\n"
f'{image(f"pid_search_{event.user_id}.png", "temp")}'
f"{tmp}"
pid = data["id"]
title = data["title"]
author = data["user"]["name"]
author_id = data["user"]["id"]
image_list = []
try:
image_list.append(data["meta_single_page"]["original_image_url"])
except KeyError:
for image_url in data["meta_pages"]:
image_list.append(image_url["image_urls"]["original"])
for i, img_url in enumerate(image_list):
if not await AsyncHttpx.download_file(
img_url,
IMAGE_PATH / "temp" / f"pid_search_{event.user_id}_{i}.png",
headers=headers,
):
await pid_search.send("图片下载失败了....", at_sender=True)
tmp = ""
if isinstance(event, GroupMessageEvent):
tmp = "\n【注】将在30后撤回......"
msg_id = await pid_search.send(
Message(
f"title:{title}\n"
f"pid:{pid}\n"
f"author:{author}\n"
f"author_id:{author_id}\n"
f'{image(f"pid_search_{event.user_id}_{i}.png", "temp")}'
f"{tmp}"
)
)
)
logger.info(
f"(USER {event.user_id}, "
f"GROUP {event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
f" 查询图片 PID:{pid}"
)
if isinstance(event, GroupMessageEvent):
withdraw_message_manager.append((msg_id, 30))
logger.info(
f"(USER {event.user_id}, "
f"GROUP {event.group_id if isinstance(event, GroupMessageEvent) else 'private'})"
f" 查询图片 PID:{pid}"
)
if isinstance(event, GroupMessageEvent):
withdraw_message_manager.append((msg_id, 30))
break
else:
await pid_search.finish("图片下载失败了....", at_sender=True)