diff --git a/.gitignore b/.gitignore index d92485e5..0212f8db 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,8 @@ test_**.html logs/ report/ /resources/*/*/test/ +plugins/genshin/daily/daily.json +resources/assets/ ### DotEnv ### .env diff --git a/core/admin/services.py b/core/admin/services.py index 4b8acca2..3e2ff9c7 100644 --- a/core/admin/services.py +++ b/core/admin/services.py @@ -19,7 +19,7 @@ class BotAdminService: if len(admin_list) == 0: admin_list = await self._repository.get_all_user_id() for config_admin in config.admins: - admin_list.append(config_admin["user_id"]) + admin_list.append(config_admin.user_id) await self._cache.set_list(admin_list) return admin_list @@ -30,7 +30,7 @@ class BotAdminService: logger.warning(f"{user_id} 已经存在数据库 \n", error) admin_list = await self._repository.get_all_user_id() for config_admin in config.admins: - admin_list.append(config_admin["user_id"]) + admin_list.append(config_admin.user_id) await self._cache.set_list(admin_list) return True @@ -41,7 +41,7 @@ class BotAdminService: return False admin_list = await self._repository.get_all_user_id() for config_admin in config.admins: - admin_list.append(config_admin["user_id"]) + admin_list.append(config_admin.user_id) await self._cache.set_list(admin_list) return True diff --git a/core/assets/__init__.py b/core/assets/__init__.py index 2ff27ec9..41e91f11 100644 --- a/core/assets/__init__.py +++ b/core/assets/__init__.py @@ -1,5 +1,5 @@ from core.service import init_service -from .service import AssetsService +from core.assets.service import AssetsService @init_service diff --git a/core/template/services.py b/core/template/services.py index 5db01c6f..99899799 100644 --- a/core/template/services.py +++ b/core/template/services.py @@ -1,6 +1,6 @@ import os import time -from typing import Optional +from typing import Optional, Dict from jinja2 import Environment, PackageLoader, Template from playwright.async_api import ViewportSize @@ -18,8 +18,8 @@ class TemplateService: self._output_dir = os.path.join(self._current_dir, cache_dir_name) if not os.path.exists(self._output_dir): os.mkdir(self._output_dir) - self._jinja2_env = {} - self._jinja2_template = {} + self._jinja2_env: Dict[str, Environment] = {} + self._jinja2_template: Dict[str, Template] = {} def get_template(self, package_path: str, template_name: str) -> Template: if bot.config.debug: @@ -28,14 +28,17 @@ class TemplateService: jinja2_env = Environment(loader=loader, enable_async=True, autoescape=True) jinja2_template = jinja2_env.get_template(template_name) else: - jinja2_env: Environment = self._jinja2_env.get(package_path) - jinja2_template: Template = self._jinja2_template.get(package_path + template_name) + jinja2_env = self._jinja2_env.get(package_path) + jinja2_template = self._jinja2_template.get(package_path + template_name) if jinja2_env is None: loader = PackageLoader(self._template_package_name, package_path) jinja2_env = Environment(loader=loader, enable_async=True, autoescape=True) jinja2_template = jinja2_env.get_template(template_name) self._jinja2_env[package_path] = jinja2_env self._jinja2_template[package_path + template_name] = jinja2_template + elif jinja2_template is None: + jinja2_template = jinja2_env.get_template(template_name) + self._jinja2_template[package_path + template_name] = jinja2_template return jinja2_template async def render_async(self, template_path: str, template_name: str, template_data: dict): diff --git a/plugins/genshin/daily/material.py b/plugins/genshin/daily/material.py index d7c38424..1f405272 100644 --- a/plugins/genshin/daily/material.py +++ b/plugins/genshin/daily/material.py @@ -45,7 +45,7 @@ WEEK_MAP = ['一', '二', '三', '四', '五', '六', '日'] def convert_path(path: Union[str, Path]) -> str: - return f"..{os.sep}..{os.sep}" + str(path.relative_to(RESOURCE_DIR)) + return f"..{os.sep}..{os.sep}{str(path.relative_to(RESOURCE_DIR))}" def sort_item(items: List['ItemData']) -> Iterable['ItemData']: @@ -65,9 +65,9 @@ class DailyMaterial(Plugin, BasePlugin): data: DATA_TYPE locks: Tuple[Lock] = (Lock(), Lock()) - def __init__(self, assets: AssetsService, template: TemplateService): + def __init__(self, assets: AssetsService, template_service: TemplateService): self.assets_service = assets - self.template_service = template + self.template_service = template_service self.client = AsyncClient() async def __async_init__(self): @@ -296,8 +296,8 @@ class DailyMaterial(Plugin, BasePlugin): async def _download_icon(self, message: Optional[Message] = None): from time import time as time_ lock = asyncio.Lock() - the_time = Value(c_double, time_() - 1) - interval = 0.2 + interval = 2 + the_time = Value(c_double, time_() - interval) async def task(_id, _item, _type): logger.debug(f"正在开始下载 \"{_item[0]}\" 的图标素材") @@ -306,9 +306,9 @@ class DailyMaterial(Plugin, BasePlugin): text = '\n'.join(message.text_html.split('\n')[:2]) + f"\n正在搬运 {_item[0]} 的图标素材。。。" try: await message.edit_text(text, parse_mode=ParseMode.HTML) + the_time.value = time_() except (TimedOut, RetryAfter): pass - the_time.value = time_() asset = getattr(self.assets_service, _type)(_id) icon_types = list(filter( lambda x: not x.startswith('_') and x not in ['path'] and callable(getattr(asset, x)), @@ -326,9 +326,9 @@ class DailyMaterial(Plugin, BasePlugin): ) try: await message.edit_text(text, parse_mode=ParseMode.HTML) + the_time.value = time_() except (TimedOut, RetryAfter): pass - the_time.value = time_() for type_, items in HONEY_ID_MAP.items(): task_list = []