koishijs / koishi Goto Github PK
View Code? Open in Web Editor NEWCross-platform chatbot framework made with love
Home Page: https://koishi.chat
License: MIT License
Cross-platform chatbot framework made with love
Home Page: https://koishi.chat
License: MIT License
Describe the bug
启动使用 koishi 编写的项目后,打印出了下面这些报错:
(node:3361) UnhandledPromiseRejectionWarning: Error: authorization failed at HttpServer._listen (/LF/Robot/FenBin/Main/node_modules/koishi-core/dist/server.js:269:19) at processTicksAndRejections (internal/process/task_queues.js:94:5) (node:3361) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2) (node:3361) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
下面是我的配置:
const app = new App({ type: 'http', port: 41007, server: 'http://localhost:41006', secret: '***_2020', token: '************', })
Describe the bug
消息能发不能收
To Reproduce
私聊,讨论组,群都不回调,不知道是什么原因,还是我用错了
app.middleware((meta, next) => {
console.log(meta.message)
return next()
})
app.receiver.on('message', (meta) => {
console.log(meta.message)
})
Expected behavior
Screenshots
Versions
Additional context
实在分析不出问题在哪,能不能帮忙分析一下?
比如实现一个 meta.$reply 功能,用于回复某一段消息,如何全局扩展这个 meta 对象,或者未来是否有这个计划
还有其他的替代方案吗, 唉, 刚研究了一阵子koishi, 写完自己的程序, 酷Q就凉凉了, 可惜了这么好的框架, 谢谢作者了
Describe the bug
可以发送私人消息(sender.sendPrivateMsg),
但无法发送群/组消息(sender.sendGroupMsg,sender.sendDiscussMsg)
To Reproduce
采用了官方文档中“调用 Koishi”的安装方式,正常执行程序,如下代码:
const {App} = require('koishi');
const app = new App({
type: 'http',
port: ....,
server: 'http://...:5700',
})
app.start()
app.sender.sendPrivateMsg(823***839, `start qq.`); // 该行可以正常发送消息
app.sender.sendGroupMsg(931***016, `group: i'm online...`); // 该行无法发送消息
app.sender.sendDiscussMsg(931***016, `discuss: i'm online...`); // 该行无法发送消息
在代码中,发送 Group 和 Discuss 消息均无法发送,且无报错;
经测试,可以正常接收到 931***016 的群消息;
Versions
请问是配置的问题还是什么原因呢?
如果需要,我可以继续补充信息,谢谢~
Describe the bug
https://koishijs.github.io/guide/command-system.html#指令前缀
根据这里的文档commandPrefix可以提供array来实现多前缀触发指令。
但当我提供array时会抛出错误。
/node_modules/escape-string-regexp/index.js:7
throw new TypeError('Expected a string');
To Reproduce
const app = new App({
...
commandPrefix: ["!","!"],
})
Expected behavior
数组中提供的所有前缀都可触发bot指令
Versions
Additional context
Describe the bug
两个问题
在不连接数据库的情况下,先注册中间件,再注册指令,此时如果走了指令,在它之前注册的中间件不会触发。如果注册的是前置中间件,则只有中间件会触发,指令完全失效。
在连接数据库后,指令和中间件都不生效。。。已经在数据库中建了相应的表和字段。
To Reproduce
Expected behavior
Screenshots
Versions
最新的
Additional context
Describe the bug
npm init -y的时候package中项目名为koishi
下一步安装koishi时会报错
To Reproduce
npm init -y
npm init koishi -D
Expected behavior
建议修改默认项目名称
Screenshots
Versions
Additional context
Describe the bug
我在创建koishi机器人的时候使用想使用websocket,但是无论是使用cli还是调用koishi都会报错,而使用post的方式就没有问题,请问是bug还是对websocket支持还没有完善
To Reproduce
使用cli的ws选项或者直接调用都会出现这种情况
Expected behavior
正常启动
Screenshots
error TypeError: Cannot destructure property 'pluginMajorVersion' of 'this.version' as it is undefined.
at WsClient.versionLessThan (/data/data/com.termux/files/home/kbot/node_modules/koishi-core/dist/server.js:176:17)
at WsClient.listen (/data/data/com.termux/files/home/kbot/node_modules/koishi-core/dist/server.js:186:22)
Versions
Additional context
求助,酷Q停运了,这个会受影响嘛
Ich versteche Englisch und Chinesisch nicht! Gab es Personen, die mir helfen kann?
A lot thanks to @masnn
getGroupList()
与 getGroupInfo()
被调用之后不返回值。
const { App: Koishi } = require('koishi');
class Bot {
constructor(item) {
this.config = item.config;
this.app = new Koishi({
type: 'ws',
port: 6700,
server: `ws://${this.config.host || 'localhost'}:${this.config.port || '6700'}`,
token: this.config.access_token
});
this.run();
}
async run() {
this.app.receiver.on('connect', async () => {
console.log('Connected');
let groups = await this.app.sender.getGroupList();
console.log(`Found ${groups.length} groups`); // -> No output
});
await this.app.start();
}
};
let config = require('./config.json');
global.App = new Bot({ config });
CQHTTP 显示 已成功处理一个API请求:get_group_list
Ubuntu 1604
[email protected]
[email protected]
[email protected]
[email protected]
Describe the bug
我配置好mysql数据库之后,收到消息时,出现了以下问题:
(node:4164) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '_timestamp' of undefined
at MysqlDatabase.getGroup (F:\WebProject\tool-man\node_modules\koishi-database-mysql\dist\group.js:14:44)
at MysqlDatabase.observeGroup (F:\WebProject\tool-man\node_modules\koishi-database-mysql\dist\group.js:61:37)
at Array.App._preprocess (F:\WebProject\tool-man\node_modules\koishi-core\dist\app.js:134:55)
at next (F:\WebProject\tool-man\node_modules\koishi-core\dist\app.js:199:103)
at EventEmitter.App._applyMiddlewares (F:\WebProject\tool-man\node_modules\koishi-core\dist\app.js:206:19)
at EventEmitter.emit (events.js:200:13)
at App.emitEvent (F:\WebProject\tool-man\node_modules\koishi-core\dist\app.js:348:30)
at HttpServer.dispatchMeta (F:\WebProject\tool-man\node_modules\koishi-core\dist\server.js:162:17)
at IncomingMessage.<anonymous> (F:\WebProject\tool-man\node_modules\koishi-core\dist\server.js:249:22)
at IncomingMessage.emit (events.js:205:15)
(node:4164) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 5)
下面是我的配置:
const app = new App({
type: 'http',
port: 8080,
server: 'http://localhost:5700',
database: {
mysql: {
host: '*.*.*.*',
port: 3306,
user: 'root',
password: '******',
database: 'coolq'
},
}
})
Additional context
此外,看了一下你之前关于mysql初始化的问题,是不是要手动创建那些你在API里调用的表和字段?
在配置文件中配置 MySQL 后无法启动机器人
module.exports = {
type: "http",
port: 8080,
server: "http://localhost:5700",
plugins: [
],
database: {
mysql: {
host: 'x.x.x.x',
port: 3306,
user: 'root',
password: 'xxxxxx',
database: 'xxx',
},
},
}
错误信息
error TypeError: Cannot read property '0' of undefined
at loadEcosystem (/usr/local/lib/node_modules/koishi/dist/worker.js:65:72)
at prepareApp (/usr/local/lib/node_modules/koishi/dist/worker.js:92:26)
at Object.<anonymous> (/usr/local/lib/node_modules/koishi/dist/worker.js:111:5)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
It seems that both CoolQ and CQHTTP have Docker support. Shall we make a Docker image for Koishi to help users deploy Koishi on Linux servers more quickly?
Describe the bug
中间件对群消息不执行
To Reproduce
···
app.middleware((meta, next) => {
console.log(meta)
return next()
})
···
对群发送一条消息
Expected behavior
日志输出 meta 对象
Versions
Additional context
这 SDK 是先有文档再有程序的吧
Is your feature request related to a problem? Please describe.
这里会自动把繁体字转换为简体字
$parsed很好用,但希望能不强制转换为简体字
Describe the solution you'd like
options中增加参数阻止繁体字被转换为简体字
Describe alternatives you've considered
不用$parsed.message
Additional context
这个 issue 用于整理 koishi-plugin-eval 中存在的漏洞。对漏洞的定义包括:
提交漏洞时请附上代码。
Is your feature request related to a problem? Please describe.
我发现,command是通过context进行构造,也就是说我需要获得context之后再声明这个command。比如我的入口是index.js,这样的话是不是所有command的逻辑和index.js的逻辑都写在一起了?
Describe the solution you'd like
能不能给context增加addCommand()类似的方法,把command的声明和执行的逻辑从index.js中拆分出去。这样我就可以创建一个command的文件夹,然后再把这些command导入index.js,再addCommand()。
或者在当前版本,我如何实现这样的目的?或者有没有更好的方法?
Is your feature request related to a problem? Please describe.
我想在运行时安装卸载一些中间件(使用场景为给每个群安装群特有的中间件,并且可以通过命令禁用)
Describe the solution you'd like
增加一个卸载middleware的api
const middleware = require('my-middleware')
//其实我觉得叫install,use一类会更清楚一些
ctx.plugin(middleware)
ctx.plugin((meta,next) => {
const parsed = meta.$parsed
const tiggered = (
['atMe','nickname','prefix'].some(trigger => parsed[trigger]) &&
parsed.message.startsWith('disable')
)
if (!triggered) return next()
const target = parsed.message.slice(8)
try {
const middlewareToRemove = require(target)
//here!
ctx.remove(middlewareToRemove)
} catch (error) {
meta.$send('unable to find that.')
}
}
Describe alternatives you've considered
每次增减插件时创建一个新的context安装这些插件,但对插件实现有限制,内部需要无状态,全部通过数据库实现
(我似乎也没找到销毁ctx的方法)
Additional context
When koishi-database-memory installed, (with koishi-plugin-common)
The meta.$user field is still undefined.
const { App: Koishi } = require('koishi');
const config = require('./config');
require('koishi-database-memory');
const App = new Koishi({
type: 'ws',
port: 6700,
server: `ws://${config.host || 'localhost'}:${config.port || '6700'}`,
token: config.access_token,
commandPrefix: config.prompt,
database: {
memory: {}
}
});
App.plugin(require('koishi-plugin-common'), {
admin: true,
broadcast: false,
contextify: false,
echo: false,
exec: false,
exit: false,
help: true,
info: true
});
App.receiver.on('message', async meta => {
console.log(meta.$user); // Prints undefined
});
App.start();
{
"koishi": "^1.11.1",
"koishi-database-memory": "^1.1.6",
"koishi-plugin-common": "^2.1.7"
}
Is your feature request related to a problem? Please describe.
插件需要输出不同重要度的信息,但是目前 Koishi 没有统一的 log level。
Describe the solution you'd like
提供一个内置的 Logger API,仅触发事件,实现由 CLI 提供:
ctx.logger().info(message)
ctx.logger(scope).warn(message)
然后在命令行中增加 --log-level
参数,提供 0-4 共 5 个不同的输出等级。配置文件中可以进一步对信息进行过滤,或指定输出到的文件等。
Describe alternatives you've considered
直接通过事件触发:
ctx.app.emit('info', null, message)
ctx.app.emit('warn', scope, message)
Additional context
N/A
app.command('a').action(({ session }) => {
session.createSession((session: Session, dispose: Function) => {
if (session.message === '1') return dispose();
return session.$send('Input another number');
});
});
如上,创建session之后所有该用户输入交由提供的函数处理,不进行指令调用等的解析,直到释放;
使用以下代码启动之后
const app = new App({
type: "ws",
server: "127.0.0.1:6700"
})
startAll().catch(e=>{
console.log(e);
})
获得了这样的错误
TypeError: Cannot read property 'close' of undefined
at WsClient._close (/node_modules/koishi-core/dist/server.js:360:21)
at WsClient.close (/node_modules/koishi-core/dist/server.js:206:14)
at WsClient.listen (/node_modules/koishi-core/dist/server.js:199:18)
请问是否是我的传值错误,或者是由什么引发该错误
Describe the bug
尝试把前端切换到mirai,使用了cqhttp-mirai插件,但是cqhttp-mirai不支持http api,koishi又不支持反向websocket。。。好难办
话说作者有计划支持mirai么?
To Reproduce
Expected behavior
Screenshots
Versions
Additional context
LevelDB 是不需要自动初始化的,但是 MySQL 需要,所以应该在 bot 连接到数据库的时候自动监测是否存在对应的表,如果不存在则自动进行添加,如果发生缺项的情况也应进行补足。
Is your feature request related to a problem? Please describe.
需要记录某些群的聊天记录。
Describe the solution you'd like
编写 koishi-plugin-recorder,按照配置的群号将聊天记录输出到本地文件中,包括消息的文本、发送人、发送时间。
Describe alternatives you've considered
N/A
Additional context
N/A
Is your feature request related to a problem? Please describe.
我们有时需要在机器人运行时重载代码。
Describe the solution you'd like
提供一个热重载 API,使得 app 可以在运行时重载,同时保持监听事件(并缓存),如果可以的话还可以保留未重载的文件的状态。
Describe alternatives you've considered
关闭子进程,更新文件,重开一个子进程(缺点是状态和过程中的请求会丢失)。
Additional context
提供选项,让command执行中遇到错误自动发送 e.message 到群或打印到console
或者command return一个string或Promise也可以作为快捷回复使用
Describe the bug
C:\Program Files\workspace\acghomebuild\koishi_demo>koishi run info apply plugin common port=8080 info Koishi/1.11.2 CoolQ/Pro CQHTTP/4.15.0 info server listening at 8080 info connected to http://localhost:5701 success bot started successfully in 445 ms. error SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) at IncomingMessage.req.on (C:\Users\Administrator\AppData\Roaming\npm\node_modules\koishi\node_modules\koishi-core\dist\server.js:232:35) at IncomingMessage.emit (events.js:203:15) at endReadableNT (_stream_readable.js:1129:12) at process._tickCallback (internal/process/next_tick.js:63:19)
To Reproduce
未知,程序均可以正常运行(可以联系并提供源码),本地win10跑正常无报错。
仅腾讯云的windows server环境下,过一段时间,会出现此问题
Expected behavior
解决这个问题,或者问题出现后依然可以运行项目(比如pm2之类的手段),
或者有排查错误原因的良方
Screenshots
无
Versions
Additional context
感觉不是我的锅就是腾讯云的锅
help太长了发不出去
应添加分页功能
看到文档里中间件可以接收到notice或request型的元数据,但是如果我注册中间件并直接console.log(meta),在实际测试中如果有加群申请或者有新成员入群,打印并不触发,意味着meta没有截获到东西,只有正常的message可以触发。
这是否意味着当前这类事件只能通过receiver处理,不能用中间件?如果可以需要怎么使用?
版本信息:Koishi/1.11.2 CoolQ/Air CQHTTP/4.14.2
Is your feature request related to a problem? Please describe.
I found it so tired to read through the QQ group list.
我发现翻阅 QQ 群列表的聊天记录很累。
Meanwhile, I get in touch with RSS, and found it save much efforts for me. I just need to add a link, it will monitor the website, and push the new articles to me.
与此同时,我接触了 RSS ,它替我省下了很多精力。只需要添加链接就能推送新文章。
mainly,sometimes it's meaningful to save the chatting record.
主要是,很多时候的聊天记录是值得保存的。
and with RSS, I can easily manage them and read them like newspaper.
并且用了 RSS 后,我能方便地管理它们。
Describe the solution you'd like
for example, it can push the message (maybe specific) stream to a local html. and RSS will do the remaining things.
比如,他可以把消息流推送到一个本地的 html 文件里,RSS 会完成剩下工作。相关图片也许可以推送至 Github 图床(或直接存至本地)
Describe alternatives you've considered
手动整理是非常麻烦的。并且网上似乎也没有相关资料。
Additional context
不想删了,交了然后 close 掉好了
Expected behavior
group / groups / user / users 多个条件组合同时满足
例如 app.group(123) && app.users.except(456) 在群123中除了456以外的用户
不知道现在的版本是否能够做到这个需求?
Versions
1.12.0
Describe the bug
对指定的上下文安装命令后,执行正确的命令时出现 你要找的是不是...
To Reproduce
const { App } = require('koishi')
require('koishi-database-mysql')
global.dev=true
const app = new App({
type: 'http',
port: 8080,
server: 'http://localhost:5700'
})
app.start()
app.group(xxx).command('echo <message>')
.action(({ meta }, message) => meta.$send(message))
在 xxx 这个群发送 echo a
Expected behavior
机器人回复“a”
Screenshots
Versions
with app.on('before-send', (session)=>{ console.log(session) });
(ver 2.0.0-beta.2)
在插件上下文中使用sender无效
error ctx.sender.sendPrivateMessage is not a function
module.exports.name = 'base'
module.exports.apply = (ctx) => {
ctx.receiver.on('message', (meta) => {
ctx.sender.sendPrivateMessage(*, 'Hello world')
})
console.log(ctx.sendPrivateMessage)
}
Describe the bug
meta.$send 无法发送群组消息
To Reproduce
const {
App
} = require('koishi');
const app = new App(require('./koishi.config'));
app.receiver.on('message', (meta) => {
if (meta.message === '人有多大胆') {
meta.$send('地有多大产')
}
})
app.start();
Versions
Additional context
私聊能收到回复,但是群聊不行,我使用其他库发送群聊消息都能收到(比如 cqhttp),不知道是什么原因。加群已经一年多了,各方面状态都正常,sendGroupMsg
和 sendGroupMsgAsync
也试了,也是发不出去。
Is your feature request related to a problem? Please describe.
选择Websocket连接方式时,如果与Cqhttp服务器的ws连接断掉,就无法收到消息,必须重启应用。
Describe the solution you'd like
当ws连接断开时,能够有可配置(重试次数,重试策略,Exponential Backoff 之类)的自动重连能力。
修改目前的 koishi init
指令,使之能够通过类似 npm init
的方式提示用户创建配置文件。
Describe the bug
根据文档上快速入门教程,执行koishi start报错
To Reproduce
cd my-bot
npm i koishi -g
koishi init
koishi start
Expected behavior
能够运行,连接上CQHTTP插件
Screenshots
nodejs v10.16
koishi v1.12.0
coolq-http-api v4.15.0
Additional context
话不多说,总之我有时间就来写
没时间...咕咕咕
能否增加在本地测试插件的功能
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.