mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-04 02:26:11 +08:00
🚧 use saa-send
This commit is contained in:
parent
5010ca1ac5
commit
2ba9542b63
16
poetry.lock
generated
16
poetry.lock
generated
@ -1467,13 +1467,13 @@ typing-extensions = ">=4.0.0"
|
||||
|
||||
[[package]]
|
||||
name = "nonebot-plugin-send-anything-anywhere"
|
||||
version = "0.2.5"
|
||||
version = "0.2.6"
|
||||
description = "An adaptor for nonebot2 adaptors"
|
||||
optional = false
|
||||
python-versions = ">=3.8,<4.0"
|
||||
files = [
|
||||
{file = "nonebot_plugin_send_anything_anywhere-0.2.5-py3-none-any.whl", hash = "sha256:58db714745f71693292533433e8881b00954e8ee6438ab3cd173048b5c5ce77f"},
|
||||
{file = "nonebot_plugin_send_anything_anywhere-0.2.5.tar.gz", hash = "sha256:2385e95ee22407faf59703074ad95070bedbdcf492c261ed380f26eccd202039"},
|
||||
{file = "nonebot_plugin_send_anything_anywhere-0.2.6-py3-none-any.whl", hash = "sha256:42c7145e1c1735f159e1c16c5bd96ae2409897beb627a64039f6a90e9f09bcae"},
|
||||
{file = "nonebot_plugin_send_anything_anywhere-0.2.6.tar.gz", hash = "sha256:1774f4ef8f7800239f0b0b3cf73ce5f801fcfeac8da9f38fabf77d6829e4322e"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
@ -1536,17 +1536,17 @@ resolved_reference = "bc82dbe078a1d42c515a3a783269011fb7e7bc9d"
|
||||
|
||||
[[package]]
|
||||
name = "nonebug-saa"
|
||||
version = "0.1.0"
|
||||
version = "0.2.1"
|
||||
description = "A nonebug helper for nonebot-plugin-send-anything-anything"
|
||||
optional = false
|
||||
python-versions = ">=3.10,<4.0"
|
||||
files = [
|
||||
{file = "nonebug_saa-0.1.0-py3-none-any.whl", hash = "sha256:f2e79867f81d53ca08752382e6800ebc8c6242fbee94fa346ef48e887121b9d6"},
|
||||
{file = "nonebug_saa-0.1.0.tar.gz", hash = "sha256:bfe805d3a9d67e9e2585638b0f37185f69934d2bf433276c007850a9cb9ba52c"},
|
||||
{file = "nonebug_saa-0.2.1-py3-none-any.whl", hash = "sha256:cf41786a029f7a6085c352fd6298523b078f6310bf0f48451508bc8f8d86a6a1"},
|
||||
{file = "nonebug_saa-0.2.1.tar.gz", hash = "sha256:fee91fe86030ceaf55535a2f48e74670e3763d0397f37ce9473c0c2d72148fe3"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
nonebot-plugin-send-anything-anywhere = ">=0.2.2,<0.3.0"
|
||||
nonebot-plugin-send-anything-anywhere = ">=0.2.4,<0.3.0"
|
||||
nonebug = ">=0.3.1,<0.4.0"
|
||||
pytest-mock = ">=3.10.0,<4.0.0"
|
||||
|
||||
@ -2886,4 +2886,4 @@ yaml = []
|
||||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = ">=3.10,<4.0.0"
|
||||
content-hash = "109ee12685b1c143006df6969f7b1b3b0d3613a8a47fca3a7a8b005b64605902"
|
||||
content-hash = "c6474ad7ba525cdfa874d5fdfaec0a8ce7f8224f68a0deb4d0e4ae470a795977"
|
||||
|
@ -34,7 +34,7 @@ nonebot-adapter-onebot = "^2.0.0-beta.1"
|
||||
nonebot-plugin-htmlrender = ">=0.2.0"
|
||||
nonebot-plugin-datastore = "^0.6.2"
|
||||
nonebot-plugin-apscheduler = "^0.2.0"
|
||||
nonebot-plugin-send-anything-anywhere = "^0.2.5"
|
||||
nonebot-plugin-send-anything-anywhere = "^0.2.6"
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
ipdb = "^0.13.4"
|
||||
@ -51,7 +51,7 @@ pytest-mock = "^3.10.0"
|
||||
nonebug = { git = "https://github.com/nonebot/nonebug.git", rev = "master" }
|
||||
pytest-xdist = { extras = ["psutil"], version = "^3.1.0" }
|
||||
nb-cli = "^1.0.5"
|
||||
nonebug-saa = "^0.1.0"
|
||||
nonebug-saa = "^0.2.1"
|
||||
|
||||
[tool.poetry.extras]
|
||||
cli = ["anyio", "click", "typing-extensions"]
|
||||
|
@ -30,7 +30,6 @@ def load_adapters(nonebug_init: None):
|
||||
async def app(tmp_path: Path, request: pytest.FixtureRequest, mocker: MockerFixture):
|
||||
sys.path.append(str(Path(__file__).parent.parent / "src" / "plugins"))
|
||||
|
||||
nonebot.require("nonebot_plugin_saa")
|
||||
nonebot.require("nonebot_bison")
|
||||
from nonebot_plugin_datastore.config import plugin_config as datastore_config
|
||||
from nonebot_plugin_datastore.db import create_session, init_db
|
||||
@ -55,10 +54,10 @@ async def app(tmp_path: Path, request: pytest.FixtureRequest, mocker: MockerFixt
|
||||
|
||||
if not param.get("no_init_db"):
|
||||
await init_db()
|
||||
if not param.get("refresh_bot"):
|
||||
import nonebot_bison.utils.get_bot
|
||||
|
||||
mocker.patch.object(nonebot_bison.utils.get_bot, "refresh_bots")
|
||||
# if not param.get("refresh_bot"):
|
||||
# import nonebot_bison.utils.get_bot
|
||||
#
|
||||
# mocker.patch.object(nonebot_bison.utils.get_bot, "refresh_bots")
|
||||
|
||||
yield App()
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
import pytest
|
||||
import respx
|
||||
from httpx import Response
|
||||
from nonebot_plugin_saa.nonebug import should_send_saa
|
||||
from nonebug.app import App
|
||||
from nonebug_saa import should_send_saa
|
||||
|
||||
from .platforms.utils import get_json
|
||||
from .utils import BotReply, fake_admin_user, fake_group_message_event
|
||||
|
@ -544,6 +544,7 @@ async def test_add_with_bilibili_target_parser(app: App, init_scheduler):
|
||||
async def test_add_with_bilibili_live_target_parser(app: App, init_scheduler):
|
||||
from nonebot.adapters.onebot.v11.event import Sender
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.config import config
|
||||
from nonebot_bison.config_manager import add_sub_matcher, common_platform
|
||||
@ -621,7 +622,7 @@ async def test_add_with_bilibili_live_target_parser(app: App, init_scheduler):
|
||||
event_5_ok, BotReply.add_reply_subscribe_success("明日方舟"), True
|
||||
)
|
||||
ctx.should_finished()
|
||||
subs = await config.list_subscribe(10000, "group")
|
||||
subs = await config.list_subscribe(TargetQQGroup(group_id=10000))
|
||||
assert len(subs) == 1
|
||||
sub = subs[0]
|
||||
assert sub.target.target == "161775300"
|
||||
@ -638,6 +639,7 @@ async def test_add_with_bilibili_live_target_parser(app: App, init_scheduler):
|
||||
async def test_add_with_bilibili_bangumi_target_parser(app: App, init_scheduler):
|
||||
from nonebot.adapters.onebot.v11.event import Sender
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
from nonebot_plugin_saa import TargetQQGroup
|
||||
|
||||
from nonebot_bison.config import config
|
||||
from nonebot_bison.config_manager import add_sub_matcher, common_platform
|
||||
@ -708,7 +710,7 @@ async def test_add_with_bilibili_bangumi_target_parser(app: App, init_scheduler)
|
||||
event_4_ok, BotReply.add_reply_subscribe_success("汉化日记 第三季"), True
|
||||
)
|
||||
ctx.should_finished()
|
||||
subs = await config.list_subscribe(10000, "group")
|
||||
subs = await config.list_subscribe(TargetQQGroup(group_id=10000))
|
||||
assert len(subs) == 1
|
||||
sub = subs[0]
|
||||
assert sub.target.target == "28235413"
|
||||
|
@ -1,8 +1,8 @@
|
||||
import pytest
|
||||
import respx
|
||||
from httpx import Response
|
||||
from nonebot_plugin_saa.nonebug import should_send_saa
|
||||
from nonebug.app import App
|
||||
from nonebug_saa import should_send_saa
|
||||
|
||||
from .platforms.utils import get_json
|
||||
from .utils import fake_admin_user, fake_group_message_event
|
||||
@ -28,8 +28,7 @@ async def test_query_sub(app: App, init_scheduler):
|
||||
["明日方舟"],
|
||||
)
|
||||
async with app.test_matcher(query_sub_matcher) as ctx:
|
||||
adapter = get_driver()._adapters[str(SupportedAdapters.onebot_v11)]
|
||||
bot = ctx.create_bot(base=Bot, adapter=adapter)
|
||||
bot = ctx.create_bot(base=Bot)
|
||||
|
||||
event = fake_group_message_event(message=Message("查询订阅"), to_me=True)
|
||||
ctx.receive_event(bot, event)
|
||||
|
@ -3,8 +3,8 @@ import typing
|
||||
|
||||
import pytest
|
||||
from flaky import flaky
|
||||
from nonebot_plugin_saa.nonebug import should_send_saa
|
||||
from nonebug import App
|
||||
from nonebug_saa import should_send_saa
|
||||
from pytest_mock.plugin import MockerFixture
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@ from pytest_mock.plugin import MockerFixture
|
||||
async def test_send_no_queue(app: App, mocker: MockerFixture):
|
||||
from nonebot.adapters.onebot.v11.bot import Bot
|
||||
from nonebot_plugin_saa import MessageFactory, TargetQQGroup, TargetQQPrivate
|
||||
from nonebot_plugin_saa.utils.auto_select_bot import refresh_bots
|
||||
|
||||
from nonebot_bison.plugin_config import plugin_config
|
||||
from nonebot_bison.send import send_msgs
|
||||
@ -27,10 +28,8 @@ async def test_send_no_queue(app: App, mocker: MockerFixture):
|
||||
should_send_saa(ctx, MessageFactory("msg1"), bot, target=group_target)
|
||||
should_send_saa(ctx, MessageFactory("msg2"), bot, target=group_target)
|
||||
should_send_saa(ctx, MessageFactory("priv"), bot, target=private_target)
|
||||
await send_msgs(
|
||||
bot, group_target, [MessageFactory("msg1"), MessageFactory("msg2")]
|
||||
)
|
||||
await send_msgs(bot, private_target, [MessageFactory("priv")])
|
||||
await send_msgs(group_target, [MessageFactory("msg1"), MessageFactory("msg2")])
|
||||
await send_msgs(private_target, [MessageFactory("priv")])
|
||||
assert ctx.wait_list.empty()
|
||||
|
||||
|
||||
@ -39,6 +38,7 @@ async def test_send_queue(app: App, mocker: MockerFixture):
|
||||
import nonebot
|
||||
from nonebot.adapters.onebot.v11.bot import Bot
|
||||
from nonebot_plugin_saa import MessageFactory, TargetQQGroup
|
||||
from nonebot_plugin_saa.utils.auto_select_bot import refresh_bots
|
||||
|
||||
from nonebot_bison.plugin_config import plugin_config
|
||||
from nonebot_bison.send import MESSGE_SEND_INTERVAL, send_msgs
|
||||
@ -46,6 +46,7 @@ async def test_send_queue(app: App, mocker: MockerFixture):
|
||||
mocker.patch.object(plugin_config, "bison_use_queue", True)
|
||||
async with app.test_api() as ctx:
|
||||
new_bot = ctx.create_bot(base=Bot)
|
||||
await refresh_bots()
|
||||
mocker.patch.object(nonebot, "get_bot", lambda: new_bot)
|
||||
bot = nonebot.get_bot()
|
||||
assert isinstance(bot, Bot)
|
||||
@ -55,8 +56,8 @@ async def test_send_queue(app: App, mocker: MockerFixture):
|
||||
should_send_saa(ctx, MessageFactory("msg"), bot, target=target)
|
||||
should_send_saa(ctx, MessageFactory("msg2"), bot, target=target)
|
||||
|
||||
await send_msgs(bot, target, [MessageFactory("msg")])
|
||||
await send_msgs(bot, target, [MessageFactory("msg2")])
|
||||
await send_msgs(target, [MessageFactory("msg")])
|
||||
await send_msgs(target, [MessageFactory("msg2")])
|
||||
assert not ctx.wait_list.empty()
|
||||
await asyncio.sleep(2 * MESSGE_SEND_INTERVAL)
|
||||
assert ctx.wait_list.empty()
|
||||
@ -72,6 +73,7 @@ async def test_send_merge_no_queue(app: App):
|
||||
TargetQQGroup,
|
||||
Text,
|
||||
)
|
||||
from nonebot_plugin_saa.utils.auto_select_bot import refresh_bots
|
||||
|
||||
from nonebot_bison.plugin_config import plugin_config
|
||||
from nonebot_bison.send import send_msgs
|
||||
@ -81,6 +83,7 @@ async def test_send_merge_no_queue(app: App):
|
||||
|
||||
async with app.test_api() as ctx:
|
||||
bot = ctx.create_bot(base=Bot, self_id="8888")
|
||||
await refresh_bots()
|
||||
assert isinstance(bot, Bot)
|
||||
target = TargetQQGroup(group_id=633)
|
||||
|
||||
@ -90,7 +93,7 @@ async def test_send_merge_no_queue(app: App):
|
||||
]
|
||||
should_send_saa(ctx, message[0], bot, target=target)
|
||||
should_send_saa(ctx, message[1], bot, target=target)
|
||||
await send_msgs(bot, target, message)
|
||||
await send_msgs(target, message)
|
||||
|
||||
message = [
|
||||
MessageFactory(Text("test msg")),
|
||||
@ -99,8 +102,7 @@ async def test_send_merge_no_queue(app: App):
|
||||
]
|
||||
should_send_saa(ctx, message[0], bot, target=target)
|
||||
should_send_saa(ctx, AggregatedMessageFactory(message[1:]), bot, target=target)
|
||||
# import ipdb; ipdb.set_trace()
|
||||
await send_msgs(bot, target, message)
|
||||
await send_msgs(target, message)
|
||||
|
||||
message = [
|
||||
MessageFactory(Text("test msg")),
|
||||
@ -110,7 +112,7 @@ async def test_send_merge_no_queue(app: App):
|
||||
]
|
||||
should_send_saa(ctx, message[0], bot, target=target)
|
||||
should_send_saa(ctx, AggregatedMessageFactory(message[1:]), bot, target=target)
|
||||
await send_msgs(bot, target, message)
|
||||
await send_msgs(target, message)
|
||||
|
||||
|
||||
async def test_send_merge2_no_queue(app: App):
|
||||
@ -122,6 +124,7 @@ async def test_send_merge2_no_queue(app: App):
|
||||
TargetQQGroup,
|
||||
Text,
|
||||
)
|
||||
from nonebot_plugin_saa.utils.auto_select_bot import refresh_bots
|
||||
|
||||
from nonebot_bison.plugin_config import plugin_config
|
||||
from nonebot_bison.send import send_msgs
|
||||
@ -132,6 +135,7 @@ async def test_send_merge2_no_queue(app: App):
|
||||
async with app.test_api() as ctx:
|
||||
bot = ctx.create_bot(base=Bot, self_id="8888")
|
||||
assert isinstance(bot, Bot)
|
||||
await refresh_bots()
|
||||
target = TargetQQGroup(group_id=633)
|
||||
|
||||
message = [
|
||||
@ -140,4 +144,4 @@ async def test_send_merge2_no_queue(app: App):
|
||||
MessageFactory(Image("https://picsum.photos/200/300")),
|
||||
]
|
||||
should_send_saa(ctx, AggregatedMessageFactory(message), bot, target=target)
|
||||
await send_msgs(bot, target, message)
|
||||
await send_msgs(target, message)
|
||||
|
Loading…
x
Reference in New Issue
Block a user