From da1218221ce2d9f506464f6b6a64e05df85b3782 Mon Sep 17 00:00:00 2001 From: Mix Date: Mon, 1 Feb 2021 16:37:42 +0800 Subject: [PATCH] :white_check_mark: add specified test for mirai adapter --- tests/.env.dev | 4 ++++ tests/bot.py | 2 ++ tests/test_plugins/test_mirai.py | 13 +++++++++++++ 3 files changed, 19 insertions(+) create mode 100644 tests/test_plugins/test_mirai.py diff --git a/tests/.env.dev b/tests/.env.dev index 9b69f65a..33e6f835 100644 --- a/tests/.env.dev +++ b/tests/.env.dev @@ -11,3 +11,7 @@ COMMAND_SEP=["/", "."] CUSTOM_CONFIG1=config in env CUSTOM_CONFIG3= + +MIRAI_AUTH_KEY=12345678 +MIRAI_HOST=127.0.0.1 +MIRAI_PORT=8080 \ No newline at end of file diff --git a/tests/bot.py b/tests/bot.py index 6e45e051..849aee27 100644 --- a/tests/bot.py +++ b/tests/bot.py @@ -6,6 +6,7 @@ sys.path.insert(0, os.path.abspath("..")) import nonebot from nonebot.adapters.cqhttp import Bot from nonebot.adapters.ding import Bot as DingBot +from nonebot.adapters.mirai import Bot as MiraiBot from nonebot.log import logger, default_format # test custom log @@ -20,6 +21,7 @@ app = nonebot.get_asgi() driver = nonebot.get_driver() driver.register_adapter("cqhttp", Bot) driver.register_adapter("ding", DingBot) +driver.register_adapter("mirai", MiraiBot) # load builtin plugin nonebot.load_builtin_plugins() diff --git a/tests/test_plugins/test_mirai.py b/tests/test_plugins/test_mirai.py new file mode 100644 index 00000000..a5da93ae --- /dev/null +++ b/tests/test_plugins/test_mirai.py @@ -0,0 +1,13 @@ +from nonebot.plugin import on_message +from nonebot.adapters.mirai import Bot, MessageEvent + +message_test = on_message() + + +@message_test.handle() +async def _message(bot: Bot, event: MessageEvent): + text = event.get_plaintext() + if not text: + return + reversed_text = ''.join(reversed(text)) + await bot.send(event, reversed_text, at_sender=True)