From fa3e8c1300f0ddf759c7aab0e472293267e6ce7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=91=E8=BD=BB=E7=8B=82?= <1677568218@qq.com> Date: Mon, 28 Aug 2023 00:38:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81adapter=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/actions_scripts/file.py | 12 ++++++++++++ .github/actions_scripts/plugin_test.py | 23 ++++++++++++++--------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/.github/actions_scripts/file.py b/.github/actions_scripts/file.py index d310292..edd4447 100644 --- a/.github/actions_scripts/file.py +++ b/.github/actions_scripts/file.py @@ -3,6 +3,7 @@ import json import os +import time from pathlib import Path from typing import Any @@ -35,6 +36,7 @@ def add_info(json_data: list[dict[str, str]], infos: dict[str, Any]) -> bool: i["license"] = infos["license"] i["homepage"] = infos["homepage"] i["tags"] = infos["tags"] + i["time"] = infos["time"] return True json_data.append(infos) return False @@ -48,6 +50,15 @@ def save_json(json_data: dict[str, Any]) -> None: def main() -> None: """添加信息:1. 获取对应json文件并解析 2. 查询是否有同名插件,若存在则覆盖,并更新时间 3. 否则添加至最后一行,并附上更新时间 4. 保存至文件.""" + # 获取当前UTC时间的时间戳 + current_time_utc = time.time() + # 转换为东八区时间 + current_time_east8 = current_time_utc + 8 * 3600 + # 使用localtime得到结构化时间 + struct_time = time.localtime(current_time_east8) + # 格式化时间 + formatted_time = time.strftime("%Y-%m-%d %H:%M:%S", struct_time) + json_data = get_json() data_list = json_data.get(type_info + "s", []) info = { @@ -60,6 +71,7 @@ def main() -> None: "homepage": homepage, "tags": tags, "is_official": False, + "time":formatted_time } if add_info(data_list, info): set_action_outputs( diff --git a/.github/actions_scripts/plugin_test.py b/.github/actions_scripts/plugin_test.py index 64a4654..51e543c 100644 --- a/.github/actions_scripts/plugin_test.py +++ b/.github/actions_scripts/plugin_test.py @@ -3,13 +3,14 @@ from alicebot.bot import Bot -PLUGIN_MODULE_NAME = sys.argv[1] +MODULE_NAME = sys.argv[1] TYPE = sys.argv[2] - -if PLUGIN_MODULE_NAME == "null": +if MODULE_NAME == "null": + sys.stdout.write("Invalid MODULE_NAME value. Must be a valid Python module name.") sys.exit(1) -if TYPE != "plugin": +if TYPE not in {"plugin", "adapter", "bot"}: + sys.stdout.write("Invalid TYPE value. Must be one of 'plugin', 'adapter', or 'bot'.") sys.exit(1) bot = Bot(config_file=None) @@ -21,17 +22,21 @@ def error_or_exception(self: Bot, message: str, exception: Exception) -> None: sys.stdout.write(message) sys.exit(1) - Bot.error_or_exception = error_or_exception -bot.load_plugins(PLUGIN_MODULE_NAME) - - +if TYPE == "plugin": + bot.load_plugins(MODULE_NAME) +if TYPE == "adapter": + bot.load_adapters(MODULE_NAME) +if TYPE == "bot": + sys.exit(0) @bot.bot_run_hook async def bot_run_hook(bot: Bot) -> None: """在 Bot 启动后直接退出。.""" - bot.should_exit.set() + if TYPE == "plugin": + bot.should_exit.set() + sys.exit(0) if __name__ == "__main__":