mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-07 04:13:00 +08:00
♻️ adjust card
This commit is contained in:
parent
7ef225a87e
commit
3ccdcc844b
@ -1,12 +1,11 @@
|
|||||||
|
import contextlib
|
||||||
from typing import Type, cast
|
from typing import Type, cast
|
||||||
|
|
||||||
from nonebot.adapters import Message, MessageTemplate
|
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
|
from nonebot.matcher import Matcher
|
||||||
from nonebot.params import Arg, ArgPlainText
|
from nonebot.params import Arg, ArgPlainText
|
||||||
from nonebot.typing import T_State
|
from nonebot.typing import T_State
|
||||||
from nonebot_plugin_saa import PlatformTarget
|
from nonebot_plugin_saa import PlatformTarget, SupportedAdapters, Text
|
||||||
|
|
||||||
from ..apis import check_sub_target
|
from ..apis import check_sub_target
|
||||||
from ..config import config
|
from ..config import config
|
||||||
@ -75,13 +74,28 @@ def do_add_sub(add_sub: Type[Matcher]):
|
|||||||
try:
|
try:
|
||||||
if raw_id_text == "查询":
|
if raw_id_text == "查询":
|
||||||
url = "https://nonebot-bison.netlify.app/usage/#%E6%89%80%E6%94%AF%E6%8C%81%E5%B9%B3%E5%8F%B0%E7%9A%84-uid"
|
url = "https://nonebot-bison.netlify.app/usage/#%E6%89%80%E6%94%AF%E6%8C%81%E5%B9%B3%E5%8F%B0%E7%9A%84-uid"
|
||||||
|
msg = Text(url)
|
||||||
|
with contextlib.suppress(ImportError):
|
||||||
|
from nonebot.adapters.onebot.v11 import MessageSegment
|
||||||
|
|
||||||
title = "Bison所支持的平台UID"
|
title = "Bison所支持的平台UID"
|
||||||
content = "查询相关平台的uid格式或获取方式"
|
content = "查询相关平台的uid格式或获取方式"
|
||||||
image = "https://s3.bmp.ovh/imgs/2022/03/ab3cc45d83bd3dd3.jpg"
|
image = "https://s3.bmp.ovh/imgs/2022/03/ab3cc45d83bd3dd3.jpg"
|
||||||
getId_share = f"[CQ:share,url={url},title={title},content={content},image={image}]" # 缩短字符串格式长度,以及方便后续修改为消息段格式
|
msg.overwrite(
|
||||||
await add_sub.reject(OB11Message(getId_share))
|
SupportedAdapters.onebot_v11,
|
||||||
|
MessageSegment.share(
|
||||||
|
url=url, title=title, content=content, image=image
|
||||||
|
),
|
||||||
|
)
|
||||||
|
await msg.reject()
|
||||||
platform = platform_manager[state["platform"]]
|
platform = platform_manager[state["platform"]]
|
||||||
raw_id_text = await platform.parse_target(unescape(raw_id_text))
|
with contextlib.suppress(ImportError):
|
||||||
|
from nonebot.adapters.onebot.v11 import Message
|
||||||
|
from nonebot.adapters.onebot.v11.utils import unescape
|
||||||
|
|
||||||
|
if isinstance(raw_id, Message):
|
||||||
|
raw_id_text = unescape(raw_id_text)
|
||||||
|
raw_id_text = await platform.parse_target(raw_id_text)
|
||||||
name = await check_sub_target(state["platform"], raw_id_text)
|
name = await check_sub_target(state["platform"], raw_id_text)
|
||||||
if not name:
|
if not name:
|
||||||
await add_sub.reject("id输入错误")
|
await add_sub.reject("id输入错误")
|
||||||
|
@ -2,10 +2,16 @@ import pytest
|
|||||||
import respx
|
import respx
|
||||||
from httpx import Response
|
from httpx import Response
|
||||||
from nonebug.app import App
|
from nonebug.app import App
|
||||||
|
from nonebug_saa import should_send_saa
|
||||||
from pytest_mock import MockerFixture
|
from pytest_mock import MockerFixture
|
||||||
|
|
||||||
from .platforms.utils import get_json
|
from .platforms.utils import get_json
|
||||||
from .utils import BotReply, fake_admin_user, fake_group_message_event
|
from .utils import (
|
||||||
|
BotReply,
|
||||||
|
add_reply_on_id_input_search,
|
||||||
|
fake_admin_user,
|
||||||
|
fake_group_message_event,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@ -335,7 +341,13 @@ async def test_platform_name_err(app: App):
|
|||||||
async def test_add_with_get_id(app: App):
|
async def test_add_with_get_id(app: App):
|
||||||
from nonebot.adapters.onebot.v11.event import Sender
|
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_plugin_saa import TargetQQGroup
|
from nonebot_plugin_saa import (
|
||||||
|
Custom,
|
||||||
|
MessageFactory,
|
||||||
|
SupportedAdapters,
|
||||||
|
TargetQQGroup,
|
||||||
|
Text,
|
||||||
|
)
|
||||||
|
|
||||||
from nonebot_bison.config import config
|
from nonebot_bison.config import config
|
||||||
from nonebot_bison.config_manager import add_sub_matcher, common_platform
|
from nonebot_bison.config_manager import add_sub_matcher, common_platform
|
||||||
@ -384,19 +396,19 @@ async def test_add_with_get_id(app: App):
|
|||||||
message=Message("查询"), sender=fake_admin_user
|
message=Message("查询"), sender=fake_admin_user
|
||||||
)
|
)
|
||||||
ctx.receive_event(bot, event_4_query)
|
ctx.receive_event(bot, event_4_query)
|
||||||
ctx.should_rejected()
|
should_send_saa(
|
||||||
ctx.should_call_send(
|
ctx,
|
||||||
event_4_query,
|
MessageFactory(
|
||||||
Message([MessageSegment(*BotReply.add_reply_on_id_input_search())]),
|
Text(add_reply_on_id_input_search).overwrite(
|
||||||
True,
|
SupportedAdapters.onebot_v11,
|
||||||
|
BotReply.add_reply_on_id_input_search_ob11(),
|
||||||
)
|
)
|
||||||
"""
|
),
|
||||||
关于:Message([MessageSegment(*BotReply.add_reply_on_id_input_search())])
|
bot,
|
||||||
鬼知道为什么要在这里这样写,
|
event=event_4_query,
|
||||||
没有[]的话assert不了(should_call_send使用[MessageSegment(...)]的格式进行比较)
|
)
|
||||||
不在这里MessageSegment()的话也assert不了(指不能让add_reply_on_id_input_search直接返回一个MessageSegment对象)
|
ctx.should_rejected()
|
||||||
amen
|
|
||||||
"""
|
|
||||||
event_abort = fake_group_message_event(
|
event_abort = fake_group_message_event(
|
||||||
message=Message("取消"), sender=Sender(card="", nickname="test", role="admin")
|
message=Message("取消"), sender=Sender(card="", nickname="test", role="admin")
|
||||||
)
|
)
|
||||||
@ -407,6 +419,7 @@ async def test_add_with_get_id(app: App):
|
|||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
ctx.should_finished()
|
ctx.should_finished()
|
||||||
|
await ctx.run()
|
||||||
subs = await config.list_subscribe(TargetQQGroup(group_id=10000))
|
subs = await config.list_subscribe(TargetQQGroup(group_id=10000))
|
||||||
assert len(subs) == 0
|
assert len(subs) == 0
|
||||||
|
|
||||||
|
@ -75,6 +75,8 @@ from nonebot.adapters.onebot.v11.event import Sender
|
|||||||
fake_admin_user = Sender(nickname="test", role="admin")
|
fake_admin_user = Sender(nickname="test", role="admin")
|
||||||
fake_superuser = Sender(user_id=10001, nickname="superuser")
|
fake_superuser = Sender(user_id=10001, nickname="superuser")
|
||||||
|
|
||||||
|
add_reply_on_id_input_search = "https://nonebot-bison.netlify.app/usage/#%E6%89%80%E6%94%AF%E6%8C%81%E5%B9%B3%E5%8F%B0%E7%9A%84-uid"
|
||||||
|
|
||||||
|
|
||||||
class BotReply:
|
class BotReply:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -102,20 +104,19 @@ class BotReply:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def add_reply_on_id_input_search():
|
def add_reply_on_id_input_search_ob11():
|
||||||
search_url = "https://nonebot-bison.netlify.app/usage/#%E6%89%80%E6%94%AF%E6%8C%81%E5%B9%B3%E5%8F%B0%E7%9A%84-uid"
|
from nonebot.adapters.onebot.v11 import Message, MessageSegment
|
||||||
|
|
||||||
search_title = "Bison所支持的平台UID"
|
search_title = "Bison所支持的平台UID"
|
||||||
search_content = "查询相关平台的uid格式或获取方式"
|
search_content = "查询相关平台的uid格式或获取方式"
|
||||||
search_image = "https://s3.bmp.ovh/imgs/2022/03/ab3cc45d83bd3dd3.jpg"
|
search_image = "https://s3.bmp.ovh/imgs/2022/03/ab3cc45d83bd3dd3.jpg"
|
||||||
type = "share"
|
|
||||||
data = {
|
return MessageSegment.share(
|
||||||
"url": search_url,
|
url=add_reply_on_id_input_search,
|
||||||
"title": search_title,
|
title=search_title,
|
||||||
"content": search_content,
|
content=search_content,
|
||||||
"image": search_image,
|
image=search_image,
|
||||||
}
|
)
|
||||||
msg = [type, data]
|
|
||||||
return msg
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def add_reply_on_target_confirm(platform, name, id):
|
def add_reply_on_target_confirm(platform, name, id):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user