mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-05 11:26:43 +08:00
auto fix by pre-commit hooks
This commit is contained in:
parent
48bca04470
commit
c9bea2a780
@ -110,9 +110,7 @@ def do_add_sub(add_sub: Type[Matcher]):
|
||||
)
|
||||
async def init_id(state: T_State):
|
||||
if platform_manager[state["platform"]].has_target:
|
||||
state[
|
||||
"_prompt"
|
||||
] = "请输入订阅用户的id:\n查询id获取方法请回复:“查询”"
|
||||
state["_prompt"] = "请输入订阅用户的id:\n查询id获取方法请回复:“查询”"
|
||||
else:
|
||||
state["id"] = "default"
|
||||
state["name"] = await platform_manager[state["platform"]].get_target_name(
|
||||
@ -134,18 +132,22 @@ def do_add_sub(add_sub: Type[Matcher]):
|
||||
state["id"] = target
|
||||
state["name"] = name
|
||||
except (LookupError):
|
||||
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"
|
||||
title="Bison所支持的平台UID"
|
||||
content="查询相关平台的uid格式或获取方式"
|
||||
image="https://s3.bmp.ovh/imgs/2022/03/ab3cc45d83bd3dd3.jpg"
|
||||
getId_share=f"[CQ:share,url={url},title={title},content={content},image={image}]"#缩短字符串格式长度,以及方便后续修改为消息段格式
|
||||
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"
|
||||
title = "Bison所支持的平台UID"
|
||||
content = "查询相关平台的uid格式或获取方式"
|
||||
image = "https://s3.bmp.ovh/imgs/2022/03/ab3cc45d83bd3dd3.jpg"
|
||||
getId_share = f"[CQ:share,url={url},title={title},content={content},image={image}]" # 缩短字符串格式长度,以及方便后续修改为消息段格式
|
||||
await add_sub.reject(Message(getId_share))
|
||||
except (KeyboardInterrupt):
|
||||
await add_sub.finish("已中止订阅")
|
||||
except (ValueError):
|
||||
await add_sub.reject("id输入错误")
|
||||
else:
|
||||
await add_sub.send("即将订阅的用户为:{} {} {}\n如有错误请输入“取消”重新订阅".format(state["platform"],state["name"],state["id"]))
|
||||
await add_sub.send(
|
||||
"即将订阅的用户为:{} {} {}\n如有错误请输入“取消”重新订阅".format(
|
||||
state["platform"], state["name"], state["id"]
|
||||
)
|
||||
)
|
||||
|
||||
@add_sub.got("id", _gen_prompt_template("{_prompt}"), [Depends(parse_id)])
|
||||
async def init_cat(state: T_State):
|
||||
|
@ -4,7 +4,7 @@ from httpx import Response
|
||||
from nonebug.app import App
|
||||
|
||||
from .platforms.utils import get_json
|
||||
from .utils import fake_admin_user, fake_group_message_event,BotReply
|
||||
from .utils import BotReply, fake_admin_user, fake_group_message_event
|
||||
|
||||
|
||||
# 选择platform阶段中止
|
||||
@ -43,9 +43,7 @@ async def test_abort_add_on_platform(app: App):
|
||||
ctx.should_pass_rule()
|
||||
ctx.should_call_send(
|
||||
event_1,
|
||||
Message(
|
||||
BotReply.add_reply_on_platform(platform_manager,common_platform)
|
||||
),
|
||||
Message(BotReply.add_reply_on_platform(platform_manager, common_platform)),
|
||||
True,
|
||||
)
|
||||
event_abort = fake_group_message_event(
|
||||
@ -96,9 +94,7 @@ async def test_abort_add_on_id(app: App):
|
||||
ctx.should_pass_rule()
|
||||
ctx.should_call_send(
|
||||
event_1,
|
||||
Message(
|
||||
BotReply.add_reply_on_platform(platform_manager,common_platform)
|
||||
),
|
||||
Message(BotReply.add_reply_on_platform(platform_manager, common_platform)),
|
||||
True,
|
||||
)
|
||||
event_2 = fake_group_message_event(
|
||||
@ -107,9 +103,7 @@ async def test_abort_add_on_id(app: App):
|
||||
ctx.receive_event(bot, event_2)
|
||||
ctx.should_call_send(
|
||||
event_2,
|
||||
Message(
|
||||
BotReply.add_reply_on_id
|
||||
),
|
||||
Message(BotReply.add_reply_on_id),
|
||||
True,
|
||||
)
|
||||
event_abort = fake_group_message_event(
|
||||
@ -161,7 +155,9 @@ async def test_abort_add_on_cats(app: App):
|
||||
ctx.should_call_send(
|
||||
event_1,
|
||||
Message(
|
||||
BotReply.add_reply_on_platform(platform_manager=platform_manager,common_platform=common_platform)
|
||||
BotReply.add_reply_on_platform(
|
||||
platform_manager=platform_manager, common_platform=common_platform
|
||||
)
|
||||
),
|
||||
True,
|
||||
)
|
||||
@ -171,9 +167,7 @@ async def test_abort_add_on_cats(app: App):
|
||||
ctx.receive_event(bot, event_2)
|
||||
ctx.should_call_send(
|
||||
event_2,
|
||||
Message(
|
||||
BotReply.add_reply_on_id
|
||||
),
|
||||
Message(BotReply.add_reply_on_id),
|
||||
True,
|
||||
)
|
||||
event_3 = fake_group_message_event(
|
||||
@ -182,12 +176,14 @@ async def test_abort_add_on_cats(app: App):
|
||||
ctx.receive_event(bot, event_3)
|
||||
ctx.should_call_send(
|
||||
event_3,
|
||||
BotReply.add_reply_on_target_confirm("weibo","明日方舟Arknights","6279793937"),
|
||||
True
|
||||
BotReply.add_reply_on_target_confirm(
|
||||
"weibo", "明日方舟Arknights", "6279793937"
|
||||
),
|
||||
True,
|
||||
)
|
||||
ctx.should_call_send(
|
||||
event_3,
|
||||
Message(BotReply.add_reply_on_cats(platform_manager,"weibo")),
|
||||
Message(BotReply.add_reply_on_cats(platform_manager, "weibo")),
|
||||
True,
|
||||
)
|
||||
event_abort = fake_group_message_event(
|
||||
@ -239,7 +235,9 @@ async def test_abort_add_on_tag(app: App):
|
||||
ctx.should_call_send(
|
||||
event_1,
|
||||
Message(
|
||||
BotReply.add_reply_on_platform(platform_manager=platform_manager,common_platform=common_platform)
|
||||
BotReply.add_reply_on_platform(
|
||||
platform_manager=platform_manager, common_platform=common_platform
|
||||
)
|
||||
),
|
||||
True,
|
||||
)
|
||||
@ -249,9 +247,7 @@ async def test_abort_add_on_tag(app: App):
|
||||
ctx.receive_event(bot, event_2)
|
||||
ctx.should_call_send(
|
||||
event_2,
|
||||
Message(
|
||||
BotReply.add_reply_on_id
|
||||
),
|
||||
Message(BotReply.add_reply_on_id),
|
||||
True,
|
||||
)
|
||||
event_3 = fake_group_message_event(
|
||||
@ -260,12 +256,14 @@ async def test_abort_add_on_tag(app: App):
|
||||
ctx.receive_event(bot, event_3)
|
||||
ctx.should_call_send(
|
||||
event_3,
|
||||
BotReply.add_reply_on_target_confirm("weibo","明日方舟Arknights","6279793937"),
|
||||
True
|
||||
BotReply.add_reply_on_target_confirm(
|
||||
"weibo", "明日方舟Arknights", "6279793937"
|
||||
),
|
||||
True,
|
||||
)
|
||||
ctx.should_call_send(
|
||||
event_3,
|
||||
Message(BotReply.add_reply_on_cats(platform_manager,"weibo")),
|
||||
Message(BotReply.add_reply_on_cats(platform_manager, "weibo")),
|
||||
True,
|
||||
)
|
||||
event_4 = fake_group_message_event(
|
||||
|
@ -4,7 +4,7 @@ from httpx import Response
|
||||
from nonebug.app import App
|
||||
|
||||
from .platforms.utils import get_json
|
||||
from .utils import fake_admin_user, fake_group_message_event, BotReply
|
||||
from .utils import BotReply, fake_admin_user, fake_group_message_event
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@ -31,6 +31,7 @@ async def test_configurable_at_me_true_failed(app: App):
|
||||
ctx.should_pass_rule()
|
||||
ctx.should_not_pass_permission()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_configurable_at_me_false(app: App):
|
||||
from nonebot.adapters.onebot.v11.bot import Bot
|
||||
@ -48,12 +49,13 @@ async def test_configurable_at_me_false(app: App):
|
||||
ctx.receive_event(bot, event)
|
||||
ctx.should_call_send(
|
||||
event,
|
||||
Message(BotReply.add_reply_on_platform(platform_manager,common_platform)),
|
||||
Message(BotReply.add_reply_on_platform(platform_manager, common_platform)),
|
||||
True,
|
||||
)
|
||||
ctx.should_pass_rule()
|
||||
ctx.should_pass_permission()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_add_with_target(app: App):
|
||||
@ -90,7 +92,11 @@ async def test_add_with_target(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_2 = fake_group_message_event(
|
||||
@ -124,19 +130,23 @@ async def test_add_with_target(app: App):
|
||||
ctx.receive_event(bot, event_4_ok)
|
||||
ctx.should_call_send(
|
||||
event_4_ok,
|
||||
BotReply.add_reply_on_target_confirm("weibo","明日方舟Arknights","6279793937"),
|
||||
True
|
||||
BotReply.add_reply_on_target_confirm(
|
||||
"weibo", "明日方舟Arknights", "6279793937"
|
||||
),
|
||||
True,
|
||||
)
|
||||
ctx.should_call_send(
|
||||
event_4_ok,
|
||||
Message(BotReply.add_reply_on_cats(platform_manager,"weibo")),
|
||||
Message(BotReply.add_reply_on_cats(platform_manager, "weibo")),
|
||||
True,
|
||||
)
|
||||
event_5_err = fake_group_message_event(
|
||||
message=Message("图文 文字 err"), sender=fake_admin_user
|
||||
)
|
||||
ctx.receive_event(bot, event_5_err)
|
||||
ctx.should_call_send(event_5_err, BotReply.add_reply_on_cats_input_error("err"), True)
|
||||
ctx.should_call_send(
|
||||
event_5_err, BotReply.add_reply_on_cats_input_error("err"), True
|
||||
)
|
||||
ctx.should_rejected()
|
||||
event_5_ok = fake_group_message_event(
|
||||
message=Message("图文 文字"), sender=fake_admin_user
|
||||
@ -147,7 +157,9 @@ async def test_add_with_target(app: App):
|
||||
message=Message("全部标签"), sender=fake_admin_user
|
||||
)
|
||||
ctx.receive_event(bot, event_6)
|
||||
ctx.should_call_send(event_6, BotReply.add_reply_subscribe_success("明日方舟Arknights"), True)
|
||||
ctx.should_call_send(
|
||||
event_6, BotReply.add_reply_subscribe_success("明日方舟Arknights"), True
|
||||
)
|
||||
ctx.should_finished()
|
||||
subs = config.list_subscribe(10000, "group")
|
||||
assert len(subs) == 1
|
||||
@ -160,6 +172,7 @@ async def test_add_with_target(app: App):
|
||||
assert sub["target_type"] == "weibo"
|
||||
assert sub["target_name"] == "明日方舟Arknights"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_add_with_target_no_cat(app: App):
|
||||
@ -186,7 +199,7 @@ async def test_add_with_target_no_cat(app: App):
|
||||
ctx.should_pass_rule()
|
||||
ctx.should_call_send(
|
||||
event_1,
|
||||
Message(BotReply.add_reply_on_platform(platform_manager,common_platform)),
|
||||
Message(BotReply.add_reply_on_platform(platform_manager, common_platform)),
|
||||
True,
|
||||
)
|
||||
event_3 = fake_group_message_event(
|
||||
@ -204,10 +217,12 @@ async def test_add_with_target_no_cat(app: App):
|
||||
ctx.receive_event(bot, event_4_ok)
|
||||
ctx.should_call_send(
|
||||
event_4_ok,
|
||||
BotReply.add_reply_on_target_confirm("ncm-artist","塞壬唱片-MSR","32540734"),
|
||||
True
|
||||
BotReply.add_reply_on_target_confirm("ncm-artist", "塞壬唱片-MSR", "32540734"),
|
||||
True,
|
||||
)
|
||||
ctx.should_call_send(
|
||||
event_4_ok, BotReply.add_reply_subscribe_success("塞壬唱片-MSR"), True
|
||||
)
|
||||
ctx.should_call_send(event_4_ok, BotReply.add_reply_subscribe_success("塞壬唱片-MSR"), True)
|
||||
ctx.should_finished()
|
||||
subs = config.list_subscribe(10000, "group")
|
||||
assert len(subs) == 1
|
||||
@ -218,6 +233,7 @@ async def test_add_with_target_no_cat(app: App):
|
||||
assert sub["target_type"] == "ncm-artist"
|
||||
assert sub["target_name"] == "塞壬唱片-MSR"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_add_no_target(app: App):
|
||||
@ -241,7 +257,7 @@ async def test_add_no_target(app: App):
|
||||
ctx.should_pass_rule()
|
||||
ctx.should_call_send(
|
||||
event_1,
|
||||
Message(BotReply.add_reply_on_platform(platform_manager,common_platform)),
|
||||
Message(BotReply.add_reply_on_platform(platform_manager, common_platform)),
|
||||
True,
|
||||
)
|
||||
event_3 = fake_group_message_event(
|
||||
@ -250,14 +266,16 @@ async def test_add_no_target(app: App):
|
||||
ctx.receive_event(bot, event_3)
|
||||
ctx.should_call_send(
|
||||
event_3,
|
||||
Message(BotReply.add_reply_on_cats(platform_manager,"arknights")),
|
||||
Message(BotReply.add_reply_on_cats(platform_manager, "arknights")),
|
||||
True,
|
||||
)
|
||||
event_4 = fake_group_message_event(
|
||||
message=Message("游戏公告"), sender=fake_admin_user
|
||||
)
|
||||
ctx.receive_event(bot, event_4)
|
||||
ctx.should_call_send(event_4, BotReply.add_reply_subscribe_success("明日方舟游戏信息"), True)
|
||||
ctx.should_call_send(
|
||||
event_4, BotReply.add_reply_subscribe_success("明日方舟游戏信息"), True
|
||||
)
|
||||
ctx.should_finished()
|
||||
subs = config.list_subscribe(10000, "group")
|
||||
assert len(subs) == 1
|
||||
@ -268,6 +286,7 @@ async def test_add_no_target(app: App):
|
||||
assert sub["target_type"] == "arknights"
|
||||
assert sub["target_name"] == "明日方舟游戏信息"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_platform_name_err(app: App):
|
||||
from nonebot.adapters.onebot.v11.event import Sender
|
||||
@ -289,7 +308,7 @@ async def test_platform_name_err(app: App):
|
||||
ctx.should_pass_rule()
|
||||
ctx.should_call_send(
|
||||
event_1,
|
||||
Message(BotReply.add_reply_on_platform(platform_manager,common_platform)),
|
||||
Message(BotReply.add_reply_on_platform(platform_manager, common_platform)),
|
||||
True,
|
||||
)
|
||||
event_2 = fake_group_message_event(
|
||||
|
@ -71,50 +71,54 @@ fake_admin_user = Sender(nickname="test", role="admin")
|
||||
fake_superuser = Sender(user_id=10001, nickname="superuser")
|
||||
|
||||
from nonebot.adapters.onebot.v11.message import Message
|
||||
|
||||
|
||||
class BotReply:
|
||||
def add_reply_on_platform(platform_manager,common_platform):
|
||||
def add_reply_on_platform(platform_manager, common_platform):
|
||||
return (
|
||||
"请输入想要订阅的平台,目前支持,请输入冒号左边的名称:\n"
|
||||
+ "".join(
|
||||
[
|
||||
"{}:{}\n".format(
|
||||
platform_name, platform_manager[platform_name].name
|
||||
)
|
||||
for platform_name in common_platform
|
||||
]
|
||||
)
|
||||
+ "要查看全部平台请输入:“全部”\n中止订阅过程请输入:“取消”"
|
||||
"请输入想要订阅的平台,目前支持,请输入冒号左边的名称:\n"
|
||||
+ "".join(
|
||||
[
|
||||
"{}:{}\n".format(
|
||||
platform_name, platform_manager[platform_name].name
|
||||
)
|
||||
for platform_name in common_platform
|
||||
]
|
||||
)
|
||||
+ "要查看全部平台请输入:“全部”\n中止订阅过程请输入:“取消”"
|
||||
)
|
||||
|
||||
def add_reply_on_platform_input_allplatform(platform_manager):
|
||||
return "全部平台\n" + "\n".join(
|
||||
[
|
||||
"{}:{}".format(platform_name, platform.name)
|
||||
for platform_name, platform in platform_manager.items()
|
||||
])
|
||||
[
|
||||
"{}:{}".format(platform_name, platform.name)
|
||||
for platform_name, platform in platform_manager.items()
|
||||
]
|
||||
)
|
||||
|
||||
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%84uid"
|
||||
search_title="Bison所支持的平台UID"
|
||||
search_content="查询相关平台的uid格式或获取方式"
|
||||
search_image="https://s3.bmp.ovh/imgs/2022/03/ab3cc45d83bd3dd3.jpg"
|
||||
return (f"[CQ:share,url={search_url},title={search_title},content={search_content},image={search_image}")
|
||||
|
||||
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()))))
|
||||
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%84uid"
|
||||
search_title = "Bison所支持的平台UID"
|
||||
search_content = "查询相关平台的uid格式或获取方式"
|
||||
search_image = "https://s3.bmp.ovh/imgs/2022/03/ab3cc45d83bd3dd3.jpg"
|
||||
return f"[CQ:share,url={search_url},title={search_title},content={search_content},image={search_image}"
|
||||
|
||||
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))
|
||||
return "添加 {} 成功".format(name)
|
||||
|
||||
add_reply_on_id_input_error="id输入错误"
|
||||
add_reply_on_platform_input_error="平台输入错误"
|
||||
add_reply_on_id="请输入订阅用户的id:\n查询id获取方法请回复:“查询”"
|
||||
add_reply_on_tags='请输入要订阅的tag,订阅所有tag输入"全部标签"'
|
||||
add_reply_abort="已中止订阅"
|
||||
add_reply_on_id_input_error = "id输入错误"
|
||||
add_reply_on_platform_input_error = "平台输入错误"
|
||||
add_reply_on_id = "请输入订阅用户的id:\n查询id获取方法请回复:“查询”"
|
||||
add_reply_on_tags = '请输入要订阅的tag,订阅所有tag输入"全部标签"'
|
||||
add_reply_abort = "已中止订阅"
|
||||
|
Loading…
x
Reference in New Issue
Block a user