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: 使用 switch 禁用插件后仍会执行部分逻辑 #3

Closed
MirrorCY opened this issue Dec 11, 2022 · 3 comments
Closed

Bug: 使用 switch 禁用插件后仍会执行部分逻辑 #3

MirrorCY opened this issue Dec 11, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@MirrorCY
Copy link
Member

Describe the bug

使用 switch 禁用一个插件后,如果该插件有介于 apply()ctx.command() 之间的逻辑,仍会在匹配到 command 关键词时被执行。例如 novelai-bot 会在定义命令范围外进行参数检查,使用 switch novelai 禁用此插件后输入不合法的分辨率仍会报错。

Steps to reproduce

  • 全新安装 koishi bp
  • 安装 switch 和 novleai 插件并完成相关配置
  • 进入 QQ 群输入 switch novelai
  • 输入 nai -r 9999x9999 koishi
  • 查看返回的报错

Expected behavior

当插件的所有已注册指令都被禁用时,不应该触发该插件其余逻辑;
或当一个已注册指令被禁用时,不应该在发现被禁用指令关键词时调用该插件。

Screenshots

2FEB_52CGV4@ WOVSVKPJCA

Versions

  • Koishi version: 4.10.5

Additional context

No response

@MirrorCY MirrorCY added the bug Something isn't working label Dec 11, 2022
@MaikoTan
Copy link
Member

https://github.com/koishijs/koishi/blob/219ab235ef2be6e9aebb62a6a4dd8286faf9e292/plugins/a11y/switch/src/index.ts#L38-L50

So you could see here we block an invoke of the command using the command/execute event, which is triggered before executing the cmd.action(callback) part. That's why the validations or hooks still running even we disable it with the switch command.
But I don't know if there is an event that triggered AFTER parsing a command. (Because if you register a middleware BEFORE the parsing part, you could only parse the messages by yourself, generally we don't want to make a plugin complicated and unmaintainable.)

@MaikoTan
Copy link
Member

MaikoTan commented Feb 1, 2023

cc @shigma

@shigma shigma transferred this issue from koishijs/koishi Mar 11, 2023
@Hieuzest
Copy link
Contributor

closed via 8f353a9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants