From a9b698b4a08bff4a0747adca71a9b55808be4bff Mon Sep 17 00:00:00 2001 From: Yuki-Asuuna <10174503104@stu.ecnu.edu.cn> Date: Fri, 18 Feb 2022 14:34:43 +0800 Subject: =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E6=9C=8D=E5=8A=A1=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E8=BE=93=E5=87=BA=20&=20=E5=8E=BB=E9=99=A4scheduler?= =?UTF-8?q?=20Warning=20&=20=E8=A1=A5=E5=85=85requirements.txt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I978daa50a7a60e9e551bd6a22d543ab24b6898da --- .gitignore | 3 +++ ATRI/plugins/help/data_source.py | 21 ++++++++++++--------- ATRI/utils/apscheduler.py | 6 +++--- requirements.txt | 5 ++++- test/test_plugin_help.py | 19 ++++++++++++------- 5 files changed, 34 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index e2a2045..cad6e71 100644 --- a/.gitignore +++ b/.gitignore @@ -139,5 +139,8 @@ dmypy.json # End of https://www.toptal.com/developers/gitignore/api/python +# for JetBrain Pycharm +.idea + /accounts/* /data/* diff --git a/ATRI/plugins/help/data_source.py b/ATRI/plugins/help/data_source.py index de07678..da9432a 100644 --- a/ATRI/plugins/help/data_source.py +++ b/ATRI/plugins/help/data_source.py @@ -1,4 +1,7 @@ import os +import json + +from tabulate import tabulate from ATRI import __version__ from ATRI.rule import to_bot @@ -6,7 +9,6 @@ from ATRI.service import Service, SERVICES_DIR, ServiceTools from ATRI.config import BotSelfConfig from ATRI.exceptions import ReadFileError - SERVICE_INFO_FORMAT = """ 服务名:{service} 说明:{docs} @@ -15,7 +17,6 @@ SERVICE_INFO_FORMAT = """ Tip: @bot 帮助 [服务] [命令] 以查看对应命令详细信息 """.strip() - COMMAND_INFO_FORMAT = """ 命令:{cmd} 类型:{cmd_type} @@ -56,13 +57,15 @@ class Helper(Service): @staticmethod def service_list() -> str: files = os.listdir(SERVICES_DIR) - temp_list = list() - for i in files: - service = i.replace(".json", "") - temp_list.append(service) - - services = "、".join(map(str, temp_list)) - repo = f"咱搭载了以下服务~\n{services}\n@bot 帮助 [服务] -以查看对应服务帮助" + services = list() + for f in files: + prefix = f.replace(".json", "") + f = os.path.join(SERVICES_DIR, f) + with open(f, "r", encoding="utf-8") as r: + service = json.load(r) + services.append([prefix, "√" if service["enabled"] else "×", "√" if service["only_admin"] else "×"]) + table = tabulate(services, headers=["服务名称", "开启状态", "仅支持管理员"], tablefmt="plain", showindex=True) + repo = f"咱搭载了以下服务~\n{table}\n@bot 帮助 [服务] -以查看对应服务帮助" return repo @staticmethod diff --git a/ATRI/utils/apscheduler.py b/ATRI/utils/apscheduler.py index daf37f4..186ff8e 100644 --- a/ATRI/utils/apscheduler.py +++ b/ATRI/utils/apscheduler.py @@ -9,16 +9,16 @@ from nonebot.log import logger, LoguruHandler apscheduler_autostart: bool = True -apscheduler_config: dict = {"apscheduler.timezone": "Asia/Shanghai"} +# apscheduler_config: dict = {"apscheduler.timezone": "Asia/Shanghai"} driver = get_driver() -scheduler = AsyncIOScheduler() +scheduler = AsyncIOScheduler(timezone="Asia/Shanghai") async def _start_scheduler(): if not scheduler.running: - scheduler.configure(apscheduler_config) + # scheduler.configure(apscheduler_config) scheduler.start() logger.info("Scheduler Started.") diff --git a/requirements.txt b/requirements.txt index 09932a0..1655d22 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,4 +11,7 @@ pytz>=2020.1 pyyaml>=5.4 scikit-image>=0.18.3 tensorflow>=2.6.0 -jieba>=0.42.1 \ No newline at end of file +jieba>=0.42.1 +tabulate>=0.8.9 +wcwidth>=0.2.5 +aiohttp>=3.8.1 \ No newline at end of file diff --git a/test/test_plugin_help.py b/test/test_plugin_help.py index ef30e1d..7bc0cf3 100644 --- a/test/test_plugin_help.py +++ b/test/test_plugin_help.py @@ -66,17 +66,22 @@ async def test_about_me(app: App): @pytest.mark.asyncio async def test_service_list(app: App): import os + import json + from tabulate import tabulate from ATRI.service import SERVICES_DIR from ATRI.plugins.help import service_list files = os.listdir(SERVICES_DIR) - temp_list = list() - for i in files: - service = i.replace(".json", "") - temp_list.append(service) - - services = "、".join(map(str, temp_list)) + services = list() + for f in files: + prefix = f.replace(".json", "") + f = os.path.join(SERVICES_DIR, f) + with open(f, "r", encoding="utf-8") as r: + service = json.load(r) + services.append([prefix, "√" if service["enabled"] else "×", "√" if service["only_admin"] else "×"]) + table = tabulate(services, headers=["服务名称", "开启状态", "仅支持管理员"], tablefmt="plain", showindex=True) + output = f"咱搭载了以下服务~\n{table}\n@bot 帮助 [服务] -以查看对应服务帮助" Message = make_fake_message() @@ -91,7 +96,7 @@ async def test_service_list(app: App): event, f""" 咱搭载了以下服务~ - {services} + {output} @bot 帮助 [服务] -以查看对应服务帮助 """, True, -- cgit v1.2.3