Skip to content

Commit

Permalink
feat: 支持adapter测试
Browse files Browse the repository at this point in the history
  • Loading branch information
MarleneJiang committed Aug 27, 2023
1 parent b046fc8 commit fa3e8c1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
12 changes: 12 additions & 0 deletions .github/actions_scripts/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import json
import os
import time
from pathlib import Path
from typing import Any

Expand Down Expand Up @@ -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
Expand All @@ -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 = {
Expand All @@ -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(
Expand Down
23 changes: 14 additions & 9 deletions .github/actions_scripts/plugin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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__":
Expand Down

0 comments on commit fa3e8c1

Please sign in to comment.