Comments (7)
@arily 试试 ctx.removeMiddleware
from koishi.
@shigma 抱歉!!好像我写的有些问题,上面想要被卸载掉的其实是插件
try {
const pluginToRemove = require(target)
ctx.remove(pluginToRemove)
}
大概是这样.
通过ctx.removeMiddleware的话应该需要拿到具体的中间件?
from koishi.
插件在 Koishi 的设计中,本身就不应该在运行时加载,自然也就不存在运行时卸载的概念。
如果你想要手动实现一个运行时卸载的功能,不妨考虑使用监听器:
// 定义一个插件
module.exports = (ctx, options) => {
ctx.middleware(callback1)
ctx.receiver.on(event, callback2)
ctx.on('remove-my-plugin', () => {
ctx.removeMiddleware(callback1)
ctx.receiver.off(event, callback2)
})
}
// 在你想要移除插件的地方
ctx.emit('remove-my-plugin')
from koishi.
是否支持停用指令 ctx.removeCommand()
(?
from koishi.
@masnn 目前没有这个接口,下个大版本会加上。在此之前可以使用暴力方式移除:
Context.prototype.removeCommand = function (cmd) {
cmd.shortcuts.forEach(name => delete ctx.app._shortcutMap[name])
ctx.app._shortcuts = difference(ctx.app._shortcuts, cmd.shortcuts)
cmd._aliases.forEach(name => delete ctx.app._commandMap[name])
ctx.app._commands = difference(ctx.app._commands, [cmd])
if (cmd.parent) cmd.parent.children = difference(cmd.parent.children, [cmd])
}
得写这么多我很惭愧……
from koishi.
在 next 分支的最新一次更新 bd46fe8 中已经实装了下列方法:
command.dispose() // 移除指令及其子指令
context.dispose() // 移除当前插件中注册的监听器、中间件和指令
from koishi.
已经实装于 koishi v2 beta 版本。
from koishi.
Related Issues (20)
- Feature: `Schema.dict` 的表格形式支持 i18n 的 $value HOT 4
- Bug: QQ适配器指令前缀不生效 HOT 4
- Bug: scoped 插件无法热重载 HOT 3
- Bug: 插件不显示提供的指令 HOT 1
- Bug: adapter-satori 连 Chronocat 后 READY 信令内没有 status 字段 HOT 4
- Feature: 支持别名的过滤器
- 添加 SECURITY.md HOT 2
- Bug: yarn pub 无法填写otp HOT 3
- Bug: Schema相同的属性未正确合并 HOT 1
- Bug: 无法在局域网访问网页面板 HOT 3
- Bug: yarn pub 无法正常上传包 HOT 2
- Bug: 多余请求头导致拿不到头像 HOT 2
- Bug: 使用 windows 安装的 podman-desktop 启动镜像时老是尝试启动 /mnt/c/.../powershell.exe 但报错 ENOENT HOT 1
- Feature: Schema.string() 添加代码编辑器的 role
- Bug: Schema.array() 的`添加项目`按钮行为不正常,在特定场景不可用等
- Bug(Schema): Computed with Union Not Showing Branches Correctly HOT 2
- Bug: help 指令在遇到 .platform 或其他情况下回复错误
- Bug: 在使用指令管理 改变一些层级后,指令管理选项消失 HOT 2
- feat(core): parser[number]: support delimiters in number
- Bug: 使用adapter-satori的机器人会出现i18n错误 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from koishi.