summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--ATRI/plugins/help/data_source.py21
-rw-r--r--ATRI/utils/apscheduler.py6
-rw-r--r--requirements.txt5
-rw-r--r--test/test_plugin_help.py19
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,