mirror of
https://github.com/PaiGramTeam/MibooGram.git
synced 2024-11-16 04:45:27 +00:00
🐛 修复模板复用不正确导致的错误并改进代码避免触发洪水模式
Co-authored-by: Karako <karakohear@gmail.com> Co-authored-by: 洛水居室 <luoshuijs@outlook.com>
This commit is contained in:
parent
feb717b28b
commit
b477dc7648
2
.gitignore
vendored
2
.gitignore
vendored
@ -33,6 +33,8 @@ test_**.html
|
||||
logs/
|
||||
report/
|
||||
/resources/*/*/test/
|
||||
plugins/genshin/daily/daily.json
|
||||
resources/assets/
|
||||
|
||||
### DotEnv ###
|
||||
.env
|
||||
|
@ -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
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
from core.service import init_service
|
||||
from .service import AssetsService
|
||||
from core.assets.service import AssetsService
|
||||
|
||||
|
||||
@init_service
|
||||
|
@ -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):
|
||||
|
@ -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正在搬运 <b>{_item[0]}</b> 的图标素材。。。"
|
||||
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 = []
|
||||
|
Loading…
Reference in New Issue
Block a user