From b3e35d83e2b0d5621f24a72df78662d102e105c4 Mon Sep 17 00:00:00 2001 From: yzhh <31803608+OasisAkari@users.noreply.github.com> Date: Wed, 26 Apr 2023 21:59:00 +0800 Subject: [PATCH] remove some function that uses official api from arcaea module 616sb --- modules/arcaea/__init__.py | 120 ++++-------------- modules/arcaea/recyclebin/__init__.py | 0 .../{ => recyclebin}/getb30_official.py | 6 +- .../arcaea/{ => recyclebin}/info_official.py | 0 4 files changed, 31 insertions(+), 95 deletions(-) create mode 100644 modules/arcaea/recyclebin/__init__.py rename modules/arcaea/{ => recyclebin}/getb30_official.py (97%) rename modules/arcaea/{ => recyclebin}/info_official.py (100%) diff --git a/modules/arcaea/__init__.py b/modules/arcaea/__init__.py index edd95be2..5023aa91 100644 --- a/modules/arcaea/__init__.py +++ b/modules/arcaea/__init__.py @@ -8,9 +8,7 @@ from core.component import module from core.utils.http import get_url from .dbutils import ArcBindInfoManager from .getb30 import getb30 -from .getb30_official import getb30_official from .info import get_info -from .info_official import get_info_official from .initialize import arcb30init from .song import get_song_info from .utils import get_userinfo @@ -25,21 +23,11 @@ class WithErrCode(Exception): pass -@arc.command('b30 [] {{arcaea.b30.help}}', - 'b30 official [] {{arcaea.message.official}}', - 'b30 unofficial [] {{arcaea.message.unofficial}}') +@arc.command('b30 [] {{arcaea.b30.help}}') async def _(msg: Bot.MessageSession): if not os.path.exists(assets_path): await msg.finish(msg.locale.t("arcaea.message.assets.not_found", prefix=msg.prefixes[0])) query_code = None - prefer_uses = msg.options.get('arc_api', None) - official = msg.parsed_msg.get('official', False) - unofficial = msg.parsed_msg.get('unofficial', False) - if not unofficial and not official and prefer_uses is False: - unofficial = True - if not official and prefer_uses is True: - official = True - friendcode: str = msg.parsed_msg.get('', False) if friendcode: if friendcode.isdigit(): @@ -54,68 +42,39 @@ async def _(msg: Bot.MessageSession): if get_friendcode_from_db is not None: query_code = get_friendcode_from_db if query_code is not None: - if not unofficial: - try: - resp = await getb30_official(query_code) - if resp["status"]: - msgchain = [Plain(msg.locale.t("arcaea.b30.message.success", b30=resp["b30"], r10=resp["r10"], - last5list=resp["last5list"]))] - if 'file' in resp and msg.Feature.image: - msgchain.append(Image(path=resp['file'])) - await msg.sendMessage(msgchain, allow_split_image=False) + try: + resp = await getb30(query_code) + if resp['status']: + msgchain = [Plain(msg.locale.t("arcaea.b30.message.success", b30=resp["b30"], r10=resp["r10"], + last5list=resp["last5list"]))] + if 'file' in resp and msg.Feature.image: + msgchain.append(Image(path=resp['file'])) + await msg.finish(msgchain) + else: + if 'errcode' in resp: + raise WithErrCode(resp['errcode']) else: raise - except Exception: - traceback.print_exc() - if not official and prefer_uses is None: - await msg.sendMessage(msg.locale.t("arcaea.message.official.fetch.failed.fallback")) - unofficial = True - else: - await msg.finish(msg.locale.t("arcaea.message.official.fetch.failed")) - if unofficial: - try: - resp = await getb30(query_code) - if resp['status']: - msgchain = [Plain(msg.locale.t("arcaea.b30.message.success", b30=resp["b30"], r10=resp["r10"], - last5list=resp["last5list"]))] - if 'file' in resp and msg.Feature.image: - msgchain.append(Image(path=resp['file'])) - await msg.finish(msgchain) - else: - if 'errcode' in resp: - raise WithErrCode(resp['errcode']) - else: - raise - except WithErrCode as e: - err_key = "arcaea.errcode." + str(e.args[0]) - err_msg = msg.locale.t(err_key) - if err_key != err_msg: - await msg.finish(msg.locale.t("arcaea.message.failed.fetch") + err_msg) - else: - await msg.finish(msg.locale.t("arcaea.message.unofficial.fetch.failed")) - except Exception: - traceback.print_exc() + except WithErrCode as e: + err_key = "arcaea.errcode." + str(e.args[0]) + err_msg = msg.locale.t(err_key) + if err_key != err_msg: + await msg.finish(msg.locale.t("arcaea.message.failed.fetch") + err_msg) + else: await msg.finish(msg.locale.t("arcaea.message.unofficial.fetch.failed")) + except Exception: + traceback.print_exc() + await msg.finish(msg.locale.t("arcaea.message.unofficial.fetch.failed")) else: await msg.finish(msg.locale.t("arcaea.message.user.unbound", prefix=msg.prefixes[0])) -@arc.command('info [] {{arcaea.info.help}}', - 'info official [] {{arcaea.message.official}}', - 'info unofficial [] {{arcaea.message.unofficial}}', ) +@arc.command('info [] {{arcaea.info.help}}') async def _(msg: Bot.MessageSession): if not os.path.exists(assets_path): await msg.sendMessage(msg.locale.t("arcaea.message.assets.not_found", prefix=msg.prefixes[0])) return query_code = None - prefer_uses = msg.options.get('arc_api', None) - unofficial = msg.parsed_msg.get('unofficial', False) - official = msg.parsed_msg.get('official', False) - if not unofficial and not official and prefer_uses is False: - unofficial = True - - if not official and prefer_uses is True: - official = True friendcode = msg.parsed_msg.get('', False) if friendcode: if friendcode.isdigit(): @@ -130,27 +89,12 @@ async def _(msg: Bot.MessageSession): if get_friendcode_from_db is not None: query_code = get_friendcode_from_db if query_code is not None: - if not unofficial: - try: - resp = await get_info_official(msg, query_code) - if resp['success']: - await msg.finish(resp['msg']) - else: - if not official and prefer_uses is None: - await msg.sendMessage(msg.locale.t("arcaea.message.official.fetch.failed.fallback")) - unofficial = True - except Exception: - traceback.print_exc() - if not official and prefer_uses is None: - await msg.sendMessage(msg.locale.t("arcaea.message.official.fetch.failed.fallback")) - unofficial = True - if unofficial: - try: - resp = await get_info(msg, query_code) - await msg.finish(resp) - except Exception: - traceback.print_exc() - await msg.finish(msg.locale.t("arcaea.message.unofficial.fetch.failed")) + try: + resp = await get_info(msg, query_code) + await msg.finish(resp) + except Exception: + traceback.print_exc() + await msg.finish(msg.locale.t("arcaea.message.unofficial.fetch.failed")) else: await msg.finish(msg.locale.t("arcaea.message.user.unbound", prefix=msg.prefixes[0])) @@ -258,11 +202,3 @@ async def _(msg: Bot.MessageSession): rank += 1 r.append(f'{rank}. {x["title"]["en"]} ({x["status"]})') await msg.finish('\n'.join(r)) - - -@arc.command('switch {{arcaea.switch.help}}') -async def _(msg: Bot.MessageSession): - value = msg.options.get('arc_api', True) - set_value = msg.data.edit_option('arc_api', not value) - await msg.finish(msg.locale.t("arcaea.switch.message.success.official" - if not value else "arcaea.switch.message.success.unofficial")) diff --git a/modules/arcaea/recyclebin/__init__.py b/modules/arcaea/recyclebin/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/modules/arcaea/getb30_official.py b/modules/arcaea/recyclebin/getb30_official.py similarity index 97% rename from modules/arcaea/getb30_official.py rename to modules/arcaea/recyclebin/getb30_official.py index 0473192e..d038bcae 100644 --- a/modules/arcaea/getb30_official.py +++ b/modules/arcaea/recyclebin/getb30_official.py @@ -9,9 +9,9 @@ import uuid from config import Config from core.logger import Logger from core.utils.http import get_url -from .drawb30img import drawb30 -from .drawsongimg import dsimg -from .utils import autofix_b30_song_background +from modules.arcaea.drawb30img import drawb30 +from modules.arcaea.drawsongimg import dsimg +from modules.arcaea.utils import autofix_b30_song_background assets_path = os.path.abspath('./assets/arcaea') diff --git a/modules/arcaea/info_official.py b/modules/arcaea/recyclebin/info_official.py similarity index 100% rename from modules/arcaea/info_official.py rename to modules/arcaea/recyclebin/info_official.py