From 5f118471cbc3a4d2bcc687f35ee129122fae0778 Mon Sep 17 00:00:00 2001 From: HibiKier <775757368@qq.com> Date: Fri, 16 Sep 2022 19:29:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9B=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + README.md | 7 + basic_plugins/apscheduler/__init__.py | 4 +- .../init_plugins_settings.py | 147 +++++++++--------- plugins/bilibili_sub/__init__.py | 4 +- plugins/fudu.py | 21 +-- plugins/genshin/query_resource_points/map.py | 2 +- 7 files changed, 96 insertions(+), 91 deletions(-) diff --git a/.gitignore b/.gitignore index 031a9ce5..f9197b7e 100644 --- a/.gitignore +++ b/.gitignore @@ -159,3 +159,5 @@ resources/ !/configs/config.yaml !/.env !/.env.dev +!/plugins/csgo_server/ +!/plugins/activity/ diff --git a/README.md b/README.md index 64936bfe..e5932c33 100644 --- a/README.md +++ b/README.md @@ -279,9 +279,16 @@ PS: **ARM平台** 请使用全量版 同时 **如果你的机器 RAM < 1G 可能 ## 更新 +### 2022/9/16 + +* fix: bilibili_sub, azur_draw_card [@pull/1090](https://github.com/HibiKier/zhenxun_bot/pull/1090) +* 修复原神资源查询查询完毕后图片存储错误 +* b站订阅发送 与 b站订阅 使用相同开关,即:关闭b站订阅 + ### 2022/9/10 * 自定义群欢迎消息参数不完全时提示报错 +* 修改bt插件的url地址 [@pull/1067](https://github.com/HibiKier/zhenxun_bot/pull/1067) ### 2022/9/8 diff --git a/basic_plugins/apscheduler/__init__.py b/basic_plugins/apscheduler/__init__.py index f3c87249..5b6d2370 100755 --- a/basic_plugins/apscheduler/__init__.py +++ b/basic_plugins/apscheduler/__init__.py @@ -60,7 +60,7 @@ async def _(): try: await bot.send_group_msg(group_id=g, message="[[_task|zwa]]早上好" + result) except ActionFailed: - logger.warning(f"{g} 群被禁言中,无法发送早安") + logger.warning(f"{g} 发送早安失败") except Exception as e: logger.error(f"早晚安错误 e:{e}") @@ -83,7 +83,7 @@ async def _(): group_id=g, message=f"[[_task|zwa]]{NICKNAME}要睡觉了,你们也要早点睡呀" + result ) except ActionFailed: - logger.warning(f"{g} 群被禁言中,无法发送晚安") + logger.warning(f"{g} 发送晚安失败") except Exception as e: logger.error(f"早晚安错误 e:{e}") diff --git a/basic_plugins/init_plugin_config/init_plugins_settings.py b/basic_plugins/init_plugin_config/init_plugins_settings.py index 6492c6fd..6bd91806 100755 --- a/basic_plugins/init_plugin_config/init_plugins_settings.py +++ b/basic_plugins/init_plugin_config/init_plugins_settings.py @@ -34,84 +34,87 @@ def init_plugins_settings(data_path: str): logger.warning(f"配置文件 模块:{x} 获取 plugin_name 失败...{e}") _tmp_module[x] = "" for matcher in _matchers: - if matcher.plugin_name not in plugins2settings_manager.keys(): - _plugin = matcher.plugin - if not _plugin: - continue - metadata = _plugin.metadata - try: - _module = _plugin.module - except AttributeError: - logger.warning(f"插件 {matcher.plugin_name} 加载失败...,插件控制未加载.") - else: + try: + if matcher.plugin_name not in plugins2settings_manager.keys(): + _plugin = matcher.plugin + if not _plugin: + continue + metadata = _plugin.metadata try: - if metadata: - plugin_name = metadata.name + _module = _plugin.module + except AttributeError: + logger.warning(f"插件 {matcher.plugin_name} 加载失败...,插件控制未加载.") + else: + try: + if metadata: + plugin_name = metadata.name + else: + plugin_name = _module.__getattribute__("__zx_plugin_name__") + if "[admin]" in plugin_name.lower(): + try: + admin_settings = _module.__getattribute__( + "__plugin_settings__" + ) + level = admin_settings["admin_level"] + cmd = admin_settings.get("cmd") + except (AttributeError, KeyError): + level = 5 + cmd = None + if level is None: + level = 5 + admin_manager.add_admin_plugin_settings( + matcher.plugin_name, cmd, level + ) + if ( + "[hidden]" in plugin_name.lower() + or "[admin]" in plugin_name.lower() + or "[superuser]" in plugin_name.lower() + or matcher.plugin_name in plugins2settings_manager.keys() + ): + continue + except AttributeError: + if matcher.plugin_name not in _tmp: + logger.warning( + f"获取插件 {matcher.plugin_name} __zx_plugin_name__ 失败...,插件控制未加载." + ) else: - plugin_name = _module.__getattribute__("__zx_plugin_name__") - if "[admin]" in plugin_name.lower(): + _tmp_module[matcher.plugin_name] = plugin_name try: - admin_settings = _module.__getattribute__( + plugin_settings = _module.__getattribute__( "__plugin_settings__" ) - level = admin_settings["admin_level"] - cmd = admin_settings.get("cmd") - except (AttributeError, KeyError): - level = 5 - cmd = None - if level is None: - level = 5 - admin_manager.add_admin_plugin_settings( - matcher.plugin_name, cmd, level - ) - if ( - "[hidden]" in plugin_name.lower() - or "[admin]" in plugin_name.lower() - or "[superuser]" in plugin_name.lower() - or matcher.plugin_name in plugins2settings_manager.keys() - ): - continue - except AttributeError: - if matcher.plugin_name not in _tmp: - logger.warning( - f"获取插件 {matcher.plugin_name} __zx_plugin_name__ 失败...,插件控制未加载." - ) - else: - _tmp_module[matcher.plugin_name] = plugin_name - try: - plugin_settings = _module.__getattribute__( - "__plugin_settings__" - ) - except AttributeError: - plugin_settings = {"cmd": [matcher.plugin_name, plugin_name]} - if not plugin_settings.get("cost_gold"): - plugin_settings["cost_gold"] = 0 - if ( - plugin_settings.get("cmd") is not None - and plugin_name not in plugin_settings["cmd"] - ): - plugin_settings["cmd"].append(plugin_name) - if plugins2settings_manager.get( - matcher.plugin_name - ) and plugins2settings_manager[matcher.plugin_name].get( - "plugin_type" - ): - plugin_type = tuple( - plugins2settings_manager.get_plugin_data( - matcher.plugin_name - )["plugin_type"] - ) - else: - try: - plugin_type = _module.__getattribute__("__plugin_type__") except AttributeError: - plugin_type = ("normal",) - if plugin_settings and matcher.plugin_name: - plugins2settings_manager.add_plugin_settings( - matcher.plugin_name, - plugin_type=plugin_type, - **plugin_settings, - ) + plugin_settings = {"cmd": [matcher.plugin_name, plugin_name]} + if not plugin_settings.get("cost_gold"): + plugin_settings["cost_gold"] = 0 + if ( + plugin_settings.get("cmd") is not None + and plugin_name not in plugin_settings["cmd"] + ): + plugin_settings["cmd"].append(plugin_name) + if plugins2settings_manager.get( + matcher.plugin_name + ) and plugins2settings_manager[matcher.plugin_name].get( + "plugin_type" + ): + plugin_type = tuple( + plugins2settings_manager.get_plugin_data( + matcher.plugin_name + )["plugin_type"] + ) + else: + try: + plugin_type = _module.__getattribute__("__plugin_type__") + except AttributeError: + plugin_type = ("normal",) + if plugin_settings and matcher.plugin_name: + plugins2settings_manager.add_plugin_settings( + matcher.plugin_name, + plugin_type=plugin_type, + **plugin_settings, + ) + except Exception as e: + logger.error(f'{matcher.plugin_name} 初始化 plugin_settings 发生错误 {type(e)}:{e}') _tmp.append(matcher.plugin_name) _tmp_data = {"PluginSettings": plugins2settings_manager.get_data()} with open(plugins2settings_file, "w", encoding="utf8") as wf: diff --git a/plugins/bilibili_sub/__init__.py b/plugins/bilibili_sub/__init__.py index b43740b5..88672968 100755 --- a/plugins/bilibili_sub/__init__.py +++ b/plugins/bilibili_sub/__init__.py @@ -15,6 +15,7 @@ from .data_source import ( BilibiliSub, ) from models.level_user import LevelUser +from utils.manager import group_manager from configs.config import Config from utils.utils import is_number, scheduler, get_bot from typing import Optional, Tuple, Any @@ -267,7 +268,8 @@ async def send_sub_msg(rst: str, sub: BilibiliSub, bot: Bot): and Config.get_config("bilibili_sub", "UP_MSG_AT_ALL") ): rst = "[CQ:at,qq=all]\n" + rst - await bot.send_group_msg(group_id=group_id, message=Message(rst)) + if group_manager.get_plugin_status("bilibili_sub", group_id): + await bot.send_group_msg(group_id=group_id, message=Message(rst)) else: await bot.send_private_msg(user_id=int(x), message=Message(rst)) except Exception as e: diff --git a/plugins/fudu.py b/plugins/fudu.py index 0de3d20f..b642ed50 100755 --- a/plugins/fudu.py +++ b/plugins/fudu.py @@ -1,6 +1,8 @@ +from io import BytesIO +import imagehash +from PIL import Image from nonebot.adapters.onebot.v11.permission import GROUP from configs.path_config import TEMP_PATH -from utils.image_utils import get_img_hash import random from utils.message_builder import image from nonebot import on_message @@ -8,7 +10,6 @@ from utils.utils import get_message_img, get_message_text from nonebot.adapters.onebot.v11 import GroupMessageEvent from configs.config import Config from utils.http_utils import AsyncHttpx -from services.log import logger from configs.config import NICKNAME @@ -90,7 +91,7 @@ async def _(event: GroupMessageEvent): if not img and not msg: return if img: - img_hash = await get_fudu_img_hash(img[0], event.group_id) + img_hash = await get_fudu_img_hash(img[0]) else: img_hash = "" add_msg = msg + "|-|" + img_hash @@ -123,15 +124,5 @@ async def _(event: GroupMessageEvent): await fudu.finish("[[_task|fudu]]" + rst) -async def get_fudu_img_hash(url, group_id): - try: - if await AsyncHttpx.download_file( - url, TEMP_PATH / f"compare_{group_id}_img.jpg" - ): - img_hash = get_img_hash(TEMP_PATH / f"compare_{group_id}_img.jpg") - return str(img_hash) - else: - logger.warning(f"复读下载图片失败...") - except Exception as e: - logger.warning(f"复读读取图片Hash出错 {type(e)}:{e}") - return "" +async def get_fudu_img_hash(url): + return str(imagehash.average_hash(Image.open(BytesIO((await AsyncHttpx.get(url)).content)))) diff --git a/plugins/genshin/query_resource_points/map.py b/plugins/genshin/query_resource_points/map.py index 74cfd79a..be0e01be 100755 --- a/plugins/genshin/query_resource_points/map.py +++ b/plugins/genshin/query_resource_points/map.py @@ -118,7 +118,7 @@ class Map: self._generate_best_route() self.map.crop((min_width, min_height, max_width, max_height)) rand = random.randint(1, 10000) - self.map.save(f"{IMAGE_PATH}/temp/genshin_map_{rand}.png") + self.map.save(f"{TEXT_PATH}/genshin_map_{rand}.png") return rand # 资源数量