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

Feature request: 运行时分频道禁用插件 #384

Closed
Tracked by #552
univeous opened this issue Sep 23, 2021 · 8 comments
Closed
Tracked by #552

Feature request: 运行时分频道禁用插件 #384

univeous opened this issue Sep 23, 2021 · 8 comments
Assignees
Labels
feature 新特性
Milestone

Comments

@univeous
Copy link

Describe the problem related to the feature request

我想在运行时分频道启用/禁用一些插件。

Describe the solution you'd like

现有的switch功能可以在运行时在特定频道禁用指令,但无法禁用中间件。
希望提供类似的指令在运行时在特定频道禁用/启用插件。同时希望提供指令来查看当前频道已启用的指令/插件。
在插件配置中增加一项来决定插件默认是否在新频道中启用。

Describe alternatives you've considered

插件可以自行维护禁用频道并处理相关逻辑,但个人认为较为繁琐,希望可以提供相关功能。

Additional context

参考:
基于 nonebot 框架的HoshinoBot可以通过lssv指令来列出插件(HoshinoBot中称为Service)在当前频道的启用情况,通过enable及disable指令在当前频道启用/禁用插件。相关代码
相关:#52

@univeous univeous added the feature 新特性 label Sep 23, 2021
@shigma shigma added domain: core next 下个大版本实装 labels Sep 23, 2021
@shigma
Copy link
Member

shigma commented Sep 23, 2021

首先非常感谢你的建议!

这确实是一个很有价值的功能,在未来的版本中我会认真考虑实装这个功能。

顺便问下,HoshinoBot 的这个 Service 只能是插件对频道禁用吗?有没有全局禁用,只对特定频道启用的例子呢?

@shigma shigma self-assigned this Sep 23, 2021
@univeous
Copy link
Author

有没有全局禁用,只对特定频道启用的例子呢?

HoshinoBot中在创建Service时可以指定是否默认启用,如果enable_on_default为False则默认全局禁用,只在调用了enable指令的特定频道里生效。我在上面的建议:

在插件配置中增加一项来决定插件默认是否在新频道中启用。

也是同样的意思,可能我没有表达清楚。

HoshinoBot中的例子

sv = Service('xxx', enable_on_default=False, help_='xxx')

@shigma
Copy link
Member

shigma commented Sep 23, 2021

明白了。不过由于 Koishi 的上下文比 nonebot 复杂的多(本身就可以叠加一堆 filter),所以可能就算做了也只能额外支持中间件,不能支持其他东西,这样能接受吗?

@shigma
Copy link
Member

shigma commented Sep 23, 2021

顺便,其实 Koishi v4 的 status 插件会支持任何插件的运行时重载(包括修改上下文),所以可以完美实现你的需求,唯一的缺点是插件重载可能会丢失自身状态(当然这取决于你是怎么写的)。我认为可能是一个更好的思路,你觉得呢?

@shigma
Copy link
Member

shigma commented Sep 23, 2021

啊,刚刚 dev 讨论了一下,可能 v4 会加一个官方插件实现你这个需求

@univeous
Copy link
Author

v4相关的我还没怎么看,要是有官方插件实现那好耶(

@purerosefallen
Copy link
Member

Planning to work on this.

@shigma shigma removed domain: core next 下个大版本实装 labels Jan 19, 2022
@shigma shigma mentioned this issue Feb 15, 2022
12 tasks
@shigma shigma mentioned this issue Feb 25, 2022
15 tasks
@shigma shigma added this to the 4.5 milestone Feb 25, 2022
@shigma
Copy link
Member

shigma commented Apr 5, 2022

这个功能在几个月前就已经实装于 @koishijs/plugin-switch 中,但这个插件仅作用于指令,而不能作用域其他插件。我在考虑了各种情况下的判断是,仅作用于指令已经能满足大部分需求。

如果需要深度定制插件的上下文(不仅是分频道,还有分用户,分机器人等等),可以期待之后会实装的新功能:插件组。

@shigma shigma closed this as completed Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 新特性
Projects
None yet
Development

No branches or pull requests

3 participants