diff --git a/bot.py b/bot.py index 324f5dc3..a2c28ec5 100644 --- a/bot.py +++ b/bot.py @@ -51,9 +51,7 @@ def run_bot(): cache_path = os.path.abspath(Config('cache_path')) if os.path.exists(cache_path): shutil.rmtree(cache_path) - os.mkdir(cache_path) - else: - os.mkdir(cache_path) + os.mkdir(cache_path) pid_cache = os.path.abspath('.pid_last') if os.path.exists(pid_cache): diff --git a/modules/arcaea/__init__.py b/modules/arcaea/__init__.py index d2edb248..8458d982 100644 --- a/modules/arcaea/__init__.py +++ b/modules/arcaea/__init__.py @@ -39,7 +39,7 @@ async def _(msg: Bot.MessageSession, use_local=True): use_local = False resp = await get_url((web_render_local if use_local else web_render) + 'source?url=' + urllib.parse.quote('https://webapi.lowiro.com/webapi/serve/static/bin/arcaea/apk/'), 200, - fmt='json') + fmt='json', request_private_ip=True) if resp: await msg.finish([Plain(msg.locale.t("arcaea.message.download", version=resp["value"]["version"], url=resp['value']['url']))]) @@ -56,7 +56,7 @@ async def _(msg: Bot.MessageSession, use_local=True): use_local = False resp = await get_url((web_render_local if use_local else web_render) + 'source?url=' + urllib.parse.quote('https://webapi.lowiro.com/webapi/song/showcase/'), - 200, fmt='json') + 200, fmt='json', request_private_ip=True) if resp: value = resp["value"][0] image = f'{assets_path}/jacket/{value["song_id"]}.jpg' @@ -68,7 +68,8 @@ async def _(msg: Bot.MessageSession, use_local=True): await msg.finish(msg.locale.t("arcaea.message.get_failed")) -@arc.command('rank free {{arcaea.help.rank.free}}', 'rank paid {{arcaea.help.rank.paid}}') +@arc.command('rank free {{arcaea.help.rank.free}}', + 'rank paid {{arcaea.help.rank.paid}}') async def _(msg: Bot.MessageSession, use_local=True): if not web_render_local: if not web_render: @@ -78,10 +79,11 @@ async def _(msg: Bot.MessageSession, use_local=True): if msg.parsed_msg.get('free', False): resp = await get_url((web_render_local if use_local else web_render) + 'source?url=' + urllib.parse.quote('https://webapi.lowiro.com/webapi/song/rank/free/'), - 200, fmt='json') + 200, fmt='json', request_private_ip=True) else: resp = await get_url((web_render_local if use_local else web_render) + 'source?url=' + - urllib.parse.quote('https://webapi.lowiro.com/webapi/song/rank/paid/'), 200, fmt='json') + urllib.parse.quote('https://webapi.lowiro.com/webapi/song/rank/paid/'), + 200, fmt='json', request_private_ip=True) if resp: r = [] rank = 0 diff --git a/modules/core/su_utils.py b/modules/core/su_utils.py index 1b238d50..9bb6bc7e 100644 --- a/modules/core/su_utils.py +++ b/modules/core/su_utils.py @@ -169,9 +169,7 @@ async def _(): Logger.info('Start purging cache...') if os.path.exists(cache_path): shutil.rmtree(cache_path) - os.mkdir(cache_path) - else: - os.mkdir(cache_path) + os.mkdir(cache_path) set_ = module('set', required_superuser=True, base=True) diff --git a/modules/maimai/libraries/maimai_best_50.py b/modules/maimai/libraries/maimai_best_50.py index c47f4e03..35466943 100644 --- a/modules/maimai/libraries/maimai_best_50.py +++ b/modules/maimai/libraries/maimai_best_50.py @@ -408,7 +408,7 @@ async def generate(msg, payload) -> Tuple[Optional[Image.Image], bool]: elif str(e).startswith('403'): await msg.finish(msg.locale.t("maimai.message.forbidden")) else: - await msg.finish(ErrorMessage(str(e))) + raise sd_best = BestList(35) dx_best = BestList(15) diff --git a/modules/maimai/libraries/maimaidx_api_data.py b/modules/maimai/libraries/maimaidx_api_data.py index 01452173..6843b77c 100644 --- a/modules/maimai/libraries/maimaidx_api_data.py +++ b/modules/maimai/libraries/maimaidx_api_data.py @@ -15,51 +15,45 @@ cover_dir = f"{assets_path}/static/mai/cover" async def update_alias(): - try: - url = "https://download.fanyu.site/maimai/alias.json" - input_data = await get_url(url, 200, fmt='json') + url = "https://download.fanyu.site/maimai/alias.json" + input_data = await get_url(url, 200, fmt='json') - output_data = {} - for key, values in input_data.items(): - for value in values: - if value == "未找到": - continue - if value not in output_data: - output_data[value] = [] - output_data[value].append(key) + output_data = {} + for key, values in input_data.items(): + for value in values: + if value == "未找到": + continue + if value not in output_data: + output_data[value] = [] + output_data[value].append(key) - output_data = {k: output_data[k] for k in sorted(output_data)} - - file_path = os.path.join(assets_path, "mai_alias.json") - with open(file_path, 'w') as file: - json.dump(output_data, file) - - return True - except: - return False + output_data = {k: output_data[k] for k in sorted(output_data)} + file_path = os.path.join(assets_path, "mai_alias.json") + with open(file_path, 'w') as file: + json.dump(output_data, file) + + return True async def update_covers(): - try: - url = f"https://www.diving-fish.com/maibot/static.zip" - download_file = await download_to_cache(url, timeout=60) + 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) - - 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) + Logger.info('Maimai covers download completed.') + ca = random_cache_path() + shutil.unpack_archive(download_file, ca) - os.remove(download_file) - return True - except: - return False + 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) + + os.remove(download_file) + + return True async def get_alias(msg, input_): @@ -117,7 +111,7 @@ async def get_record(msg, payload): elif str(e).startswith('403'): await msg.finish(msg.locale.t("maimai.message.forbidden")) else: - await msg.finish(ErrorMessage(str(e))) + raise return data @@ -137,5 +131,5 @@ async def get_plate(msg, payload): elif str(e).startswith('403'): await msg.finish(msg.locale.t("maimai.message.forbidden")) else: - await msg.finish(ErrorMessage(str(e))) + raise return data diff --git a/schedulers/maimai_alias.py b/schedulers/maimai_alias.py index 04c7997a..df7c46ca 100644 --- a/schedulers/maimai_alias.py +++ b/schedulers/maimai_alias.py @@ -1,11 +1,15 @@ +from config import Config from core.builtins import Bot from core.logger import Logger -from core.scheduler import CronTrigger -from core.scheduler import Scheduler +from core.scheduler import CronTrigger, Scheduler from modules.maimai.libraries.maimaidx_api_data import update_alias @Scheduler.scheduled_job(CronTrigger.from_crontab('0 0 * * *')) async def maimai_alias(): Logger.info('Updating maimai alias...') - await update_alias() \ No newline at end of file + try: + await update_alias() + except Exception: + if Config('debug'): + Logger.error(traceback.format_exc()) \ No newline at end of file diff --git a/schedulers/weekly_rss.py b/schedulers/weekly_rss.py index 971d9b5f..bf526622 100644 --- a/schedulers/weekly_rss.py +++ b/schedulers/weekly_rss.py @@ -1,8 +1,7 @@ from core.builtins import Bot from core.logger import Logger from core.queue import JobQueue -from core.scheduler import CronTrigger -from core.scheduler import Scheduler +from core.scheduler import CronTrigger, Scheduler from modules.weekly import get_weekly from modules.weekly.teahouse import get_rss as get_teahouse_rss