♻️ use plaintext promot

This commit is contained in:
felinae98 2023-06-07 11:41:16 +08:00
parent 6743929ca2
commit 9b679cb827
5 changed files with 56 additions and 74 deletions

View File

@ -2,10 +2,9 @@ import asyncio
from datetime import datetime
from nonebot import on_command
from nonebot.adapters import Bot
from nonebot.adapters import Bot, Event, MessageTemplate
from nonebot.adapters.onebot.v11 import MessageEvent
from nonebot.adapters.onebot.v11.event import GroupMessageEvent, PrivateMessageEvent
from nonebot.adapters.onebot.v11.message import Message
from nonebot.adapters.onebot.v11.event import PrivateMessageEvent
from nonebot.adapters.onebot.v11.permission import GROUP_ADMIN, GROUP_OWNER
from nonebot.matcher import Matcher
from nonebot.params import ArgPlainText, ArgStr
@ -57,11 +56,6 @@ group_manage_matcher = on_command(
group_handle_cancel = gen_handle_cancel(group_manage_matcher, "已取消")
@group_manage_matcher.handle()
async def send_group_list_private(event: GroupMessageEvent, state: T_State):
await group_manage_matcher.finish(Message("该功能只支持私聊使用请私聊Bot"))
@group_manage_matcher.handle()
async def send_group_list(bot: Bot, event: PrivateMessageEvent, state: T_State):
groups = await bot.call_api("get_group_list")
@ -77,9 +71,11 @@ async def send_group_list(bot: Bot, event: PrivateMessageEvent, state: T_State):
@group_manage_matcher.got(
"group_idx", Message.template("{_prompt}"), [group_handle_cancel]
"group_idx", MessageTemplate("{_prompt}"), [group_handle_cancel]
)
async def do_choose_group_number(state: T_State, group_idx: str = ArgPlainText()):
async def do_choose_group_number(
state: T_State, event: PrivateMessageEvent, group_idx: str = ArgPlainText()
):
group_number_idx: dict[int, int] = state["group_number_idx"]
assert group_number_idx
idx = int(group_idx)
@ -97,7 +93,7 @@ async def do_choose_group_number(state: T_State, group_idx: str = ArgPlainText()
)
async def do_dispatch_command(
bot: Bot,
event: MessageEvent,
event: PrivateMessageEvent,
state: T_State,
matcher: Matcher,
command: str = ArgStr(),

View File

@ -1,6 +1,6 @@
from typing import Type, cast
from nonebot.adapters import Message
from nonebot.adapters import Message, MessageTemplate
from nonebot.adapters.onebot.v11 import Message as OB11Message
from nonebot.adapters.onebot.v11.utils import unescape
from nonebot.matcher import Matcher
@ -36,7 +36,7 @@ def do_add_sub(add_sub: Type[Matcher]):
+ "要查看全部平台请输入:“全部”\n中止订阅过程请输入:“取消”"
)
@add_sub.got("platform", OB11Message.template("{_prompt}"), [handle_cancel])
@add_sub.got("platform", MessageTemplate("{_prompt}"), [handle_cancel])
async def parse_platform(state: T_State, platform: str = ArgPlainText()) -> None:
if not isinstance(state["platform"], Message):
return
@ -69,7 +69,7 @@ def do_add_sub(add_sub: Type[Matcher]):
state["id"] = "default"
state["name"] = await check_sub_target(state["platform"], Target(""))
@add_sub.got("raw_id", OB11Message.template("{_prompt}"), [handle_cancel])
@add_sub.got("raw_id", MessageTemplate("{_prompt}"), [handle_cancel])
async def got_id(state: T_State, raw_id: str = ArgPlainText()):
if state.get("id"):
return
@ -107,7 +107,7 @@ def do_add_sub(add_sub: Type[Matcher]):
" ".join(list(platform_manager[state["platform"]].categories.values()))
)
@add_sub.got("raw_cats", OB11Message.template("{_prompt}"), [handle_cancel])
@add_sub.got("raw_cats", MessageTemplate("{_prompt}"), [handle_cancel])
async def parser_cats(state: T_State, raw_cats: str = ArgPlainText()):
if "cats" in state.keys():
return
@ -127,7 +127,7 @@ def do_add_sub(add_sub: Type[Matcher]):
return
state["_prompt"] = '请输入要订阅/屏蔽的标签(不含#号)\n多个标签请使用空格隔开\n订阅所有标签输入"全部标签"\n具体规则回复"详情"'
@add_sub.got("raw_tags", OB11Message.template("{_prompt}"), [handle_cancel])
@add_sub.got("raw_tags", MessageTemplate("{_prompt}"), [handle_cancel])
async def parser_tags(state: T_State, raw_tags: str = ArgPlainText()):
if "tags" in state.keys():
return

View File

@ -41,7 +41,7 @@ async def test_abort_add_on_platform(app: App, init_scheduler):
ctx.should_pass_rule()
ctx.should_call_send(
event_1,
Message(BotReply.add_reply_on_platform(platform_manager, common_platform)),
BotReply.add_reply_on_platform(platform_manager, common_platform),
True,
)
event_abort = fake_group_message_event(
@ -90,7 +90,7 @@ async def test_abort_add_on_id(app: App, init_scheduler):
ctx.should_pass_rule()
ctx.should_call_send(
event_1,
Message(BotReply.add_reply_on_platform(platform_manager, common_platform)),
BotReply.add_reply_on_platform(platform_manager, common_platform),
True,
)
event_2 = fake_group_message_event(
@ -99,7 +99,7 @@ async def test_abort_add_on_id(app: App, init_scheduler):
ctx.receive_event(bot, event_2)
ctx.should_call_send(
event_2,
Message(BotReply.add_reply_on_id(Weibo)),
BotReply.add_reply_on_id(Weibo),
True,
)
event_abort = fake_group_message_event(
@ -148,10 +148,8 @@ async def test_abort_add_on_cats(app: App, init_scheduler):
ctx.should_pass_rule()
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,
)
@ -161,7 +159,7 @@ async def test_abort_add_on_cats(app: App, init_scheduler):
ctx.receive_event(bot, event_2)
ctx.should_call_send(
event_2,
Message(BotReply.add_reply_on_id(Weibo)),
BotReply.add_reply_on_id(Weibo),
True,
)
event_3 = fake_group_message_event(
@ -177,7 +175,7 @@ async def test_abort_add_on_cats(app: App, init_scheduler):
)
ctx.should_call_send(
event_3,
Message(BotReply.add_reply_on_cats(platform_manager, "weibo")),
BotReply.add_reply_on_cats(platform_manager, "weibo"),
True,
)
event_abort = fake_group_message_event(
@ -226,10 +224,8 @@ async def test_abort_add_on_tag(app: App, init_scheduler):
ctx.should_pass_rule()
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,
)
@ -239,7 +235,7 @@ async def test_abort_add_on_tag(app: App, init_scheduler):
ctx.receive_event(bot, event_2)
ctx.should_call_send(
event_2,
Message(BotReply.add_reply_on_id(Weibo)),
BotReply.add_reply_on_id(Weibo),
True,
)
event_3 = fake_group_message_event(
@ -255,14 +251,14 @@ async def test_abort_add_on_tag(app: App, init_scheduler):
)
ctx.should_call_send(
event_3,
Message(BotReply.add_reply_on_cats(platform_manager, "weibo")),
BotReply.add_reply_on_cats(platform_manager, "weibo"),
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, Message(BotReply.add_reply_on_tags), True)
ctx.should_call_send(event_4, BotReply.add_reply_on_tags, True)
event_abort = fake_group_message_event(
message=Message("取消"), sender=Sender(card="", nickname="test", role="admin")
)

View File

@ -52,7 +52,7 @@ 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)),
BotReply.add_reply_on_platform(platform_manager, common_platform),
True,
)
ctx.should_pass_rule()
@ -95,10 +95,8 @@ async def test_add_with_target(app: App, init_scheduler):
ctx.should_pass_rule()
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,
)
@ -118,7 +116,7 @@ async def test_add_with_target(app: App, init_scheduler):
ctx.receive_event(bot, event_3)
ctx.should_call_send(
event_3,
Message(BotReply.add_reply_on_id(Weibo)),
BotReply.add_reply_on_id(Weibo),
True,
)
event_4_err = fake_group_message_event(
@ -140,7 +138,7 @@ async def test_add_with_target(app: App, init_scheduler):
)
ctx.should_call_send(
event_4_ok,
Message(BotReply.add_reply_on_cats(platform_manager, "weibo")),
BotReply.add_reply_on_cats(platform_manager, "weibo"),
True,
)
event_5_err = fake_group_message_event(
@ -155,7 +153,7 @@ async def test_add_with_target(app: App, init_scheduler):
message=Message("图文 文字"), sender=fake_admin_user
)
ctx.receive_event(bot, event_5_ok)
ctx.should_call_send(event_5_ok, Message(BotReply.add_reply_on_tags), True)
ctx.should_call_send(event_5_ok, BotReply.add_reply_on_tags, True)
event_6_more_info = fake_group_message_event(
message=Message("详情"), sender=fake_admin_user
)
@ -210,7 +208,7 @@ async def test_add_with_target_no_cat(app: App, init_scheduler):
ctx.should_pass_rule()
ctx.should_call_send(
event_1,
Message(BotReply.add_reply_on_platform(platform_manager, common_platform)),
BotReply.add_reply_on_platform(platform_manager, common_platform),
True,
)
event_3 = fake_group_message_event(
@ -219,7 +217,7 @@ async def test_add_with_target_no_cat(app: App, init_scheduler):
ctx.receive_event(bot, event_3)
ctx.should_call_send(
event_3,
Message(BotReply.add_reply_on_id(NcmArtist)),
BotReply.add_reply_on_id(NcmArtist),
True,
)
event_4_ok = fake_group_message_event(
@ -267,7 +265,7 @@ async def test_add_no_target(app: App, init_scheduler):
ctx.should_pass_rule()
ctx.should_call_send(
event_1,
Message(BotReply.add_reply_on_platform(platform_manager, common_platform)),
BotReply.add_reply_on_platform(platform_manager, common_platform),
True,
)
event_3 = fake_group_message_event(
@ -276,7 +274,7 @@ async def test_add_no_target(app: App, init_scheduler):
ctx.receive_event(bot, event_3)
ctx.should_call_send(
event_3,
Message(BotReply.add_reply_on_cats(platform_manager, "arknights")),
BotReply.add_reply_on_cats(platform_manager, "arknights"),
True,
)
event_4 = fake_group_message_event(
@ -316,7 +314,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)),
BotReply.add_reply_on_platform(platform_manager, common_platform),
True,
)
event_2 = fake_group_message_event(
@ -368,10 +366,8 @@ 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
)
BotReply.add_reply_on_platform(
platform_manager=platform_manager, common_platform=common_platform
),
True,
)
@ -381,7 +377,7 @@ async def test_add_with_get_id(app: App):
ctx.receive_event(bot, event_3)
ctx.should_call_send(
event_3,
Message(BotReply.add_reply_on_id(Weibo)),
BotReply.add_reply_on_id(Weibo),
True,
)
event_4_query = fake_group_message_event(
@ -448,10 +444,8 @@ async def test_add_with_bilibili_target_parser(app: App, init_scheduler):
ctx.should_pass_rule()
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,
)
@ -472,7 +466,7 @@ async def test_add_with_bilibili_target_parser(app: App, init_scheduler):
assert Bilibili.parse_target_promot
ctx.should_call_send(
event_3,
Message(BotReply.add_reply_on_id(Bilibili)),
BotReply.add_reply_on_id(Bilibili),
True,
)
event_4_err1 = fake_group_message_event(
@ -513,14 +507,14 @@ async def test_add_with_bilibili_target_parser(app: App, init_scheduler):
)
ctx.should_call_send(
event_4_ok,
Message(BotReply.add_reply_on_cats(platform_manager, "bilibili")),
BotReply.add_reply_on_cats(platform_manager, "bilibili"),
True,
)
event_5_ok = fake_group_message_event(
message=Message("视频"), sender=fake_admin_user
)
ctx.receive_event(bot, event_5_ok)
ctx.should_call_send(event_5_ok, Message(BotReply.add_reply_on_tags), True)
ctx.should_call_send(event_5_ok, BotReply.add_reply_on_tags, True)
event_6 = fake_group_message_event(
message=Message("全部标签"), sender=fake_admin_user
)
@ -572,10 +566,8 @@ async def test_add_with_bilibili_live_target_parser(app: App, init_scheduler):
ctx.should_pass_rule()
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,
)
@ -595,7 +587,7 @@ async def test_add_with_bilibili_live_target_parser(app: App, init_scheduler):
ctx.receive_event(bot, event_3)
ctx.should_call_send(
event_3,
Message(BotReply.add_reply_on_id(Bilibililive)),
BotReply.add_reply_on_id(Bilibililive),
True,
)
@ -611,7 +603,7 @@ async def test_add_with_bilibili_live_target_parser(app: App, init_scheduler):
)
ctx.should_call_send(
event_4_ok,
Message(BotReply.add_reply_on_cats(platform_manager, "bilibili-live")),
BotReply.add_reply_on_cats(platform_manager, "bilibili-live"),
True,
)
event_5_ok = fake_group_message_event(
@ -667,10 +659,8 @@ async def test_add_with_bilibili_bangumi_target_parser(app: App, init_scheduler)
ctx.should_pass_rule()
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,
)
@ -690,7 +680,7 @@ async def test_add_with_bilibili_bangumi_target_parser(app: App, init_scheduler)
ctx.receive_event(bot, event_3)
ctx.should_call_send(
event_3,
Message(BotReply.add_reply_on_id(BilibiliBangumi)),
BotReply.add_reply_on_id(BilibiliBangumi),
True,
)

View File

@ -27,7 +27,7 @@ async def test_query_with_superuser_private(app: App):
)
ctx.should_call_send(
event,
Message("请选择需要管理的群:\n1. 101 - test group\n请输入左侧序号\n中止操作请输入'取消'"),
"请选择需要管理的群:\n1. 101 - test group\n请输入左侧序号\n中止操作请输入'取消'",
True,
)
event_1_err = fake_private_message_event(
@ -90,7 +90,7 @@ async def test_query_with_abort_on_idx(app: App):
)
ctx.should_call_send(
event,
Message("请选择需要管理的群:\n1. 101 - test group\n请输入左侧序号\n中止操作请输入'取消'"),
"请选择需要管理的群:\n1. 101 - test group\n请输入左侧序号\n中止操作请输入'取消'",
True,
)
event_abort = fake_private_message_event(
@ -126,7 +126,7 @@ async def test_query_with_abort_on_command(app: App):
)
ctx.should_call_send(
event,
Message("请选择需要管理的群:\n1. 101 - test group\n请输入左侧序号\n中止操作请输入'取消'"),
"请选择需要管理的群:\n1. 101 - test group\n请输入左侧序号\n中止操作请输入'取消'",
True,
)
event_1_ok = fake_private_message_event(
@ -164,6 +164,6 @@ async def test_query_with_superuser_group_tome(app: App):
user_id=fake_superuser.user_id,
)
ctx.receive_event(bot, event)
ctx.should_pass_rule()
ctx.should_pass_permission()
ctx.should_call_send(event, Message("该功能只支持私聊使用请私聊Bot"), True)
# ctx.should_pass_rule()
# ctx.should_pass_permission()
# ctx.should_call_send(event, Message("该功能只支持私聊使用请私聊Bot"), True)