diff --git a/README.md b/README.md index 62549289..cf39eabd 100644 --- a/README.md +++ b/README.md @@ -286,6 +286,7 @@ PS: **ARM平台** 请使用全量版 同时 **如果你的机器 RAM < 1G 可能 * 修复词条含有CQ回答的模糊匹配无法被解析 * 禁言检测图片在内存中获取图片hash * B站订阅在群里中任意群管理员可以统一管理(原来为管理员1无法删除管理员2的订阅) +* 修复原神资源查询地图api数据变更导致更新的地图不完全 ### 2022/8/27 diff --git a/plugins/genshin/query_resource_points/__init__.py b/plugins/genshin/query_resource_points/__init__.py index fcee9511..b17edf72 100755 --- a/plugins/genshin/query_resource_points/__init__.py +++ b/plugins/genshin/query_resource_points/__init__.py @@ -47,7 +47,7 @@ __plugin_block_limit__ = { qr = on_command("原神资源查询", aliases={"原神资源查找"}, priority=5, block=True) qr_lst = on_command("原神资源列表", priority=5, block=True) rex_qr = on_regex(".*?(在哪|在哪里|哪有|哪里有).*?", priority=5, block=True) -update_info = on_command("更新原神资源信息", permission=SUPERUSER, priority=1, block=True) +update_info = on_regex("^更新原神资源信息$", permission=SUPERUSER, priority=1, block=True) @qr.handle() diff --git a/plugins/genshin/query_resource_points/query_resource.py b/plugins/genshin/query_resource_points/query_resource.py index eb71e58a..3653731d 100755 --- a/plugins/genshin/query_resource_points/query_resource.py +++ b/plugins/genshin/query_resource_points/query_resource.py @@ -172,28 +172,29 @@ async def download_map_init(semaphore: Semaphore, flag: bool = False): if data["message"] == "OK": data = json.loads(data["data"]["info"]["detail"]) CENTER_POINT = (data["origin"][0], data["origin"][1]) - if not _map.exists(): + if not _map.exists() or flag: data = data["slices"] idx = 0 - for _map_data in data[0]: - map_url = _map_data["url"] - await download_image( - map_url, - map_path / f"{idx}.png", - semaphore, - force_flag=flag, - ) - BuildImage( - 0, 0, background=f"{map_path}/{idx}.png", ratio=MAP_RATIO - ).save() - idx += 1 - _w, h = BuildImage(0, 0, background=f"{map_path}/0.png").size - w = _w * len(os.listdir(map_path)) - map_file = BuildImage(w, h, _w, h, ratio=MAP_RATIO) + w_len = len(data[0]) + h_len = len(data) + for _map_data in data: + for _map in _map_data: + map_url = _map["url"] + await download_image( + map_url, + map_path / f"{idx}.png", + semaphore, + force_flag=flag, + ) + BuildImage( + 0, 0, background=f"{map_path}/{idx}.png", ratio=MAP_RATIO + ).save() + idx += 1 + w, h = BuildImage(0, 0, background=f"{map_path}/0.png").size + map_file = BuildImage(w * w_len, h * h_len, w, h, ratio=MAP_RATIO) for i in range(idx): - map_file.paste( - BuildImage(0, 0, background=f"{map_path}/{i}.png") - ) + img = BuildImage(0, 0, background=f"{map_path}/{i}.png") + await map_file.apaste(img) map_file.save(f"{map_path}/map.png") else: logger.warning(f'获取原神地图失败 msg: {data["message"]}') @@ -202,7 +203,7 @@ async def download_map_init(semaphore: Semaphore, flag: bool = False): except (TimeoutError, ConnectTimeout): logger.warning("下载原神地图数据超时....") except Exception as e: - logger.error(f"下载原神地图数据超时 {type(e)}:{e}") + logger.error(f"下载原神地图数据失败 {type(e)}:{e}") # 下载资源类型数据 diff --git a/utils/image_utils.py b/utils/image_utils.py index 6e329b5e..89d73147 100755 --- a/utils/image_utils.py +++ b/utils/image_utils.py @@ -178,8 +178,8 @@ class BuildImage: self.h = int(h) self.paste_image_width = int(paste_image_width) self.paste_image_height = int(paste_image_height) - self.current_w = 0 - self.current_h = 0 + self._current_w = 0 + self._current_h = 0 self.font = ImageFont.truetype(str(FONT_PATH / font), int(font_size)) if not plain_text and not color: color = (255, 255, 255) @@ -287,11 +287,11 @@ class BuildImage: pos = (width, height) if isinstance(img, BuildImage): img = img.markImg - if self.current_w == self.w: - self.current_w = 0 - self.current_h += self.paste_image_height + if self._current_w >= self.w: + self._current_w = 0 + self._current_h += self.paste_image_height if not pos: - pos = (self.current_w, self.current_h) + pos = (self._current_w, self._current_h) if alpha: try: self.markImg.paste(img, pos, img) @@ -300,7 +300,7 @@ class BuildImage: self.markImg.paste(img, pos, img) else: self.markImg.paste(img, pos) - self.current_w += self.paste_image_width + self._current_w += self.paste_image_width def getsize(self, msg: str) -> Tuple[int, int]: """