Merge branch 'main' into next

This commit is contained in:
felinae98 2022-06-09 00:44:48 +08:00
commit 9fe98ec6bb
No known key found for this signature in database
GPG Key ID: 00C8B010587FF610
5 changed files with 105 additions and 9 deletions

View File

@ -2,6 +2,8 @@
## 最近更新
- 添加新的订阅平台mcbbsnews [@AzideCupric](https://github.com/AzideCupric) ([#84](https://github.com/felinae98/nonebot-bison/pull/84))
### 新功能
- 添加bilibili开播提醒 [@Sichongzou](https://github.com/Sichongzou) ([#60](https://github.com/felinae98/nonebot-bison/pull/60))

View File

@ -53,6 +53,12 @@
- 电台更新
- FF14
- 游戏公告
- mcbbs 幻翼块讯
- Java 版本资讯
- 基岩版本资讯
- 快讯
- 基岩快讯
- 周边消息
## 功能

View File

@ -357,7 +357,7 @@ async def send_group_list(bot: Bot, event: PrivateMessageEvent, state: T_State):
for idx, group in enumerate(groups, 1):
group_number_idx[idx] = group["group_id"]
res_text += f'{idx}. {group["group_id"]} - {group["group_name"]}\n'
res_text += "请输入左侧序号"
res_text += "请输入左侧序号\n中止操作请输入'取消'"
# await group_manage_matcher.send(res_text)
state["_prompt"] = res_text
state["group_number_idx"] = group_number_idx
@ -369,11 +369,16 @@ async def _parse_group_idx(state: T_State, event_msg: str = EventPlainText()):
group_number_idx: Optional[dict[int, int]] = state.get("group_number_idx")
assert group_number_idx
try:
assert event_msg != "取消", "userAbort"
idx = int(event_msg)
assert idx in group_number_idx.keys()
assert idx in group_number_idx.keys(), "idxNotInList"
state["group_idx"] = idx
except:
await group_manage_matcher.reject("请输入正确序号")
except AssertionError as AE:
errType = AE.args[0]
if errType == "userAbort":
await group_manage_matcher.finish("已取消")
elif errType == "idxNotInList":
await group_manage_matcher.reject("请输入正确序号")
@group_manage_matcher.got(
@ -387,13 +392,13 @@ async def do_choose_group_number(state: T_State):
async def _check_command(event_msg: str = EventPlainText()):
if event_msg not in {"添加订阅", "查询订阅", "删除订阅"}:
if event_msg not in {"添加订阅", "查询订阅", "删除订阅", "取消"}:
await group_manage_matcher.reject("请输入正确的命令")
return
@group_manage_matcher.got(
"command", "请输入需要使用的命令:添加订阅,查询订阅,删除订阅", [Depends(_check_command)]
"command", "请输入需要使用的命令:添加订阅,查询订阅,删除订阅,取消", [Depends(_check_command)]
)
async def do_dispatch_command(
bot: Bot,
@ -402,6 +407,8 @@ async def do_dispatch_command(
matcher: Matcher,
command: str = ArgStr(),
):
if command == "取消":
await group_manage_matcher.finish("已取消")
permission = await matcher.update_permission(bot, event)
new_matcher = Matcher.new(
"message",

View File

@ -169,7 +169,7 @@ class Bilibililive(StatusChange):
# E-mail : 1557157806@qq.com
categories = {}
platform_name = "bilibili-live"
enable_tag = True
enable_tag = False
enabled = True
is_common = True
scheduler_class = "bilibili.com"

View File

@ -25,7 +25,9 @@ async def test_query_with_superuser_private(app: App):
"get_group_list", {}, [{"group_id": 101, "group_name": "test group"}]
)
ctx.should_call_send(
event, Message("请选择需要管理的群:\n1. 101 - test group\n请输入左侧序号"), True
event,
Message("请选择需要管理的群:\n1. 101 - test group\n请输入左侧序号\n中止操作请输入'取消'"),
True,
)
event_1_err = fake_private_message_event(
message=Message("0"),
@ -43,7 +45,7 @@ async def test_query_with_superuser_private(app: App):
user_id=fake_superuser.user_id,
)
ctx.receive_event(bot, event_1_ok)
ctx.should_call_send(event_1_ok, "请输入需要使用的命令:添加订阅,查询订阅,删除订阅", True)
ctx.should_call_send(event_1_ok, "请输入需要使用的命令:添加订阅,查询订阅,删除订阅,取消", True)
event_2_err = fake_private_message_event(
message=Message("222"),
sender=fake_superuser,
@ -64,6 +66,85 @@ async def test_query_with_superuser_private(app: App):
ctx.should_pass_permission()
@pytest.mark.asyncio
async def test_query_with_abort_on_idx(app: App):
from nonebot.adapters.onebot.v11.bot import Bot
from nonebot.adapters.onebot.v11.message import Message
from nonebot_bison.config_manager import group_manage_matcher
async with app.test_matcher(group_manage_matcher) as ctx:
bot = ctx.create_bot(base=Bot)
event = fake_private_message_event(
message=Message("群管理"),
sender=fake_superuser,
to_me=True,
user_id=fake_superuser.user_id,
)
ctx.receive_event(bot, event)
ctx.should_pass_rule()
ctx.should_pass_permission()
ctx.should_call_api(
"get_group_list", {}, [{"group_id": 101, "group_name": "test group"}]
)
ctx.should_call_send(
event,
Message("请选择需要管理的群:\n1. 101 - test group\n请输入左侧序号\n中止操作请输入'取消'"),
True,
)
event_abort = fake_private_message_event(
message=Message("取消"),
sender=fake_superuser,
to_me=True,
user_id=fake_superuser.user_id,
)
ctx.receive_event(bot, event_abort)
ctx.should_call_send(event_abort, "已取消", True)
ctx.should_finished()
async def test_query_with_abort_on_command(app: App):
from nonebot.adapters.onebot.v11.bot import Bot
from nonebot.adapters.onebot.v11.message import Message
from nonebot_bison.config_manager import group_manage_matcher
async with app.test_matcher(group_manage_matcher) as ctx:
bot = ctx.create_bot(base=Bot)
event = fake_private_message_event(
message=Message("群管理"),
sender=fake_superuser,
to_me=True,
user_id=fake_superuser.user_id,
)
ctx.receive_event(bot, event)
ctx.should_pass_rule()
ctx.should_pass_permission()
ctx.should_call_api(
"get_group_list", {}, [{"group_id": 101, "group_name": "test group"}]
)
ctx.should_call_send(
event,
Message("请选择需要管理的群:\n1. 101 - test group\n请输入左侧序号\n中止操作请输入'取消'"),
True,
)
event_1_ok = fake_private_message_event(
message=Message("1"),
sender=fake_superuser,
to_me=True,
user_id=fake_superuser.user_id,
)
ctx.receive_event(bot, event_1_ok)
ctx.should_call_send(event_1_ok, "请输入需要使用的命令:添加订阅,查询订阅,删除订阅,取消", True)
event_abort = fake_private_message_event(
message=Message("取消"),
sender=fake_superuser,
to_me=True,
user_id=fake_superuser.user_id,
)
ctx.receive_event(bot, event_abort)
ctx.should_call_send(event_abort, "已取消", True)
ctx.should_finished()
@pytest.mark.asyncio
async def test_query_with_superuser_group_tome(app: App):
from nonebot.adapters.onebot.v11.bot import Bot