无权限用户尝试添加订阅时返回提示信息 (#617)

*  无权限用户尝试添加订阅时返回提示信息

*  添加no_permission_matcher相关的单元测试

* 🐛 优化无权限提示的排版

* 🐛 移除没有必要的命令
This commit is contained in:
2024-09-01 22:32:47 +08:00
committed by GitHub
parent 83cd0a741e
commit d6205867b8
3 changed files with 57 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
import pytest
from nonebug import App
from ..utils import BotReply, fake_admin_user, fake_group_message_event
@pytest.mark.asyncio
async def test_with_permission(app: App):
from nonebot.adapters.onebot.v11.bot import Bot
from nonebot.adapters.onebot.v11.message import Message
from nonebot_bison.platform import platform_manager
from nonebot_bison.sub_manager import add_sub_matcher, common_platform, no_permission_matcher
async with app.test_matcher([add_sub_matcher, no_permission_matcher]) as ctx:
bot = ctx.create_bot(base=Bot)
event = fake_group_message_event(message=Message("添加订阅"), sender=fake_admin_user, to_me=True)
ctx.receive_event(bot, event)
ctx.should_call_send(
event,
BotReply.add_reply_on_platform(platform_manager, common_platform),
True,
)
ctx.should_pass_rule()
ctx.should_pass_permission()
@pytest.mark.asyncio
async def test_without_permission(app: App):
from nonebot.adapters.onebot.v11.bot import Bot
from nonebot.adapters.onebot.v11.message import Message
from nonebot_bison.sub_manager import add_sub_matcher, no_permission_matcher
async with app.test_matcher([add_sub_matcher, no_permission_matcher]) as ctx:
bot = ctx.create_bot(base=Bot)
event = fake_group_message_event(message=Message("添加订阅"), to_me=True)
ctx.receive_event(bot, event)
ctx.should_call_send(
event,
BotReply.no_permission,
True,
)
ctx.should_pass_rule()
ctx.should_pass_permission()
+1
View File
@@ -158,3 +158,4 @@ class BotReply:
)
add_reply_on_tags_need_more_info = "订阅标签直接输入标签内容\n屏蔽标签请在标签名称前添加~号\n详见https://nonebot-bison.netlify.app/usage/#%E5%B9%B3%E5%8F%B0%E8%AE%A2%E9%98%85%E6%A0%87%E7%AD%BE-tag"
add_reply_abort = "已中止订阅"
no_permission = "您没有权限进行此操作,请联系 Bot 管理员"