Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 优先级更改或者修改成别的触发模式,/say这种 #16

Open
watshon14 opened this issue Dec 31, 2024 · 7 comments
Open

Comments

@watshon14
Copy link

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

这个插件的信息经常会被别的优先级更高的插件使用同样message格式导致matcher 不会正确选择

Describe the solution you'd like
A clear and concise description of what you want to happen.

请问怎么修改触发模式,修改成/say这种的触发模式或者修改别的插件降低别的的优先度,没有写过插件的经验不太确定这些修改在哪里完成

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

@Cvandia
Copy link
Owner

Cvandia commented Dec 31, 2024

优先级可以使用priority实现,正打算考虑加入新的响应如/say,敬请期待

@watshon14
Copy link
Author

我根据gpt的把init.py的handle改成了这个样子,但是好像还是会被别的插件读取信息。

from nonebot.plugin import on_command

# 替换 on_message 为 on_command

send_fake_msg = on_command("fake", aliases={"/fake"}, priority=5, block=True)

@send_fake_msg.handle()
async def _(bot: Bot, event: Union[PrivateMessageEvent, GroupMessageEvent]):
    args = str(event.get_message()).strip()
    if not args:
        await send_fake_msg.finish("请输入要伪造的消息内容")
    fake_msg_list = []  # 创建伪造消息列表
    user_msgs = args.split(user_split)
    for raw_user_msg in user_msgs:
        user_msg = raw_user_msg.strip()
        try:
            user_qq, msg = user_msg.split("说", 1)
        except ValueError:
            await send_fake_msg.finish("消息格式错误, 请按照 <QQ号>说<内容> 的格式输入")
        user_info = await bot.get_stranger_info(user_id=int(user_qq))
        user_name = user_info["nickname"]
        fake_msg_list.append((user_name, user_qq, msg))
    try:
        await send_forward_msg(bot, event, fake_msg_list)
    except Exception as e:
        await send_fake_msg.finish(f"发送失败,{e}")

问一下他有什么办法能让他不拦截信息吗?就比如说这个插件虽然他被matcher select了但是他不会停留在这,会接着流向下一个插件这种,如果能这样的话就不用调优先度了。我试着去找了一下那个会吞并这个插件消息的message的priority但是我没找到,或者说是没有找到同样写法的priority,是这两个nonebot-plugin-updater, nonebot-plugin-running-state. 我对这些代码的认知仅停留在gpt修改还有英语阅读上,如果您能提供一些处理的建议之类的,或者如何把这些handler改成指令的形式的话,感激不尽

@Cvandia
Copy link
Owner

Cvandia commented Jan 1, 2025

@watshon14 源码对应在这里修改block=False

@watshon14
Copy link
Author

@watshon14 源码对应在这里修改block=False

请问插件的block和优先度都是这么写的吗?还是也有可能会有别的方法去handle,我看了一下别的插件的源代码好像有一些没有和这个完全一致的写法,也有可能是我阅读失误了。如果他没有的话能直接这么写给他的function加一个priorityblock=false

@Cvandia
Copy link
Owner

Cvandia commented Jan 1, 2025

是的,但这不是插件的优先度和阻断性,更确切的说是指具体响应器(matcher)的优先度与阻断性,一个插件可含有多个matcher,用于处理相关的消息。
对于所有on的matcher,都可加入priorityblock参数来配置响应器的优先级和阻断性,如下:

matcher1 = on_message('hello',priority=5,block=False)
matcher2 = on_regex(r'^hello,world$',priority=6,block=True)

@matcher1.handle()
async def _():
    #matcher1处理hello消息的逻辑
    ...
@matcher2.handle()
async def _();
    #matcher2处理hello,world消息的逻辑
    ...

这些参数使得matcher按照开发者设计要求响应消息

@Cvandia
Copy link
Owner

Cvandia commented Jan 1, 2025

前面提到的nonebot-plugin-updater插件等,用到另外一种匹配器Alconna,这里不展开详述。同样的在源码这里可以添加priorityblock参数

@watshon14
Copy link
Author

前面提到的nonebot-plugin-updater插件等,用到另外一种匹配器Alconna,这里不展开详述。同样的在源码这里可以添加priorityblock参数

好的,谢谢您的指点。更详细的问一下,用Alconna的matcher的话,写priority和block的argument是在您标出来的on_alchonna后面的括号里的argument里面写吗?还是跟您的一样单独一行写function=on_message()然后在括号里写argument?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants