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

增加获取某插件下matcher及其触发条件的API #1228

Closed
htharoldht opened this issue Sep 5, 2022 · 6 comments
Closed

增加获取某插件下matcher及其触发条件的API #1228

htharoldht opened this issue Sep 5, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@htharoldht
Copy link

是否在使用中遇到某些问题而需要新的特性?请描述:

为了更方便地对权限进行管理,我想获取到某插件下的所有matcher,以及其触发条件

描述你所需要的特性:

该接口能更方便地进行权限管理、命令帮助,甚至对生成机器人的帮助文档都会有很大的帮助

@htharoldht htharoldht added the enhancement New feature or request label Sep 5, 2022
@yanyongyu
Copy link
Member

plugin = nonebot.get_plugin('name')获取插件对象,plugin.matchers就是你要的所有matcher。

获取到matcher怎么解析matcher.rule触发条件就看你自己想怎么写了

@htharoldht
Copy link
Author

我能拿到matcher的触发条件,但是拿不到matcher的名字

for i in plugin.matcher:
    for j in i.rule.checkers:
        tmp = list(map(str, re.findall(r"[\"']([^',]+?)['\"]", str(j.call))))

@yanyongyu
Copy link
Member

yanyongyu commented Sep 6, 2022

matcher是不会存储名字这种东西的,你可以考虑放到matcher.__doc__

@htharoldht
Copy link
Author

增加matcher.__doc__的话,得手动更改好多东西[捂脸],且现有的插件基本都没有这个支持

如果框架内部有这个东西,就方便多了

这样就可以针对各个插件的matcher级别进行权限控制,以及之前提到的帮助文档生成

@yanyongyu
Copy link
Member

参考 #1015 目前不会对matcher进行改变,只有插件元数据

@yanyongyu
Copy link
Member

如果有问题或者建议,请前往 #1015 参与讨论。

@yanyongyu yanyongyu closed this as not planned Won't fix, can't repro, duplicate, stale Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

2 participants