mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-09-28 16:20:56 +08:00
@@ -4,7 +4,7 @@ from asyncio.locks import Semaphore
|
||||
from asyncio.exceptions import TimeoutError
|
||||
from ._model.pixiv import Pixiv
|
||||
from typing import List, Optional
|
||||
from utils.utils import change_pixiv_image_links
|
||||
from utils.utils import change_pixiv_image_links, change_img_md5
|
||||
from utils.image_utils import BuildImage
|
||||
from utils.http_utils import AsyncHttpx
|
||||
from services.log import logger
|
||||
@@ -238,6 +238,7 @@ async def get_image(img_url: str, user_id: int) -> Optional[str]:
|
||||
TEMP_PATH / f"pix_{user_id}_{img_url.split('/')[-1][:-4]}.jpg", "wb"
|
||||
) as f:
|
||||
await f.write(response.content)
|
||||
change_img_md5(TEMP_PATH / f"pix_{user_id}_{img_url.split('/')[-1][:-4]}.jpg")
|
||||
return TEMP_PATH / f"pix_{user_id}_{img_url.split('/')[-1][:-4]}.jpg"
|
||||
except TimeoutError:
|
||||
logger.warning(f"PIX:{img_url} 图片下载超时...")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from configs.path_config import IMAGE_PATH
|
||||
from utils.message_builder import image
|
||||
from utils.utils import change_img_md5
|
||||
from asyncio.exceptions import TimeoutError
|
||||
from configs.config import Config
|
||||
from utils.http_utils import AsyncHttpx
|
||||
@@ -143,6 +144,7 @@ async def download_pixiv_imgs(
|
||||
file,
|
||||
timeout=Config.get_config("pixiv_rank_search", "TIMEOUT"),
|
||||
):
|
||||
change_img_md5(file)
|
||||
if forward_msg_index is not None:
|
||||
result += image(
|
||||
f"{user_id}_{forward_msg_index}_{index}_pixiv.jpg",
|
||||
|
||||
@@ -2,6 +2,7 @@ from configs.path_config import IMAGE_PATH, TEMP_PATH
|
||||
from utils.message_builder import image
|
||||
from services.log import logger
|
||||
from utils.image_utils import get_img_hash, compressed_image
|
||||
from utils.utils import change_img_md5
|
||||
from asyncpg.exceptions import UniqueViolationError
|
||||
from asyncio.exceptions import TimeoutError
|
||||
from typing import List, Optional
|
||||
@@ -111,6 +112,7 @@ async def search_online_setu(
|
||||
path_ / f"{index}.jpg",
|
||||
)
|
||||
logger.info(f"下载 lolicon 图片 {url_} 成功, id:{index}")
|
||||
change_img_md5(path_ / file_name)
|
||||
return image(path_ / file_name), index
|
||||
except TimeoutError:
|
||||
pass
|
||||
@@ -128,6 +130,7 @@ async def check_local_exists_or_download(setu_image: Setu) -> "MessageSegment, i
|
||||
path_ = r18_path if setu_image.is_r18 else path
|
||||
file = IMAGE_PATH / path_ / f"{setu_image.local_id}.jpg"
|
||||
if file.exists():
|
||||
change_img_md5(file)
|
||||
return image(f"{setu_image.local_id}.jpg", path_), 200
|
||||
return await search_online_setu(setu_image.img_url, id_, path_)
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ from configs.config import SYSTEM_PROXY, Config
|
||||
from typing import List, Union, Optional, Type, Any
|
||||
from nonebot.adapters.onebot.v11 import Bot, Message
|
||||
from nonebot.matcher import matchers, Matcher
|
||||
from services.log import logger
|
||||
from pathlib import Path
|
||||
import httpx
|
||||
import nonebot
|
||||
import pytz
|
||||
@@ -398,3 +400,19 @@ def change_pixiv_image_links(
|
||||
.replace("_webp", "")
|
||||
)
|
||||
return url
|
||||
|
||||
|
||||
def change_img_md5(path_file: Union[str, Path]) -> bool:
|
||||
"""
|
||||
说明:
|
||||
改变图片MD5
|
||||
参数:
|
||||
:param path_file: 图片路径
|
||||
"""
|
||||
try:
|
||||
with open(path_file, "a") as f:
|
||||
f.write(str(int(time.time() * 1000)))
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.warning(f"改变图片MD5发生错误 {type(e)}:{e} Path:{path_file}")
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user