This commit is contained in:
Azide 2022-03-13 16:19:45 +08:00
commit 0824b799c1
2 changed files with 36 additions and 28 deletions

View File

@ -323,11 +323,12 @@ async def test_platform_name_err(app: App):
True,
)
@pytest.mark.asyncio
@respx.mock
async def test_add_with_get_id(app: App):
from nonebot.adapters.onebot.v11.event import Sender
from nonebot.adapters.onebot.v11.message import Message,MessageSegment
from nonebot.adapters.onebot.v11.message import Message, MessageSegment
from nonebot_bison.config import Config
from nonebot_bison.config_manager import add_sub_matcher, common_platform
from nonebot_bison.platform import platform_manager
@ -359,7 +360,11 @@ async def test_add_with_get_id(app: App):
ctx.should_pass_rule()
ctx.should_call_send(
event_1,
Message(BotReply.add_reply_on_platform(platform_manager=platform_manager,common_platform=common_platform)),
Message(
BotReply.add_reply_on_platform(
platform_manager=platform_manager, common_platform=common_platform
)
),
True,
)
event_3 = fake_group_message_event(
@ -379,15 +384,15 @@ async def test_add_with_get_id(app: App):
ctx.should_call_send(
event_4_query,
[MessageSegment(*BotReply.add_reply_on_id_input_search())],
True
True,
)
'''
"""
line 362:
鬼知道为什么要在这里这样写
没有[]的话assert不了(should_call_send使用[MessageSegment(...)]的格式进行比较)
不在这里MessageSegment()的话也assert不了(指不能让add_reply_on_id_input_search直接返回一个MessageSegment对象)
amen
'''
"""
event_abort = fake_group_message_event(
message=Message("取消"), sender=Sender(card="", nickname="test", role="admin")
)
@ -397,4 +402,4 @@ async def test_add_with_get_id(app: App):
BotReply.add_reply_abort,
True,
)
ctx.should_finished()
ctx.should_finished()

View File

@ -70,7 +70,9 @@ from nonebot.adapters.onebot.v11.event import Sender
fake_admin_user = Sender(nickname="test", role="admin")
fake_superuser = Sender(user_id=10001, nickname="superuser")
from nonebot.adapters.onebot.v11.message import Message,MessageSegment
from nonebot.adapters.onebot.v11.message import Message, MessageSegment
class BotReply:
def add_reply_on_platform(platform_manager, common_platform):
return (
@ -95,29 +97,30 @@ class BotReply:
)
def add_reply_on_id_input_search():
search_url="https://nonebot-bison.vercel.app/usage/#%E6%89%80%E6%94%AF%E6%8C%81%E5%B9%B3%E5%8F%B0%E7%9A%84-uid"
search_title="Bison所支持的平台UID"
search_content="查询相关平台的uid格式或获取方式"
search_image="https://s3.bmp.ovh/imgs/2022/03/ab3cc45d83bd3dd3.jpg"
type='share'
data={
'url':search_url,
'title':search_title,
'content':search_content,
'image':search_image
}
msg=[type,data]
search_url = "https://nonebot-bison.vercel.app/usage/#%E6%89%80%E6%94%AF%E6%8C%81%E5%B9%B3%E5%8F%B0%E7%9A%84-uid"
search_title = "Bison所支持的平台UID"
search_content = "查询相关平台的uid格式或获取方式"
search_image = "https://s3.bmp.ovh/imgs/2022/03/ab3cc45d83bd3dd3.jpg"
type = "share"
data = {
"url": search_url,
"title": search_title,
"content": search_content,
"image": search_image,
}
msg = [type, data]
return msg
def add_reply_on_target_confirm(platform,name,id):
return (f"即将订阅的用户为:{platform} {name} {id}\n如有错误请输入“取消”重新订阅")
def add_reply_on_cats(platform_manager,platform:str):
return ("请输入要订阅的类别,以空格分隔,支持的类别有:{}".format(
" ".join(list(platform_manager[platform].categories.values()))))
def add_reply_on_cats_input_error(cat:str):
return ("不支持 {}".format(cat))
def add_reply_on_target_confirm(platform, name, id):
return f"即将订阅的用户为:{platform} {name} {id}\n如有错误请输入“取消”重新订阅"
def add_reply_on_cats(platform_manager, platform: str):
return "请输入要订阅的类别,以空格分隔,支持的类别有:{}".format(
" ".join(list(platform_manager[platform].categories.values()))
)
def add_reply_on_cats_input_error(cat: str):
return "不支持 {}".format(cat)
def add_reply_subscribe_success(name):
return "添加 {} 成功".format(name)