kolaris-bot
v4.0.7
Published
icqq bot 框架
Readme
kolaris-bot
Usage
import { Kolaris } from 'kolaris-bot'
new Kolaris({
uin: 619113277,
// 私聊管理插件启、停的指令
command: 'plug',
// 插件存储目录
pluginDir: 'plugins',
master: [619113277],
config: {
platform: 5,
ver: '9.0.56',
sign_api_addr: xxx,
ignore_self: false,
},
renderer: {
pool: { max: 4 },
defaultViewport: { width: 800, height: 600, deviceScaleFactor: 2 },
},
}).start()插件写法
插件运行时默认使用 CommonJS 加载,以便在同一进程内通过 require.cache 可靠卸载。插件源码可以使用 TypeScript/现代语法开发,再构建为 CJS。
import { defineBotPlugin } from 'kolaris-bot'
export default defineBotPlugin({
setup(ctx) {
ctx.command('ping')
.group()
.use(event => event.reply('pong'))
ctx.message
.groupId(369877448)
.equal('/status')
.use(async (event) => {
await event.reply('ok')
})
},
})HTML 渲染发图
HTML 渲染由 Kolaris 核心懒加载 Puppeteer,并使用页面池复用资源。插件只需要调用 replyHtml():
export default defineBotPlugin({
setup(ctx) {
ctx.command('card').use(async (event) => {
await event.replyHtml(`
<body style="margin:0;padding:32px;font-family:sans-serif">
<h1>Kolaris</h1>
<p>HTML to image</p>
</body>
`, {
viewport: { width: 640, height: 360 },
selector: 'body',
})
})
},
})生命周期
通过 ctx 注册的资源会在插件卸载时自动清理:
ctx.on.*消息监听ctx.cron()定时任务ctx.timeout()/ctx.interval()ctx.http.server()ctx.ws.server()/ctx.ws.client()ctx.db.level()ctx.dispose()自定义清理函数
普通 Node ESM 插件不会在同一进程内承诺彻底热卸载;如需 ESM 热卸载,应使用未来的独立进程/worker 隔离运行时。
