diff --git a/core/utils/http.py b/core/utils/http.py index e8d9cc76..b971effb 100644 --- a/core/utils/http.py +++ b/core/utils/http.py @@ -51,7 +51,7 @@ async def get_url(url: str, status_code: int = False, headers: dict = None, para :param attempt: 指定请求尝试次数。 :param request_private_ip: 是否允许请求私有IP。 :param logging_err_resp: 是否记录错误响应。 - :param cookies: 使用的 cookies + :param cookies: 使用的 cookies。 :returns: 指定url的内容(字符串)。 """ diff --git a/modules/maimai/libraries/chunithm_apidata.py b/modules/maimai/libraries/chunithm_apidata.py index 1ded9d5c..d08e91f6 100644 --- a/modules/maimai/libraries/chunithm_apidata.py +++ b/modules/maimai/libraries/chunithm_apidata.py @@ -2,6 +2,7 @@ import traceback import ujson as json from core.builtins import Bot, Plain +from core.logger import Logger from core.utils.http import post_url from .chunithm_music import Music @@ -33,6 +34,6 @@ async def get_record(msg, payload): else: await msg.finish(msg.locale.t("chunithm.message.forbidden")) else: - traceback.print_exc() - - return data \ No newline at end of file + Logger.error(traceback.format_exc()) + if data: + return data \ No newline at end of file diff --git a/modules/maimai/libraries/maimaidx_apidata.py b/modules/maimai/libraries/maimaidx_apidata.py index 37468992..96ec8b10 100644 --- a/modules/maimai/libraries/maimaidx_apidata.py +++ b/modules/maimai/libraries/maimaidx_apidata.py @@ -14,34 +14,40 @@ total_list = TotalList() async def update_alias(): - url = "https://download.fanyu.site/maimai/alias.json" - data = await get_url(url, 200, fmt='json') + try: + url = "https://download.fanyu.site/maimai/alias.json" + data = await get_url(url, 200, fmt='json') - file_path = os.path.join(assets_path, "mai_alias.json") - with open(file_path, 'w') as file: - json.dump(data, file) - + file_path = os.path.join(assets_path, "mai_alias.json") + with open(file_path, 'w') as file: + json.dump(data, file) + except: + Logger.error(traceback.format_exc()) + return False return True async def update_covers(): - cover_dir = f"{assets_path}/static/mai/cover" - url = f"https://www.diving-fish.com/maibot/static.zip" - download_file = await download_to_cache(url, timeout=60) + try: + cover_dir = f"{assets_path}/static/mai/cover" + url = f"https://www.diving-fish.com/maibot/static.zip" + download_file = await download_to_cache(url, timeout=60) - Logger.info('Maimai covers download completed.') - ca = random_cache_path() - shutil.unpack_archive(download_file, ca) + Logger.info('Maimai covers download completed.') + ca = random_cache_path() + shutil.unpack_archive(download_file, ca) - if os.path.exists(cover_dir): - shutil.rmtree(cover_dir) + if os.path.exists(cover_dir): + shutil.rmtree(cover_dir) - static_cover_dir = os.path.join(ca, 'mai/cover') - if os.path.exists(static_cover_dir): - shutil.move(static_cover_dir, cover_dir) + static_cover_dir = os.path.join(ca, 'mai/cover') + if os.path.exists(static_cover_dir): + shutil.move(static_cover_dir, cover_dir) + except: + Logger.error(traceback.format_exc()) + return False os.remove(download_file) - return True @@ -117,9 +123,9 @@ async def get_record(msg, payload): else: await msg.finish(msg.locale.t("maimai.message.forbidden")) else: - traceback.print_exc() - - return data + Logger.error(traceback.format_exc()) + if data: + return data async def get_plate(msg, payload): @@ -140,5 +146,5 @@ async def get_plate(msg, payload): await msg.finish(msg.locale.t("maimai.message.forbidden.eula")) else: await msg.finish(msg.locale.t("maimai.message.forbidden")) - - return data + if data: + return data diff --git a/modules/maimai/maimai.py b/modules/maimai/maimai.py index 2bc04469..d9159350 100644 --- a/modules/maimai/maimai.py +++ b/modules/maimai/maimai.py @@ -1,9 +1,7 @@ import traceback -from config import Config from core.builtins import Bot, Plain, Image as BImage from core.component import module -from core.scheduler import CronTrigger from core.utils.image import msgchain2image from .dbutils import DivingProberBindInfoManager from .libraries.maimaidx_apidata import get_alias, get_info, search_by_alias, update_alias, update_covers @@ -338,14 +336,4 @@ async def _(msg: Bot.MessageSession): if await update_alias() and await update_covers(): await msg.finish(msg.locale.t("success")) else: - await msg.finish(msg.locale.t("failed")) - - -@mai.schedule(CronTrigger.from_crontab('0 0 * * *')) -async def _(): - Logger.info('Updating maimai alias...') - try: - await update_alias() - except Exception: - if Config('debug'): - Logger.error(traceback.format_exc()) + await msg.finish(msg.locale.t("failed")) \ No newline at end of file diff --git a/modules/wiki/locales/zh_cn.json b/modules/wiki/locales/zh_cn.json index 50da2d03..828deb27 100644 --- a/modules/wiki/locales/zh_cn.json +++ b/modules/wiki/locales/zh_cn.json @@ -30,7 +30,7 @@ "wiki.help.wiki_inline.template": "在 {{ }} 内输入标题以自动查询模板。", "wiki.help.wiki_inline.url": "发送 Wiki 页面的 URL 以生成 Infobox 图片。", "wiki.message.section": "章节", - "wiki.message.section.rendering": "(章节渲染中)", + "wiki.message.section.rendering": "(章节渲染中……)", "wiki.message.ab.qq.title": "滥用过滤器日志", "wiki.message.ab.qq.title.address": "滥用过滤器日志地址", "wiki.message.ab.slice": "•${title} - ${user} 于 ${time}\n 过滤器描述:${filter_name}\n 采取的行动:${result}", @@ -39,8 +39,8 @@ "wiki.message.error.info": "详细信息:", "wiki.message.error.query": "发生错误:无法查询此 Wiki。", "wiki.message.error.set": "发生错误:无法设置此 Wiki。", - "wiki.message.error.fetch_log": "无法获取日志,可能是本wiki设置了日志的查看权限。", - "wiki.message.error.unable_to_render_section": "(章节渲染失败,请联系开发者检查原因)", + "wiki.message.error.fetch_log": "发生错误:无法获取日志,可能是此 Wiki 设置了日志的查看权限。", + "wiki.message.error.unable_to_render_section": "(章节渲染失败,请联系开发者检查原因。)", "wiki.message.fandom.disable": "已关闭 Fandom 全局 Interwiki 查询。", "wiki.message.fandom.enable": "已开启 Fandom 全局 Interwiki 查询。", "wiki.message.flies": "此页面包括以下文件:\n", diff --git a/schedulers/maimai_alias.py b/schedulers/maimai_alias.py new file mode 100644 index 00000000..5fba4025 --- /dev/null +++ b/schedulers/maimai_alias.py @@ -0,0 +1,14 @@ +from config import Config +from core.logger import Logger +from core.scheduler import Scheduler, CronTrigger +from modules.maimai.libraries.maimaidx_apidata import update_alias + + +@Scheduler.scheduled_job(CronTrigger.from_crontab('0 0 * * *')) +async def update_maimai_alias(): + Logger.info('Updating Maimai alias...') + try: + await update_alias() + except Exception: + if Config('debug'): + Logger.error(traceback.format_exc()) diff --git a/schedulers/purge.py b/schedulers/purge.py index 30be86d3..863c752c 100644 --- a/schedulers/purge.py +++ b/schedulers/purge.py @@ -7,9 +7,9 @@ from core.scheduler import Scheduler, CronTrigger @Scheduler.scheduled_job(CronTrigger.from_crontab('0 0 * * *')) -async def _(): - cache_path = os.path.abspath(Config('cache_path')) +async def auto_purge(): Logger.info('Start purging cache...') + cache_path = os.path.abspath(Config('cache_path')) if os.path.exists(cache_path): shutil.rmtree(cache_path) os.mkdir(cache_path) diff --git a/schedulers/wiki_bot.py b/schedulers/wiki_bot.py index afaf887f..9f7b7635 100644 --- a/schedulers/wiki_bot.py +++ b/schedulers/wiki_bot.py @@ -1,6 +1,5 @@ from datetime import datetime, timedelta -from core.builtins import Bot from core.logger import Logger from core.queue import JobQueue from core.scheduler import DateTrigger, Scheduler @@ -12,4 +11,4 @@ async def login_bots(): Logger.info('Start login wiki bot account...') await BotAccount.login() await JobQueue.trigger_hook_all('login_wiki_bots', cookies=BotAccount.cookies) - Logger.info('Login wiki bot account done') + Logger.info('Login wiki bot account successfully.')